From fcd3ba4a3ba33e5a07f846bffacf27811a709943 Mon Sep 17 00:00:00 2001 From: Spythere Date: Wed, 26 Aug 2020 21:28:34 +0200 Subject: [PATCH] =?UTF-8?q?Dodano=20statystki=20ruchu=20kolejowego=20w=20z?= =?UTF-8?q?ak=C5=82adce=20Poci=C4=85gi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/StationsView/StationTable.vue | 6 +- src/components/TrainsView/TrainStats.vue | 258 +++++++++++++++++++ src/components/TrainsView/TrainTable.vue | 18 +- src/store/modules/store.ts | 70 ++++- src/store/modules/trains.ts | 19 +- src/views/TrainsView.vue | 4 + 6 files changed, 356 insertions(+), 19 deletions(-) create mode 100644 src/components/TrainsView/TrainStats.vue diff --git a/src/components/StationsView/StationTable.vue b/src/components/StationsView/StationTable.vue index a89d743..494a1db 100644 --- a/src/components/StationsView/StationTable.vue +++ b/src/components/StationsView/StationTable.vue @@ -118,10 +118,10 @@ >{{station.routes.oneWay.noCatenary}} - {{station.scheduledTrains.length}} + >{{station.scheduledTrains.length}}--> @@ -166,7 +166,7 @@ export default class StationTable extends styleMixin { ["Maszyniści"], ["Informacje", "ogólne"], ["Szlaki", "2tor | 1tor"], - ["Aktywne RJ"], + // ["Aktywne RJ"], ]; changeSorter(index: number) { diff --git a/src/components/TrainsView/TrainStats.vue b/src/components/TrainsView/TrainStats.vue new file mode 100644 index 0000000..a293628 --- /dev/null +++ b/src/components/TrainsView/TrainStats.vue @@ -0,0 +1,258 @@ + + + + + \ No newline at end of file diff --git a/src/components/TrainsView/TrainTable.vue b/src/components/TrainsView/TrainTable.vue index 4d3196b..f75ca12 100644 --- a/src/components/TrainsView/TrainTable.vue +++ b/src/components/TrainsView/TrainTable.vue @@ -117,19 +117,11 @@ export default class TrainTable extends Vue { } mapTimetableSceneries(sceneries: string[]): string { - let text = ""; + if (sceneries.length < 1) return ""; - for (let i = sceneries.length - 2; i > 0; i--) { - const station = this.stations.find( - (station) => station.stationHash == sceneries[i] - ); - - if (!station) continue; - - text += `${station.stationName}${i > 1 ? ", " : ""}`; - } - - return text; + return sceneries + .filter((scenery, i) => i > 0 && i < sceneries.length - 1) + .join(" * "); } } @@ -166,7 +158,7 @@ export default class TrainTable extends Vue { background-color: #444; padding: 1rem; - margin: 1rem 0; + margin-bottom: 1em; &:nth-child(even) { background-color: #666; diff --git a/src/store/modules/store.ts b/src/store/modules/store.ts index 8e611ac..80ffa6a 100644 --- a/src/store/modules/store.ts +++ b/src/store/modules/store.ts @@ -113,6 +113,55 @@ async function getScheduledTrains(stationName: string) { return scheduledTrains; } + +async function testLoad() { + let scheduledTrains: any[] = []; + + for (let train of onlineTrainsData) { + if (train.region !== "eu" || !train.isOnline) continue; + + const timetable = await queryTimetableData(train.trainNo); + + if (!timetable.trainInfo) continue; + + timetable.stopPoints.forEach((point) => { + const station = onlineStationsData.find( + (online) => + online.stationName + .toLowerCase() + .includes(point.pointNameRAW.toLowerCase()) || + online.stationName + .toLowerCase() + .includes(point.pointNameRAW.toLowerCase().split(" ")[0]) || + online.stationName + .toLowerCase() + .includes(point.pointNameRAW.toLowerCase().split(",")[0]) + ); + + if (!station) return; + + if (!scheduledTrains[station.stationName]) + scheduledTrains[station.stationName] = []; + + if ( + scheduledTrains[station.stationName].find( + (scheduled) => train.trainNo === scheduled.trainNo + ) + ) + return; + + scheduledTrains[station.stationName].push({ + arrivalTime: point?.arrivalTime, + departureTime: point?.departureTime, + trainCategory: timetable.trainInfo?.trainCategoryCode, + trainNo: train.trainNo, + }); + }); + } + + return scheduledTrains; +} + @Module class Store extends VuexModule { private trainCount: number = 0; @@ -122,6 +171,13 @@ class Store extends VuexModule { private stations: Station[] = []; + // private scheduledTrains: { + // trainNo: number; + // trainCategory: string; + // arrivalTime: string; + // departureTime: string; + // }[] = []; + private filteredStations: {}[] = []; private filterInitStates = { @@ -267,7 +323,7 @@ class Store extends VuexModule { // station.stationName // ); - let scheduledTrains = []; + let scheduledTrains: any[] = []; return { ...stationData, @@ -293,6 +349,18 @@ class Store extends VuexModule { }) ); + // const scheduled = await testLoad(); + + // for (let stationName in scheduled) { + // let t = updatedStations.find( + // (updated) => updated.stationName === stationName + // ); + + // if (!t) continue; + + // t.scheduledTrains = scheduled[stationName]; + // } + this.context.commit("updateStations", { updatedStations, trainCount: onlineTrainsData.filter( diff --git a/src/store/modules/trains.ts b/src/store/modules/trains.ts index 2c1929f..5586e2f 100644 --- a/src/store/modules/trains.ts +++ b/src/store/modules/trains.ts @@ -27,7 +27,11 @@ interface TrainData { } interface TimetableResponseData { - stopPoints: { pointDistance: number }[] | []; + stopPoints: { + pointDistance: number; + pointNameRAW: string; + pointName: string; + }[]; trainInfo: { timetableId: number; trainCategoryCode: string; @@ -100,6 +104,17 @@ export default class TrainsModule extends VuexModule { ? train.dataCon.split(";")[0] : train.dataCon; + const stopPoints = timetableResponseData?.stopPoints.reduce( + (acc, point) => { + if (point.pointName.includes("strong")) { + acc.push(point.pointNameRAW); + } + + return acc; + }, + [] as string[] + ); + return { driverId: train.driverId, driverName: train.driverName, @@ -118,7 +133,7 @@ export default class TrainsModule extends VuexModule { timetableId: timetableData && timetableData.timetableId, category: timetableData && timetableData.trainCategoryCode, routeDistance: (timetableData && timetableData.routeDistance) || 0, - sceneries: timetableData && timetableData.sceneries, + sceneries: stopPoints, TWR: timetableData && timetableData.twr, SKR: timetableData && timetableData.skr, }; diff --git a/src/views/TrainsView.vue b/src/views/TrainsView.vue index 799b4fa..c4b0001 100644 --- a/src/views/TrainsView.vue +++ b/src/views/TrainsView.vue @@ -16,6 +16,8 @@ + + @@ -33,6 +35,7 @@ import Loading from "@/components/App/Loading.vue"; import TrainSorter from "@/components/TrainsView/TrainSorter.vue"; import TrainTable from "@/components/TrainsView/TrainTable.vue"; +import TrainStats from "@/components/TrainsView/TrainStats.vue"; import axios from "axios"; @@ -41,6 +44,7 @@ import axios from "axios"; Loading, TrainSorter, TrainTable, + TrainStats, }, }) export default class TrainsView extends Vue {