From ab6984d500da1709ace6f5907d6f092294ded7dc Mon Sep 17 00:00:00 2001 From: Spythere Date: Thu, 17 Feb 2022 22:34:17 +0100 Subject: [PATCH] Poprawka favicon --- public/favicon-64.png | Bin 2142 -> 2122 bytes src/scripts/interfaces/Timetable.ts | 30 ++++---- src/scripts/utils/storeUtils.ts | 13 ++-- src/store/index.ts | 102 ++++++++++++++++------------ 4 files changed, 85 insertions(+), 60 deletions(-) diff --git a/public/favicon-64.png b/public/favicon-64.png index 59641101268e6c8271ca18bf0f717aef911e96de..8ab84b4c73412e911dc6ebe22fc52d5f2e856b5a 100644 GIT binary patch delta 2059 zcmV+m2=w>f5XumcR)60~L_t(|0p(jwOcY5Jehh<-APVAD89c2ABi@XfFdGxI@edCs zh|z#I5B{(oR-@U72hD2SAn_;e$srmg8xLZlH{+0~YvO@XNxaFdUX6|-gb0KCzM`wQ zyQh1my1GXl_>!LPsjk2G>b+O5s$N%6iBVTq7q6_WOnm+Nb$@k5MMZpidOFVcI(`** zWX*7%Y$OuFJC&YMCZLrccThf|#0(%Nk`$5QE5-HoF*8yW zGD2ejk8~Z6UKc+e#@|AD!2p1XGM{C75yoUVPj@bt8w^V_0yDr5;Syd%f&q%sk>xAN z4D1cchzJG1l7A&jx|sM8emqGA@p42ZF%nkd7A;ytf1W>2!!KTl3(rWyI~CP{4dDxI zKWu1d=%4`5k^sZ7UE|IsRLg)c$$-E6`)TdkwYK;FJbg-SyLQcV%ECCw5Nn!*MOrc} z4L|EhgKq|4)X6d8){$GaYL&R0BPsJOT)2>aKXJmf?tkBo9rGmgwOOhpFA1RP3{wh{i(H7lC-U^H)bDMMkbpRrjO5sj5v3G5p3D+SWfD|a8lYeRGDU`vJ0Tydt?&vaTafK@bFwfKM zAYS66K~o-F82}H96y4e~0X)ZRZZD$F1a>Vu*|5b)18`FI?%k`D7dkvRI4F$S_U+rn zU8T&88#jc{0Z8vs1)MJdRd6~=HU>aUxKeG=A08g2w{PDn<(2tBILfJ(fe#=Vph~<2 z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zFcxB~48mvCQ^2CP_gsB$si~o5%a+BS<+Jce@D+dGxIu5v zo=x%DH}ValhxXqm&&d`-*|>+l5&G z%PzSwNuUfuZ52n49!;`}zr;F93BAC0?dF&QR&nguG1)5AvpSJrlNJh)D8n(^q)Z@< z&qO_g`CkF#09HnYsVFQgB&W!xu>b^#1cG@%OG}I1bkr~qeATK|x-(1x1b?7_AUOa= zcu1Ly9FoKT1ZeUSz(6QKlN6S{4+^jxUGZOs*FpN+kx0Zxlb45XWxFUqlMMJi$Q~UB zbkQV(o4yZMSpmF0c7-Mx-2U5fl@;*vBOA0HQ9Hy+PaS0}vi-f|%0-Y*1j&z{t`$l!nzI z^*uIR1kMLw>Hg?VY%-+mm^PCDuqGH4K8n$KL1H<)2k#R|yE;%JZZ-%jAcuT`(M64d zgdJWWs`kRYFSwM4h zGd+I%n9QPh{-oeZp+Qoqc85g(=ZZyA3+M((X|4#Npp~YuZr!@LWo(f=dh|%{S**aa zH0ni?rwrjJE-pU7mwz2(0yG1x2C0Ek%qRx!KGBC5*=o~55ni`4)5frv36h4RON`6G zN5eASym>=L!2sy|`SVH53Ht=tEHOdapy{-+!t4~g*r}~X>}{%Ya8?Zs4ROy9p;cdB zFFQyxKv|ugos^T46X!h98}N4+vIHeq`s;M%3>}zYCA6{<=6~r$jKk~`Yku$Ey>g9N z1xmYl^QN3v?;b-5P(b29D}i<+!UMz0;{3uo(wQr$`)1@}@+snTOaUcAnI`)GW}{~X zfT<%hp-{-rW;w`~u$WYbqy`2CWG5Hh@?j%{n*117;j(zMLuein{ zLUD?0yv`0n@SnKWYoZGqRuOr0R^m&!!xjO-F=aog4tTbMQ-`O& (`https://rj.td2.info.pl/dist/img/thumbnails/${locoType.includes("EN") ? locoType + "rb" : locoType}.png`) @@ -79,7 +80,7 @@ export const timestampToString = (timestamp: number | null): string => }) : ""; -export const getTrainStopStatus = (stopInfo: TrainStop, timetableData: { currentStationName: string }, station: Station) => { +export const getTrainStopStatus = (stopInfo: TrainStop, currentStationName: string, station: Station) => { let stopStatus = "", stopLabel = "", stopStatusID = -1; @@ -88,23 +89,23 @@ export const getTrainStopStatus = (stopInfo: TrainStop, timetableData: { current stopStatus = "terminated"; stopLabel = "Skończył bieg"; stopStatusID = 5; - } else if (!stopInfo.terminatesHere && stopInfo.confirmed && timetableData.currentStationName == station.name) { + } else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName == station.name) { stopStatus = "departed"; stopLabel = "Odprawiony"; stopStatusID = 2; - } else if (!stopInfo.terminatesHere && stopInfo.confirmed && timetableData.currentStationName != station.name) { + } else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName != station.name) { stopStatus = "departed-away"; stopLabel = "Odjechał"; stopStatusID = 4; - } else if (timetableData.currentStationName == station.name && !stopInfo.stopped) { + } else if (currentStationName == station.name && !stopInfo.stopped) { stopStatus = "online"; stopLabel = "Na stacji"; stopStatusID = 0; - } else if (timetableData.currentStationName == station.name && stopInfo.stopped) { + } else if (currentStationName == station.name && stopInfo.stopped) { stopStatus = "stopped"; stopLabel = "Postój"; stopStatusID = 1; - } else if (timetableData.currentStationName != station.name) { + } else if (currentStationName != station.name) { stopStatus = "arriving"; stopLabel = "W drodze"; stopStatusID = 3; diff --git a/src/store/index.ts b/src/store/index.ts index 4c35c40..8c58626 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -26,6 +26,7 @@ import ScheduledTrain from '@/scripts/interfaces/ScheduledTrain'; export interface State { stationList: Station[], trainList: Train[], + timetableList: Timetable[], sceneryData: any[][], @@ -85,6 +86,7 @@ export const store = createStore({ state: () => ({ stationList: [], trainList: [], + timetableList: [], sceneryData: [], @@ -237,11 +239,17 @@ export const store = createStore({ async fetchTimetableData({ commit }) { let warnings = 0; - const reducedList = this.state.trainList.reduce(async (acc: Promise, train: Train) => { + const timetableList = this.state.trainList.reduce(async (acc: Promise, train: Train) => { const data: { success: boolean; message: TimetableAPIData } = await (await axios.get(URLs.getTimetableURL(train.trainNo, this.state.region.id))).data; if (!data.success) { warnings++; + + (await acc).push({ + trainNo: train.trainNo, + success: false + }); + return acc; } @@ -312,25 +320,30 @@ export const store = createStore({ }, []); (await acc).push({ + data: { + trainNo: train.trainNo, + driverName: train.driverName, + driverId: train.driverId, + currentStationName: train.currentStationName, + currentStationHash: train.currentStationHash, + timetableId: trainInfo.timetableId, + category: trainInfo.trainCategoryCode, + route: trainInfo.route, + TWR: trainInfo.twr, + SKR: trainInfo.skr, + routeDistance: timetable.stopPoints[timetable.stopPoints.length - 1].pointDistance, + followingStops, + followingSceneries: trainInfo.sceneries + }, + trainNo: train.trainNo, - driverName: train.driverName, - driverId: train.driverId, - currentStationName: train.currentStationName, - currentStationHash: train.currentStationHash, - timetableId: trainInfo.timetableId, - category: trainInfo.trainCategoryCode, - route: trainInfo.route, - TWR: trainInfo.twr, - SKR: trainInfo.skr, - routeDistance: timetable.stopPoints[timetable.stopPoints.length - 1].pointDistance, - followingStops, - followingSceneries: trainInfo.sceneries + success: true }); return acc; }, Promise.resolve([])); - commit(MUTATIONS.UPDATE_TIMETABLES, (await reducedList)); + commit(MUTATIONS.UPDATE_TIMETABLES, (await timetableList)); commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, warnings == 0 ? DataStatus.Loaded : DataStatus.Warning); } @@ -346,9 +359,6 @@ export const store = createStore({ checkpoints: stationData.checkpoints ? stationData.checkpoints.split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [], } })); - - console.log(state.stationList); - }, @@ -441,9 +451,12 @@ export const store = createStore({ const stationName = station.name.toLowerCase(); const scheduledTrains: ScheduledTrain[] = timetableList.reduce((acc: ScheduledTrain[], timetable: Timetable) => { - if (!timetable.followingSceneries.includes(station.onlineInfo?.hash || "")) return acc; + if (!timetable.data) + return acc; - const stopInfoIndex = timetable.followingStops.findIndex(stop => { + if (!timetable.data.followingSceneries.includes(station.onlineInfo?.hash || "")) return acc; + + const stopInfoIndex = timetable.data.followingStops.findIndex(stop => { const stopName = stop.stopNameRAW.toLowerCase(); // if (stop.stopName == "ARKADIA ZDRÓJ" && station.name == "Arkadia Zdrój 2019" && stop.pointId != "1583014379097") return false; @@ -466,18 +479,18 @@ export const store = createStore({ if (stopInfoIndex == -1) return acc; - const trainStop = timetable.followingStops[stopInfoIndex]; - const trainStopStatus = getTrainStopStatus(trainStop, timetable, station); + const trainStop = timetable.data.followingStops[stopInfoIndex]; + const trainStopStatus = getTrainStopStatus(trainStop, timetable.data.currentStationName, station); acc.push({ - trainNo: timetable.trainNo, - driverName: timetable.driverName, - driverId: timetable.driverId, - currentStationName: timetable.currentStationName, - currentStationHash: timetable.currentStationHash, - category: timetable.category, - beginsAt: timetable.followingStops[0].stopNameRAW, - terminatesAt: timetable.followingStops[timetable.followingStops.length - 1].stopNameRAW, + trainNo: timetable.data.trainNo, + driverName: timetable.data.driverName, + driverId: timetable.data.driverId, + currentStationName: timetable.data.currentStationName, + currentStationHash: timetable.data.currentStationHash, + category: timetable.data.category, + beginsAt: timetable.data.followingStops[0].stopNameRAW, + terminatesAt: timetable.data.followingStops[timetable.data.followingStops.length - 1].stopNameRAW, nearestStop: "", stopInfo: trainStop, stopLabel: trainStopStatus.stopLabel, @@ -493,22 +506,25 @@ export const store = createStore({ for (const checkpoint of station.generalInfo.checkpoints) { timetableList.forEach(timetable => { - if (!timetable.followingSceneries.includes(station.onlineInfo?.hash || "")) return; + if (!timetable.data) return; + if (!timetable.data.followingSceneries.includes(station.onlineInfo?.hash || "")) return; - timetable.followingStops + const timetableData = timetable.data; + + timetableData.followingStops .filter(trainStop => trainStop.stopNameRAW.toLowerCase() === checkpoint.checkpointName.toLowerCase()) .forEach(trainStop => { - const trainStopStatus = getTrainStopStatus(trainStop, timetable, station); + const trainStopStatus = getTrainStopStatus(trainStop, timetableData.currentStationName, station); checkpoint.scheduledTrains.push({ trainNo: timetable.trainNo, - driverName: timetable.driverName, - driverId: timetable.driverId, - currentStationName: timetable.currentStationName, - currentStationHash: timetable.currentStationHash, - category: timetable.category, - beginsAt: timetable.followingStops[0].stopNameRAW, - terminatesAt: timetable.followingStops[timetable.followingStops.length - 1].stopNameRAW, + driverName: timetableData.driverName, + driverId: timetableData.driverId, + currentStationName: timetableData.currentStationName, + currentStationHash: timetableData.currentStationHash, + category: timetableData.category, + beginsAt: timetableData.followingStops[0].stopNameRAW, + terminatesAt: timetableData.followingStops[timetableData.followingStops.length - 1].stopNameRAW, nearestStop: "", stopInfo: trainStop, stopLabel: trainStopStatus.stopLabel, @@ -531,8 +547,10 @@ export const store = createStore({ }); state.trainList = state.trainList.reduce((acc, train) => { - const timetableData = timetableList.find(data => data && data.trainNo === train.trainNo && data.driverId === train.driverId); - const allTimetables = timetableList.filter(data => data && data.driverId === train.driverId && data.trainNo !== train.trainNo); + const timetable = timetableList.find(tt => tt.data && tt.trainNo === train.trainNo && tt.data.driverId === train.driverId); + const allTimetables = timetableList.filter(tt => tt.data && tt.data.driverId === train.driverId && tt.trainNo !== train.trainNo); + + if (!timetable || !timetable.data) return acc; if (allTimetables.length > 0) return acc; @@ -541,7 +559,7 @@ export const store = createStore({ .find(station => station.name === train.currentStationName) ?.onlineInfo?.scheduledTrains?.find(stationTrain => stationTrain.trainNo === train.trainNo); - acc.push({ ...train, timetableData, stopStatus: trainStopData?.stopStatus || "", stopLabel: trainStopData?.stopLabel || "" }); + acc.push({ ...train, timetableData: timetable.data, stopStatus: trainStopData?.stopStatus || "", stopLabel: trainStopData?.stopLabel || "" }); return acc; }, [] as Train[]);