376 lines
17 KiB
JavaScript
376 lines
17 KiB
JavaScript
import { createMartPoint, createSeriesModel, createMarkLineModels, hexColor, convertSheetToList } from '@/utils/runPlan';
|
||
const StationMap = {
|
||
YARD1: '潏河停车场',
|
||
YARD2: '潏河停车场',
|
||
WQN: '韦曲南站',
|
||
HTC: '航天城站',
|
||
FQY: '凤栖原站',
|
||
SYZ: '三爻站',
|
||
HZX: '会展中心站',
|
||
WYJ: '纬一街站',
|
||
XZZ: '小寨站',
|
||
TYC: '体育场站',
|
||
NSM: '南稍门站',
|
||
YNM: '永宁门站',
|
||
ZLZ: '钟楼站',
|
||
BDJ: '北大街站',
|
||
AYM: '安远门站',
|
||
LSY: '龙首原站',
|
||
DMG: '大明宫西站',
|
||
STS: '市图书馆站',
|
||
FCW: '凤城五路站',
|
||
XZX: '行政中心站',
|
||
YDG: '运动公园站',
|
||
BYZ: '北苑站',
|
||
BKZ: '北客站',
|
||
NDOP1: '渭河车辆段',
|
||
NDOP2: '渭河车辆段'
|
||
};
|
||
|
||
export default {
|
||
/** 边缘高度*/
|
||
EdgeHeight: 600,
|
||
|
||
/** 间隔高度*/
|
||
CoordMultiple: 1,
|
||
|
||
/** 偏移时间*/
|
||
TranslationTime: 60 * 60 * 2,
|
||
/** excel解析配置*/
|
||
ExcelConfig: {
|
||
beginRow: 1,
|
||
beginCol: 0,
|
||
fieldNum: 8,
|
||
sepField: 'Trip',
|
||
idField: 'Train ID',
|
||
columns: {
|
||
'LOC': { key: 'stationName', formatter: (val) => { return StationMap[val]; } },
|
||
'Arrive': { key: 'arriveTime', formatter: (val) => { return val; } },
|
||
'Depart': { key: 'departureTime', formatter: (val) => { return val; } }
|
||
}
|
||
|
||
},
|
||
|
||
/** 解析exal数据转换为Json后台数据*/
|
||
importData(Sheet, JsonData) {
|
||
var dataList = convertSheetToList(Sheet, true);
|
||
var needList = Object.keys(this.ExcelConfig.columns);
|
||
if (dataList && dataList.length) {
|
||
for (var colIndex = this.ExcelConfig.beginCol; colIndex < dataList.length; colIndex += this.ExcelConfig.fieldNum + 1) {
|
||
var isContinue = true;
|
||
var tripObj = { code: '', trainId: '', arrivalList: [] };
|
||
for (var rowIndex = this.ExcelConfig.beginRow; isContinue; rowIndex += 1) {
|
||
isContinue = false;
|
||
|
||
var stationObj = {};
|
||
for (var index = 0; index < this.ExcelConfig.fieldNum; index += 1) {
|
||
if (dataList[colIndex + index]) {
|
||
var title = dataList[colIndex + index][0];
|
||
var value = dataList[colIndex + index][rowIndex];
|
||
|
||
if (title && value) {
|
||
// 数据列解析
|
||
isContinue = true;
|
||
var titleStr = `${title}`.trim();
|
||
var valueStr = `${value}`.trim();
|
||
|
||
if (titleStr == this.ExcelConfig.sepField) {
|
||
if (tripObj.code) {
|
||
const length = tripObj.arrivalList.length;
|
||
if (length == 1) {
|
||
tripObj.arrivalList[0]['flag'] = true;
|
||
}
|
||
if (valueStr.includes('FT') || valueStr.includes('LT')) {
|
||
valueStr = valueStr.replace('FT', '').replace('LT', '');
|
||
}
|
||
valueStr = tripObj.trainId + valueStr;
|
||
delete tripObj.trainId;
|
||
JsonData.push(tripObj);
|
||
tripObj = { code: valueStr, arrivalList: [] };
|
||
} else {
|
||
if (valueStr.includes('FT') || valueStr.includes('LT')) {
|
||
valueStr = valueStr.replace('FT', '').replace('LT', '');
|
||
}
|
||
valueStr = tripObj.trainId + valueStr;
|
||
delete tripObj.trainId;
|
||
tripObj.code = valueStr;
|
||
}
|
||
} else if (titleStr === this.ExcelConfig.idField) {
|
||
tripObj.trainId = valueStr;
|
||
}
|
||
|
||
// 取需要的字段
|
||
if (needList.findIndex(elem => { return elem == titleStr; }) >= 0) {
|
||
stationObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(valueStr);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 添加字段值
|
||
if (Object.keys(stationObj).length) {
|
||
if (!stationObj.departureTime) {
|
||
stationObj.departureTime = stationObj.arriveTime;
|
||
} else if (!stationObj.arriveTime) {
|
||
stationObj.arriveTime = stationObj.departureTime;
|
||
}
|
||
if (stationObj.stationName) {
|
||
tripObj.arrivalList.push(stationObj);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 添加最后那条没有车次的记录
|
||
if (tripObj.code) {
|
||
const length = tripObj.arrivalList.length;
|
||
if (length) {
|
||
tripObj.arrivalList[length - 1]['flag'] = true;
|
||
}
|
||
JsonData.push(tripObj);
|
||
}
|
||
}
|
||
}
|
||
const deleteIndexList = [];
|
||
const secondStation = ['北客站', '韦曲南站'];
|
||
const firstStation = ['潏河停车场', '渭河车辆段'];
|
||
JsonData.forEach((item, i) => {
|
||
if (item.arrivalList.length === 2 && firstStation.includes(item.arrivalList[0].stationName) && secondStation.includes(item.arrivalList[1].stationName)) {
|
||
JsonData[i + 1].arrivalList[0].arriveTime = item.arrivalList[1].arriveTime;
|
||
JsonData[i + 1].arrivalList.unshift(item.arrivalList[0]);
|
||
deleteIndexList.unshift(i);
|
||
} else if (item.arrivalList.length === 2 && firstStation.includes(item.arrivalList[1].stationName) && secondStation.includes(item.arrivalList[0].stationName)) {
|
||
JsonData[i - 1].arrivalList[JsonData[i - 1].arrivalList.length - 1].departureTime = item.arrivalList[0].departureTime;
|
||
JsonData[i - 1].arrivalList.push(item.arrivalList[1]);
|
||
deleteIndexList.unshift(i);
|
||
}
|
||
});
|
||
deleteIndexList.forEach(item => {
|
||
JsonData.splice(item, 1);
|
||
});
|
||
return JsonData;
|
||
},
|
||
|
||
/** 将后台数据解析成图表*/
|
||
convertDataToModels(data, stations, kmRangeCoordMap, lineStyle) {
|
||
var models = [];
|
||
|
||
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
|
||
/** 按服务遍历数据*/
|
||
data.serviceNumberDataList.forEach((service) => {
|
||
/** 按车次遍历数据*/
|
||
var isBackup = true;
|
||
var opt = { name: '', markPointData: [], data: [] };
|
||
if (service.tripNumberDataList && service.tripNumberDataList.length) {
|
||
service.tripNumberDataList.forEach((train, j) => {
|
||
var pointdata = {};
|
||
var idx = 0;
|
||
var num = 0;
|
||
var lastPoint = null;
|
||
var nextPoint = null;
|
||
|
||
/** 如果车次号为空,不显示名称*/
|
||
if (train.tripNumber) {
|
||
/** 创建标记点名称和坐标*/
|
||
pointdata.name = `${service.serviceNumber}${train.tripNumber}`;
|
||
pointdata.color = '#000' || lineStyle.color;
|
||
pointdata.directionCode = train.directionCode;
|
||
pointdata.coord = [train.stationTimeList[1].secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, train.stationTimeList[1], train.directionCode, false)];
|
||
|
||
/** 给服务对象添加服务名称和标记点*/
|
||
opt.markPointData.push(createMartPoint(pointdata));
|
||
/** 创建服务号名称*/
|
||
opt.name = `${service.serviceNumber}`;
|
||
}
|
||
|
||
/** 计算非折返点车次点坐标集合*/
|
||
train.stationTimeList.forEach((elem, index) => {
|
||
idx = index;
|
||
if (index == 0 && train.stationTimeList[index].stationCode != train.stationTimeList[index + 1].stationCode ||
|
||
index == train.stationTimeList.length - 2 && train.stationTimeList[index].secondTime != train.stationTimeList[index + 1].secondTime ||
|
||
index > 0 && index < train.stationTimeList.length - 1) {
|
||
const aa = `${train.directionCode}${train.tripNumber}`;
|
||
opt.data.push([elem.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, elem, elem.directionCode, false), elem.stationCode, aa]);
|
||
}
|
||
});
|
||
|
||
/** 计算折返点车次坐标点集合*/
|
||
if (!train.backup && train.reentry && service.tripNumberDataList[j + 1] && service.tripNumberDataList[j + 1].stationTimeList) {
|
||
lastPoint = train.stationTimeList[idx - 1];
|
||
nextPoint = service.tripNumberDataList[j + 1].stationTimeList[1];
|
||
num = this.computedReentryNumber(train.tripNumber);
|
||
const aa = `${train.directionCode}${train.tripNumber}`;
|
||
opt.data.push([lastPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, lastPoint, train.directionCode, true, num), lastPoint.stationCode, aa]);
|
||
opt.data.push([nextPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, nextPoint, train.directionCode, true, num), nextPoint.stationCode, aa]);
|
||
}
|
||
|
||
/** 如果是备用车,按车次添加线*/
|
||
if (train.backup) {
|
||
/** 创建一条完成的服务数据*/
|
||
opt.name += j;
|
||
var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
||
if (model) {
|
||
models.push(model);
|
||
opt = { name: '', markPointData: [], data: [] };
|
||
}
|
||
}
|
||
|
||
isBackup = train.backup;
|
||
});
|
||
|
||
// 不是备用车,按服务添加线
|
||
if (!isBackup) {
|
||
/** 创建一条完成的服务数据*/
|
||
var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
||
if (model) {
|
||
models.push(model);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
return models;
|
||
} else {
|
||
return [];
|
||
}
|
||
},
|
||
|
||
/** 更新数据并解析成图表*/
|
||
updateDataToModels(data, stations, kmRangeCoordMap, runPlanData, series, lineStyle) {
|
||
if (data && data.length) {
|
||
data.forEach(elem => {
|
||
/** 判断此条记录的服务号是否存在*/
|
||
if (!runPlanData[elem.serviceNumber]) {
|
||
/** 创建一个新服务号标记*/
|
||
runPlanData[elem.serviceNumber] = {};
|
||
|
||
/** 不存在此服务号,则需要创建一条新的line*/
|
||
series.push(createSeriesModel({
|
||
zlevel: 1,
|
||
name: `run${elem.serviceNumber}`,
|
||
data: [],
|
||
markPointData: []
|
||
}, Object.assign({ color: hexColor.toCreate() }, lineStyle)));
|
||
}
|
||
|
||
/** 添加数据*/
|
||
series.forEach(serie => {
|
||
/** 找到服务号所在图数据的位置*/
|
||
if (serie.name == `run${elem.serviceNumber}`) {
|
||
/** 添加车组号记录标记*/
|
||
if (!runPlanData[elem.serviceNumber][elem.tripNumber]) {
|
||
runPlanData[elem.serviceNumber][elem.tripNumber] = [];
|
||
}
|
||
|
||
runPlanData[elem.serviceNumber][elem.tripNumber].push(elem);
|
||
runPlanData[elem.serviceNumber][elem.tripNumber].sort((a, b) => {
|
||
return parseInt(a.secondTime) - parseInt(b.secondTime);
|
||
});
|
||
|
||
/** 如果此记录车组号的数据为第一条时,则打上标签*/
|
||
if (runPlanData[elem.serviceNumber][elem.tripNumber].length <= 1) {
|
||
serie.markPoint.data.push(createMartPoint({
|
||
directionCode: elem.directionCode,
|
||
coord: [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem, false)],
|
||
name: `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`,
|
||
color: lineStyle.color || '#000'
|
||
}));
|
||
}
|
||
|
||
/** 计算折返点*/
|
||
var nextPoint = [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem, false), elem.directionCode];
|
||
if (serie.data.length > 0) {
|
||
var lastPoint = serie.data[serie.data.length - 1];
|
||
if (lastPoint[2] !== nextPoint[2]) {
|
||
var num = this.computedReentryNumber(elem.tripNumber);
|
||
serie.data.push([lastPoint[0], this.getYvalueByDirectionCode(lastPoint[1], lastPoint[2], num), lastPoint[2]]);
|
||
serie.data.push([nextPoint[0], this.getYvalueByDirectionCode(nextPoint[1], lastPoint[2], num), lastPoint[2]]);
|
||
}
|
||
}
|
||
|
||
/** 添加车组号数据到对应的服务图数据中*/
|
||
serie.data.push(nextPoint);
|
||
|
||
/** 保证原始数据排序*/
|
||
serie.data.sort((a, b) => {
|
||
return parseInt(a[0]) - parseInt(b[0]);
|
||
});
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
return series;
|
||
},
|
||
|
||
/** 初始化Y轴*/
|
||
initializeYaxis(stations) {
|
||
return createMarkLineModels(stations, (elem) => {
|
||
return this.EdgeHeight + elem.kmRange * this.CoordMultiple;
|
||
});
|
||
},
|
||
|
||
/** 将后台数据转换为试图序列模型*/
|
||
convertStationsToMap(stations) {
|
||
var map = {};
|
||
if (stations && stations.length) {
|
||
stations.forEach((elem) => {
|
||
map[`${elem.kmRange}`] = this.EdgeHeight + elem.kmRange * this.CoordMultiple;
|
||
});
|
||
}
|
||
|
||
return map;
|
||
},
|
||
|
||
/** 计算y轴最小值*/
|
||
computedYaxisMinValue(stations) {
|
||
return stations[0].kmRange * this.CoordMultiple;
|
||
},
|
||
|
||
/** 计算y轴最大值*/
|
||
computedYaxisMaxValue(stations) {
|
||
return stations[stations.length - 1].kmRange * this.CoordMultiple + this.EdgeHeight * 2;
|
||
},
|
||
|
||
/** 格式化y轴数据*/
|
||
computedFormatYAxis(stations, params) {
|
||
var yText = '0m';
|
||
|
||
stations.forEach(elem => {
|
||
if (elem.kmRange < parseInt(params.value) / this.CoordMultiple - this.EdgeHeight) {
|
||
yText = Math.floor(elem.kmRange) + 'm';
|
||
}
|
||
});
|
||
|
||
return yText;
|
||
},
|
||
|
||
/** 根据是否和上一个车次是否相交,计算下一个车次的折返的高度*/
|
||
computedReentryNumber(code) {
|
||
return parseInt(code || 1) % 2 ? 1 : 2;
|
||
},
|
||
|
||
/** 根据方向计算y折返偏移量*/
|
||
getYvalueByDirectionCode(defaultVlue, directionCode, num) {
|
||
if (directionCode === '1') {
|
||
defaultVlue -= this.EdgeHeight / 2 * num;
|
||
} else if (directionCode === '2') {
|
||
defaultVlue += this.EdgeHeight / 2 * num;
|
||
}
|
||
|
||
return defaultVlue;
|
||
},
|
||
|
||
/** 根据elem计算y值*/
|
||
getCoordYByElem(stations, kmRangeCoordMap, elem, directionCode, isSpecial, num) {
|
||
var defaultVlue = 0;
|
||
var station = stations.find(it => { return it.code == elem.stationCode; });
|
||
if (station) {
|
||
defaultVlue = kmRangeCoordMap[`${station.kmRange}`];
|
||
if (isSpecial) {
|
||
defaultVlue = this.getYvalueByDirectionCode(defaultVlue, directionCode, num);
|
||
}
|
||
}
|
||
|
||
return defaultVlue;
|
||
}
|
||
};
|