mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
fix: recognizing timetables for sceneries with the same stop names; optimization
This commit is contained in:
@@ -238,11 +238,12 @@ export default defineComponent({
|
|||||||
sceneryTimetables(): SceneryTimetableRow[] {
|
sceneryTimetables(): SceneryTimetableRow[] {
|
||||||
if (!this.onlineScenery) return [];
|
if (!this.onlineScenery) return [];
|
||||||
|
|
||||||
const sceneryName = this.$route.query['station']?.toString() ?? '';
|
const sceneryName = this.$route.query['station']?.toString().replace(/_/g, ' ') ?? '';
|
||||||
|
|
||||||
return this.onlineScenery.scheduledTrains
|
return this.onlineScenery.scheduledTrains
|
||||||
.filter(
|
.filter(
|
||||||
(ct) =>
|
(ct) =>
|
||||||
|
ct.timetablePathElement.stationName == sceneryName &&
|
||||||
ct.train.region == this.mainStore.region.id &&
|
ct.train.region == this.mainStore.region.id &&
|
||||||
this.chosenCheckpoint &&
|
this.chosenCheckpoint &&
|
||||||
ct.checkpointStop.stopNameRAW.toLowerCase() == this.chosenCheckpoint.toLowerCase()
|
ct.checkpointStop.stopNameRAW.toLowerCase() == this.chosenCheckpoint.toLowerCase()
|
||||||
@@ -251,75 +252,18 @@ export default defineComponent({
|
|||||||
const trainStopStatus = getTrainStopStatus(
|
const trainStopStatus = getTrainStopStatus(
|
||||||
ct.checkpointStop,
|
ct.checkpointStop,
|
||||||
ct.train.currentStationName,
|
ct.train.currentStationName,
|
||||||
sceneryName.replace(/_/g, ' ')
|
sceneryName
|
||||||
);
|
);
|
||||||
|
|
||||||
const trainStopIndex =
|
|
||||||
ct.train.timetableData?.followingStops.findIndex(
|
|
||||||
(stop) => stop.stopName == ct.checkpointStop.stopName
|
|
||||||
) ?? -1;
|
|
||||||
|
|
||||||
let prevStationName = '',
|
|
||||||
nextStationName = '';
|
|
||||||
|
|
||||||
let departureLine: string | null = null;
|
|
||||||
let arrivingLine: string | null = null;
|
|
||||||
|
|
||||||
let prevDepartureLine: string | null = null,
|
|
||||||
nextArrivalLine: string | null = null;
|
|
||||||
|
|
||||||
if (trainStopIndex > -1 && ct.train.timetableData?.followingStops !== undefined) {
|
|
||||||
for (let i = trainStopIndex; i >= 0; i--) {
|
|
||||||
const stop = ct.train.timetableData.followingStops[i];
|
|
||||||
|
|
||||||
if (
|
|
||||||
/strong|podg\.|pe\./g.test(stop.stopName) &&
|
|
||||||
!prevStationName &&
|
|
||||||
i <= trainStopIndex - 1
|
|
||||||
)
|
|
||||||
prevStationName = stop.stopNameRAW.replace(/,.*/g, '');
|
|
||||||
|
|
||||||
if (
|
|
||||||
stop.arrivalLine != null &&
|
|
||||||
!arrivingLine &&
|
|
||||||
!/-|_|it|sbl/gi.test(stop.arrivalLine)
|
|
||||||
) {
|
|
||||||
arrivingLine = stop.arrivalLine;
|
|
||||||
prevDepartureLine =
|
|
||||||
ct.train.timetableData.followingStops[i - 1]?.departureLine || null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = trainStopIndex; i < ct.train.timetableData.followingStops.length; i++) {
|
|
||||||
const stop = ct.train.timetableData.followingStops[i];
|
|
||||||
|
|
||||||
if (
|
|
||||||
/strong|podg\.|pe\./g.test(stop.stopName) &&
|
|
||||||
!nextStationName &&
|
|
||||||
i > trainStopIndex
|
|
||||||
)
|
|
||||||
nextStationName = stop.stopNameRAW.replace(/,.*/g, '');
|
|
||||||
|
|
||||||
if (
|
|
||||||
stop.departureLine &&
|
|
||||||
!departureLine &&
|
|
||||||
!/-|_|it|sbl/gi.test(stop.departureLine)
|
|
||||||
) {
|
|
||||||
departureLine = stop.departureLine;
|
|
||||||
nextArrivalLine = ct.train.timetableData.followingStops[i + 1]?.arrivalLine || null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkpointStop: ct.checkpointStop,
|
checkpointStop: ct.checkpointStop,
|
||||||
train: ct.train,
|
train: ct.train,
|
||||||
prevDepartureLine,
|
prevDepartureLine: ct.previousSceneryElement?.departureRouteExt ?? null,
|
||||||
nextArrivalLine,
|
nextArrivalLine: ct.nextSceneryElement?.arrivalRouteExt ?? null,
|
||||||
departureLine,
|
departureLine: ct.timetablePathElement.departureRouteExt ?? null,
|
||||||
arrivingLine,
|
arrivingLine: ct.timetablePathElement.arrivalRouteExt ?? null,
|
||||||
prevStationName,
|
prevStationName: ct.previousSceneryElement?.stationName ?? null,
|
||||||
nextStationName,
|
nextStationName: ct.nextSceneryElement?.stationName ?? null,
|
||||||
status: trainStopStatus
|
status: trainStopStatus
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
+35
-5
@@ -96,7 +96,17 @@ export const useMainStore = defineStore('mainStore', {
|
|||||||
followingStops: timetable.stopList,
|
followingStops: timetable.stopList,
|
||||||
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
||||||
sceneries: timetable.sceneries,
|
sceneries: timetable.sceneries,
|
||||||
sceneryNames: sceneryNames.reverse()
|
sceneryNames: sceneryNames.reverse(),
|
||||||
|
timetablePath: timetable.path.split(';').map((pathElementString) => {
|
||||||
|
const [arrival, station, departure] = pathElementString.split(',');
|
||||||
|
|
||||||
|
return {
|
||||||
|
arrivalRouteExt: arrival,
|
||||||
|
departureRouteExt: departure,
|
||||||
|
stationName: station.split(' ').slice(0, -1).join(' '),
|
||||||
|
stationHash: station.split(' ').slice(-1).join(' ')
|
||||||
|
};
|
||||||
|
})
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
} as Train;
|
} as Train;
|
||||||
@@ -110,11 +120,25 @@ export const useMainStore = defineStore('mainStore', {
|
|||||||
} else sceneriesTrains.set(train.currentStationName, [trainObj]);
|
} else sceneriesTrains.set(train.currentStationName, [trainObj]);
|
||||||
|
|
||||||
// Checkpoints trains map
|
// Checkpoints trains map
|
||||||
timetable?.stopList.forEach((stop, i) => {
|
if (trainObj.timetableData) {
|
||||||
|
let currentSceneryIndex = 0;
|
||||||
|
const timetablePath = trainObj.timetableData.timetablePath;
|
||||||
|
|
||||||
|
trainObj.timetableData.followingStops.forEach((stop, i) => {
|
||||||
if (/strong|podg\.|pe\./.test(stop.stopName)) {
|
if (/strong|podg\.|pe\./.test(stop.stopName)) {
|
||||||
const checkpointTrain: CheckpointTrain = {
|
const checkpointTrain: CheckpointTrain = {
|
||||||
train: trainObj,
|
train: trainObj,
|
||||||
checkpointStop: stop
|
checkpointStop: stop,
|
||||||
|
|
||||||
|
previousSceneryElement:
|
||||||
|
currentSceneryIndex > 0 ? timetablePath[currentSceneryIndex - 1] : null,
|
||||||
|
|
||||||
|
nextSceneryElement:
|
||||||
|
currentSceneryIndex < timetablePath.length - 1
|
||||||
|
? timetablePath[currentSceneryIndex + 1]
|
||||||
|
: null,
|
||||||
|
|
||||||
|
timetablePathElement: timetablePath[currentSceneryIndex]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (checkpointsTrains.has(stop.stopNameRAW.toLowerCase())) {
|
if (checkpointsTrains.has(stop.stopNameRAW.toLowerCase())) {
|
||||||
@@ -124,7 +148,11 @@ export const useMainStore = defineStore('mainStore', {
|
|||||||
]);
|
]);
|
||||||
} else checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [checkpointTrain]);
|
} else checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [checkpointTrain]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timetablePath[currentSceneryIndex].departureRouteExt == stop.departureLine)
|
||||||
|
currentSceneryIndex++;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return trainObj;
|
return trainObj;
|
||||||
});
|
});
|
||||||
@@ -252,8 +280,10 @@ export const useMainStore = defineStore('mainStore', {
|
|||||||
|
|
||||||
if (!scheduledTrains) return;
|
if (!scheduledTrains) return;
|
||||||
|
|
||||||
scheduledTrains.forEach(({ train, checkpointStop }) => {
|
scheduledTrains.forEach(({ train, checkpointStop, timetablePathElement, ...v }) => {
|
||||||
scenery.scheduledTrains.push({ train, checkpointStop });
|
if (scenery.name != timetablePathElement.stationName) return;
|
||||||
|
|
||||||
|
scenery.scheduledTrains.push({ train, checkpointStop, timetablePathElement, ...v });
|
||||||
|
|
||||||
if (uniqueTrainIds.includes(train.id) || train.region != this.region.id) return;
|
if (uniqueTrainIds.includes(train.id) || train.region != this.region.id) return;
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ export namespace API {
|
|||||||
TWR: boolean;
|
TWR: boolean;
|
||||||
SKR: boolean;
|
SKR: boolean;
|
||||||
sceneries: string[];
|
sceneries: string[];
|
||||||
|
|
||||||
|
path: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ export interface RegionCounters {
|
|||||||
timetablesCount: number;
|
timetablesCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TimetablePathElement {
|
||||||
|
arrivalRouteExt?: string;
|
||||||
|
departureRouteExt?: string;
|
||||||
|
stationName: string;
|
||||||
|
stationHash: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Train {
|
export interface Train {
|
||||||
id: string;
|
id: string;
|
||||||
modalId: string;
|
modalId: string;
|
||||||
@@ -73,6 +80,7 @@ export interface Train {
|
|||||||
routeDistance: number;
|
routeDistance: number;
|
||||||
sceneries: string[];
|
sceneries: string[];
|
||||||
sceneryNames: string[];
|
sceneryNames: string[];
|
||||||
|
timetablePath: TimetablePathElement[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +196,9 @@ export interface TrainStop {
|
|||||||
export interface CheckpointTrain {
|
export interface CheckpointTrain {
|
||||||
checkpointStop: TrainStop;
|
checkpointStop: TrainStop;
|
||||||
train: Train;
|
train: Train;
|
||||||
|
timetablePathElement: TimetablePathElement;
|
||||||
|
previousSceneryElement: TimetablePathElement | null;
|
||||||
|
nextSceneryElement: TimetablePathElement | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vehicles Data
|
// Vehicles Data
|
||||||
|
|||||||
Reference in New Issue
Block a user