-
-
-
- {{ departure.routeTo.toUpperCase() }}
+
+
+
+
+ {{ departure.routeTo.toUpperCase() }}
+
+
-
- {{ departure.routeVia.toUpperCase() }}
+
+
+
+ {{ departure.routeVia.toUpperCase() }}
+
+
- {{ departure.trainType }} {{ departure.trainNo }}
+
+ {{ departure.trainNumber }}
+
+
-
-
-
+
+ {{
+ departure.departureDigits[0]
+ }}
+
+
+
+
+ {{ departure.departureDigits[1] }}
+
+
+ :
+
+
+
+ {{ departure.departureDigits[2] }}
+
+
+
+
+
+ {{ departure.departureDigits[3] }}
+
+
+
- {{ departure.delayMinutes }} min
+
+
+ {{ departure.delayMinutes > 0 ? departure.delayMinutes + ' min' : '' }}
+
+
@@ -46,6 +83,9 @@
import { defineComponent, inject, Ref } from 'vue';
+import stationAbbrevs from '@/data/stationAbbrevs.json';
+import routeValues from '@/data/routeValues.json';
+
import { TrainResponse, TrainInfo } from '@/interfaces/TrainAPI';
import { TimetableResponse, TimetableInfo, TimetableStopInfo } from '@/interfaces/TimetableAPI';
import StationData from '@/interfaces/StationData';
@@ -56,16 +96,26 @@ interface DepartureInfo {
routeTo: string;
routeVia: string;
- trainNo: number;
- trainType: string;
+ trainNumber: string;
+
departureDate: Date;
+ departureDigits: string[];
+
delayMinutes: number;
+
+ currentRouteTo: string;
+ currentRouteVia?: string;
}
export default defineComponent({
data: () => ({
currentStationName: '',
- departureList: new Array(8).fill(null) as (DepartureInfo | null)[],
+
+ seekingTable: [],
+
+ departureList: [] as DepartureInfo[],
+
+ stationAbbrevs: stationAbbrevs as { [key: string]: string },
}),
setup() {
@@ -78,7 +128,90 @@ export default defineComponent({
};
},
+ methods: {
+ addSeekedValue(desiredValue: string, sourceCollection: string[], startIndex: number = 0) {
+ let currentIndex = startIndex - 1;
+ let collection = [...sourceCollection];
+
+ if (!collection.includes(desiredValue)) collection.push(desiredValue);
+
+ let tempSwap, randIndex;
+ for (let i = 1; i < collection.length; i++) {
+ randIndex = Math.floor(Math.random() * collection.length);
+
+ if (randIndex == 0) randIndex++;
+
+ tempSwap = collection[i];
+
+ collection[i] = collection[randIndex];
+ collection[randIndex] = tempSwap;
+ }
+
+ console.log('Desired value:', desiredValue);
+
+ const intv = setInterval(() => {
+ const currentValue = collection[++currentIndex];
+
+ if (currentIndex > collection.length - 1) {
+ console.log('Value not found!');
+
+ clearInterval(intv);
+ return;
+ }
+
+ if (currentValue == desiredValue) {
+ console.log('Value found:', currentValue);
+
+ clearInterval(intv);
+ return;
+ }
+
+ console.log('Seeking value...', currentValue, currentIndex);
+ }, 100);
+ },
+ fillTable(responseArray: DepartureInfo[] = []) {
+ if (this.departureList.length == 0)
+ this.departureList = new Array(7).fill({
+ timetableId: -1,
+
+ routeTo: '',
+ routeVia: '',
+
+ trainNumber: '',
+
+ departureDate: new Date(0),
+ departureDigits: [],
+
+ delayMinutes: 0,
+ currentRouteTo: '',
+ });
+
+ for (let i = 0; i < this.departureList.length; i++) {
+ if (i > responseArray.length - 1)
+ this.departureList[i] = {
+ timetableId: -1,
+
+ routeTo: '',
+ routeVia: '',
+
+ trainNumber: '',
+
+ departureDate: new Date(0),
+ departureDigits: [],
+
+ delayMinutes: 0,
+ currentRouteTo: '',
+ };
+ else this.departureList[i] = { ...responseArray[i] };
+ }
+ },
+ },
+
async mounted() {
+ this.fillTable();
+
+ this.addSeekedValue('Test', routeValues, 0);
+
const trainsAPIResponse: TrainResponse = await (
await fetch('https://api.td2.info.pl:9640/?method=getTrainsOnline')
).json();
@@ -120,31 +253,94 @@ export default defineComponent({
return false;
})?.pointNameRAW || '';
+ const departureDate = new Date(departureTime);
+
+ // [HH, MM, SS] - nienawidzę dat w JavaScripcie
+ const dateArray = departureDate.toLocaleString('pl-PL').split(', ')[1].split(':');
+
+ // [H,H,M,M] - ZABIJCIE MNIE BŁAGAM
+ const departureDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
+
+ const routeTo = route.split('|')[1];
+ const routeToAbbrev = this.stationAbbrevs[routeTo] || null;
+
(await acc).push({
timetableId,
- routeTo: route.split('|')[1],
+ routeTo: routeToAbbrev || routeTo,
routeVia,
- trainNo,
- trainType: trainCategoryCode,
- departureDate: departureTime,
+ trainNumber: `${trainCategoryCode} ${trainNo}`,
+ departureDate: new Date(departureTime),
+ departureDigits,
delayMinutes: departureDelay,
+ currentRouteTo: routeValues[0],
});
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.fillTable(departureList);
- this.departureList = sortedList;
+ // const sortedList: DepartureInfo[] = new Array(8)
+ // .fill({
+ // timetableId: -1,
+
+ // routeTo: '',
+ // routeVia: '',
+
+ // trainNumber: '',
+
+ // departureDate: new Date(0),
+ // departureDigits: [],
+
+ // delayMinutes: 0,
+ // currentRouteTo: '',
+ // })
+ // .map((v, i) => (i > departureList.length - 1 ? v : departureList[i]));
+
+ // setInterval(() => {
+ // sortedList.forEach(d => {
+ // if(d.currentRouteTo == d.routeTo)
+ // return;
+
+ // })
+ // }, 500);
},
});
diff --git a/src/data/routeValues.json b/src/data/routeValues.json
new file mode 100644
index 0000000..af16700
--- /dev/null
+++ b/src/data/routeValues.json
@@ -0,0 +1 @@
+["", "Aleksandrów Kujawski","Arkadia Zdrój","Babimost","Bargowice","Bargowice Zachód","Horz Zdrój","Bełchów","Blaszki","Borki","Brakowice","Buczek","Buk","Bystra Woda","Cenorzyce Nowe","Chełmik Wołowski","Chlorkowice","Cis","Czerepy","Czermin","Dobrzyca DTA","Dobrzyca DTB","Dobrzyca DTC","Dobrzyniec","Dobrzyniec Mącice","Drzewko","Dziewoszyce","Falewo","Glinnik","Grabów Miasto","Grabów Wieś","Góra Włodowska","Głogowo","Głębce","Głęboszów","Imielin","Jordanowo","Karszynek","Kcynia","Kieły","Kolsko","Kowalewo","Krzemienice","Krzęcz","Kszęty","Kudowa Zdrój","Głowno","Domaniewice","Ozorków","Chociszew","Skrzynki","Wykno","Żywiec","Węgierska Górka","Łodygowice","Wilkowice Bystra","BB Leszczyny","Legno","Lewków","Ligota Grabowska","Ligota Trzeszcze","Lisiczki","Lisków","TEFAMA","Lisków Miasto","Lublinek","Lutol Suchy","Luzino","Lębork","Milówka","Modlinków","Motławy","Naterki","Okoń Główny","Orniki","Otwocko","Parów","Piaskowo","Pilichowice","Poreńsk","Radostowice","Radowice","Radzikowo","Rajcza","Razemsko","Rebrowo Dolne","Redlin Sudecki","Santok Zdrój","Sieniawka","Skawce","Sowi Bór","Sroka","Stare Lipowo","Przęsy","Starzynki","Stefanowo","Stryków","Strączki","Sulechów","Szadek","Sól","Tarkowo","Tartakowo","Testowo","Trawniczki","Tłoki","Wełtawa","Wielichowo Główne","Wielichowo Główne gt","Wielichowo Wieś","Wijewo","Wilczyca","Witaszyczki","Witonia","Wodnica","Wola","Wola Nowska","Wschodna","Zgierz","Zgierz Kontrewers","Zwardoń","Łask","Łaskarzew","Łebnino","Łęczyca","Żerniki","Żory"]
\ No newline at end of file
diff --git a/src/data/stationAbbrevs.json b/src/data/stationAbbrevs.json
index 61f3149..d7d5ead 100644
--- a/src/data/stationAbbrevs.json
+++ b/src/data/stationAbbrevs.json
@@ -1 +1,3 @@
-[["Aleksandrów Kujawski","Aleksandrów Kuj."],["Arkadia Zdrój","Arkadia Zdr."],["Babimost","Babimost"],["Bargowice","Bargowice"],["Bełchów","Bełchów"],["Blaszki","Blaszki"],["Borki","Borki"],["Brakowice","Brakowice"],["Buczek","Buczek"],["Buk","Buk"],["Bystra Woda","Bystra Woda"],["Cenorzyce Nowe","Cenorzyce Nowe"],["Chełmik Wołowski","Chełmik Woł."],["Chlorkowice","Chlorkowice"],["Cis","Cis"],["Czerepy","Czerepy"],["Czermin","Czermin"],["Dobrzyca Towarowa","Dobrzyca Tow."],["Dobrzyniec","Dobrzyniec"],["Drzewko","Drzewko"],["Dziewoszyce","Dziewoszyce"],["Falewo","Falewo"],["Glinnik","Glinnik"],["Grabów Miasto","Grabów Miasto"],["Góra Włodowska","Góra Włodowska"],["Głogowo","Głogowo"],["Głębce","Głębce"],["Głęboszów","Głęboszów"],["Imielin","Imielin"],["Jordanowo","Jordanowo"],["Karszynek","Karszynek"],["Kcynia","Kcynia"],["Kieły","Kieły"],["Kolsko","Kolsko"],["Kowalewo","Kowalewo"],["Krzemienice","Krzemienice"],["Krzęcz","Krzęcz"],["Kszęty","Kszęty"],["Kudowa Zdrój","Kudowa Zdrój"],["Głowno","Głowno"],["Ozorków","Ozorków"],["Skrzynki","Skrzynki"],["Żywiec","Żywiec"],["Legno","Legno"],["Lewków","Lewków"],["Ligota Grabowska","Ligota Grab."],["Lisiczki","Lisiczki"],["Lisków","Lisków"],["Lisków Miasto","Lisków Miasto"],["Lublinek","Lublinek"],["Lutol Suchy","Lutol Suchy"],["Luzino","Luzino"],["Lębork","Lębork"],["Milówka","Milówka"],["Modlinków","Modlinków"],["Motławy","Motławy"],["Naterki","Naterki"],["Okoń Główny","Okoń Gł."],["Orniki","Orniki"],["Otwocko","Otwocko"],["Parów","Parów"],["Piaskowo","Piaskowo"],["Pilichowice","Pilichowice"],["Poreńsk","Poreńsk"],["Radostowice","Radostowice"],["Radowice","Radowice"],["Radzikowo","Radzikowo"],["Rajcza","Rajcza"],["Razemsko","Razemsko"],["Rebrowo Dolne","Rebrowo Dol."],["Redlin Sudecki","Redlin Sudecki"],["Santok Zdrój","Santok Zdr."],["Sieniawka","Sieniawka"],["Skawce","Skawce"],["Sowi Bór","Sowi Bór"],["Sroka","Sroka"],["Stare Lipowo","Stare Lipowo"],["Starzynki","Starzynki"],["Stefanowo","Stefanowo"],["Stryków","Stryków"],["Strączki","Strączki"],["Sulechów","Sulechów"],["Szadek","Szadek"],["Sól","Sól"],["Tarkowo","Tarkowo"],["Tartakowo","Tartakowo"],["Testowo","Testowo"],["Trawniczki","Trawniczki"],["Tłoki","Tłoki"],["Wełtawa","Wełtawa"],["Wielichowo","Wielichowo"],["Wijewo","Wijewo"],["Wilczyca","Wilczyca"],["Witaszyczki","Witaszyczki"],["Witonia","Witonia"],["Wodnica","Wodnica"],["Wola","Wola"],["Wola Nowska","Wola Nowska"],["Wschodna","Wschodna"],["Zgierz","Zgierz"],["Zgierz Kontrewers","Zgierz Kontr."],["Zwardoń","Zwardoń"],["Łask","Łask"],["Łaskarzew","Łaskarzew"],["Łebnino","Łebnino"],["Łęczyca","Łęczyca"],["Żerniki","Żerniki"],["Żory","Żory"]]
\ No newline at end of file
+{
+ "Aleksandrów Kujawski": "Aleksandrów Kuj."
+}
\ No newline at end of file
diff --git a/src/interfaces/StationData.ts b/src/interfaces/StationData.ts
index 81d4600..3b19e21 100644
--- a/src/interfaces/StationData.ts
+++ b/src/interfaces/StationData.ts
@@ -13,14 +13,14 @@
11: 0
12: 0
13: 0
- 14: "Węgierska Górka;Żywiec;Łodygowice;Wilkowice Bystra;BB Leszczyny;BB Lipnik, podg."
+ 14: "Żywiec;Węgierska Górka;Łodygowice;Wilkowice Bystra;BB Leszczyny;BB Lipnik, podg."
15: true
16: false
17: false
*/
export default interface StationData {
- stationName: string;
- nameAbbreviation: string;
- stationCheckpoints: string[];
+ stationName: string;
+ nameAbbreviation: string;
+ stationCheckpoints: string[];
}
\ No newline at end of file