diff --git a/src/App.vue b/src/App.vue index 41cf2fa..b3df125 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,8 @@ diff --git a/src/components/Pragotron.vue b/src/components/Pragotron.vue index b401c92..b82cc79 100644 --- a/src/components/Pragotron.vue +++ b/src/components/Pragotron.vue @@ -14,16 +14,17 @@
-
-
+
+
+
-
+
{{ departure.routeTo.toUpperCase() }}
-
+
{{ departure.routeVia.toUpperCase() }}
-
+
{{ departure.trainType }} {{ departure.trainNo }}
@@ -31,7 +32,7 @@ -
+
{{ departure.delayMinutes }} min
@@ -45,77 +46,97 @@ import { defineComponent, inject, Ref } from 'vue'; -import stationDataJSON from '@/data/stationList.json'; - import { TrainResponse, TrainInfo } from '@/interfaces/TrainAPI'; import { TimetableResponse, TimetableInfo, TimetableStopInfo } from '@/interfaces/TimetableAPI'; +import StationData from '@/interfaces/StationData'; + +interface DepartureInfo { + timetableId: number; + + routeTo: string; + routeVia: string; + + trainNo: number; + trainType: string; + departureDate: Date; + delayMinutes: number; +} export default defineComponent({ data: () => ({ currentStationName: '', - stationDataJSON, + departureList: new Array(8).fill(null) as (DepartureInfo | null)[], }), setup() { - const selectedStationName = inject('selectedStationName') as Ref; + const selectedStation = inject('selectedStation') as Ref; - console.log(selectedStationName.value); + console.log(selectedStation.value.stationName); return { - selectedStationName, + selectedStation, }; }, async mounted() { - /* - 0: "LCS Żywiec" - 1: "https://td2.info.pl/scenerie/lcs-zywiec/" - 2: "97, 139" - 3: null - 4: "10" - 5: "NIE" - 6: "współczesna" - 7: "SCS" - 8: "" - sbl - 9: "" - blokady - 10: 3 - 11: 0 - 12: 0 - 13: 0 - 14: "Węgierska Górka;Żywiec;Łodygowice;Wilkowice Bystra;BB Leszczyny;BB Lipnik, podg." - 15: true - 16: false - 17: false - */ - const trainsAPIResponse: TrainResponse = await ( await fetch('https://api.td2.info.pl:9640/?method=getTrainsOnline') ).json(); - const reducedList = await trainsAPIResponse.message.reduce(async (acc: Promise, train: TrainInfo) => { - const timetableAPIResponse: TimetableResponse = await ( - await fetch(`https://api.td2.info.pl:9640/?method=readFromSWDR&value=getTimetable%3B${train.trainNo}%3Beu`) - ).json(); + const departureList = ( + await trainsAPIResponse.message.reduce(async (acc: Promise, train: TrainInfo) => { + const timetableAPIResponse: TimetableResponse = await ( + await fetch(`https://api.td2.info.pl:9640/?method=readFromSWDR&value=getTimetable%3B${train.trainNo}%3Beu`) + ).json(); - const timetable: TimetableInfo = timetableAPIResponse.message; + const timetable: TimetableInfo = timetableAPIResponse.message; - if (!timetable.trainInfo) return acc; - if (!timetable.stopPoints) return acc; + if (!timetable.trainInfo) return acc; + if (!timetable.stopPoints) return acc; - const stopInfo: TimetableStopInfo | undefined = timetable.stopPoints.find( - (sp) => sp.pointNameRAW == this.selectedStationName - ); + const stopInfo: TimetableStopInfo | undefined = timetable.stopPoints.find( + (sp) => sp.pointNameRAW.toLowerCase() == this.selectedStation.stationName.toLowerCase() + ); - if (!stopInfo) return acc; - if (!stopInfo.departureLine) return acc; - if (stopInfo.confirmed == 1) return acc; + if (!stopInfo) return acc; + if (!stopInfo.departureLine || !stopInfo.departureTime) return acc; + if (stopInfo.confirmed == 1) return acc; - (await acc).push(stopInfo.pointNameRAW + ': ' + timetable.trainInfo.driverName); + const stopInfoIndex = timetable.stopPoints.indexOf(stopInfo); + const { timetableId, trainNo, route, trainCategoryCode } = timetable.trainInfo; + const { departureTime, departureDelay } = stopInfo; - return acc; - }, Promise.resolve([])); + const routeVia = + timetable.stopPoints.find((stop, i) => { + if ( + i > stopInfoIndex && + i != (timetable.stopPoints || []).length - 1 && + stop.pointName.includes('strong') && + stop.pointStopTime && + stop.pointStopTime > 0 + ) + return true; - console.log(reducedList); + return false; + })?.pointNameRAW || ''; + + (await acc).push({ + timetableId, + routeTo: route.split('|')[1], + routeVia, + trainNo, + trainType: trainCategoryCode, + departureDate: departureTime, + delayMinutes: departureDelay, + }); + + return acc; + }, Promise.resolve([])) + ).sort((d1, d2) => (d1.departureDate > d2.departureDate ? 1 : -1)); + + const sortedList = new Array(8).fill(0).map((v, i) => (i > departureList.length ? null : departureList[i])); + + this.departureList = sortedList; }, }); @@ -171,9 +192,11 @@ export default defineComponent({ grid-template-columns: 2fr 2fr 1fr 1fr 1fr; height: 100%; - span { - background: #333; - } + align-items: center; + color: white; + font-size: 1.2em; + + background: #333; } } diff --git a/src/data/stationList.json b/src/data/stationAbbrevs.json similarity index 100% rename from src/data/stationList.json rename to src/data/stationAbbrevs.json diff --git a/src/interfaces/StationAPI.ts b/src/interfaces/StationAPI.ts index a126e51..14cc1d8 100644 --- a/src/interfaces/StationAPI.ts +++ b/src/interfaces/StationAPI.ts @@ -21,4 +21,4 @@ export interface StationResponse { success: boolean; respCode: number; message: StationInfo[]; -} +} \ No newline at end of file diff --git a/src/interfaces/StationData.ts b/src/interfaces/StationData.ts new file mode 100644 index 0000000..81d4600 --- /dev/null +++ b/src/interfaces/StationData.ts @@ -0,0 +1,26 @@ +/* + 0: "LCS Żywiec" + 1: "https://td2.info.pl/scenerie/lcs-zywiec/" + 2: "97, 139" + 3: null + 4: "10" + 5: "NIE" + 6: "współczesna" + 7: "SCS" + 8: "" - sbl + 9: "" - blokady + 10: 3 + 11: 0 + 12: 0 + 13: 0 + 14: "Węgierska Górka;Żywiec;Łodygowice;Wilkowice Bystra;BB Leszczyny;BB Lipnik, podg." + 15: true + 16: false + 17: false +*/ + +export default interface StationData { + stationName: string; + nameAbbreviation: string; + stationCheckpoints: string[]; +} \ No newline at end of file