mirror of
https://github.com/Spythere/pragotron-td2.git
synced 2026-05-03 05:28:14 +00:00
Poprawki w działaniu klapek
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
const mockStation: StationData = {
|
const mockStation: StationData = {
|
||||||
stationName: 'Czermin',
|
stationName: 'Lisków',
|
||||||
nameAbbreviation: '',
|
nameAbbreviation: '',
|
||||||
stationCheckpoints: [],
|
stationCheckpoints: [],
|
||||||
};
|
};
|
||||||
|
|||||||
+124
-112
@@ -2,7 +2,9 @@
|
|||||||
<div class="pragotron">
|
<div class="pragotron">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<div class="top-pane">
|
<div class="top-pane">
|
||||||
<span class="title">ODJAZDY</span>
|
<span class="title">
|
||||||
|
<div>{{ selectedStation.stationName.toUpperCase() }}</div>
|
||||||
|
</span>
|
||||||
|
|
||||||
<div class="headers">
|
<div class="headers">
|
||||||
<span>DO STACJI</span>
|
<span>DO STACJI</span>
|
||||||
@@ -18,15 +20,17 @@
|
|||||||
<div class="row-content">
|
<div class="row-content">
|
||||||
<span class="route-to">
|
<span class="route-to">
|
||||||
<transition name="slot-anim" mode="out-in">
|
<transition name="slot-anim" mode="out-in">
|
||||||
<div class="slider-slot" :key="departure.routeTo">
|
<div class="slider-slot" :key="departure.tableValues.routeTo">
|
||||||
{{ departure.routeTo.toUpperCase() }}
|
{{ abbrevStationName(departure.tableValues.routeTo) }}
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="route-via">
|
<span class="route-via">
|
||||||
<transition name="slot-anim" mode="out-in">
|
<transition name="slot-anim" mode="out-in">
|
||||||
<div class="slider-slot" :key="departure.routeVia">{{ departure.routeVia.toUpperCase() }}</div>
|
<div class="slider-slot" :key="departure.tableValues.routeVia">
|
||||||
|
{{ abbrevStationName(departure.tableValues.routeVia) }}
|
||||||
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -81,15 +85,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
import { defineComponent, inject, Ref } from 'vue';
|
import { defineComponent, inject, reactive, Ref } from 'vue';
|
||||||
|
|
||||||
import stationAbbrevs from '@/data/stationAbbrevs.json';
|
import stationAbbrevsJSON from '@/data/stationAbbrevs.json';
|
||||||
import routeValues from '@/data/routeValues.json';
|
import routeValues from '@/data/routeValues.json';
|
||||||
|
|
||||||
import { TrainResponse, TrainInfo } from '@/interfaces/TrainAPI';
|
import { TrainResponse, TrainInfo } from '@/interfaces/TrainAPI';
|
||||||
import { TimetableResponse, TimetableInfo, TimetableStopInfo } from '@/interfaces/TimetableAPI';
|
import { TimetableResponse, TimetableInfo, TimetableStopInfo } from '@/interfaces/TimetableAPI';
|
||||||
import StationData from '@/interfaces/StationData';
|
import StationData from '@/interfaces/StationData';
|
||||||
|
|
||||||
|
const stationAbbrevs: { [key: string]: string } = stationAbbrevsJSON;
|
||||||
|
|
||||||
interface DepartureInfo {
|
interface DepartureInfo {
|
||||||
timetableId: number;
|
timetableId: number;
|
||||||
|
|
||||||
@@ -103,17 +109,43 @@ interface DepartureInfo {
|
|||||||
|
|
||||||
delayMinutes: number;
|
delayMinutes: number;
|
||||||
|
|
||||||
currentRouteTo: string;
|
tableValues: {
|
||||||
currentRouteVia?: string;
|
routeTo: string;
|
||||||
|
routeVia: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const departureInfoEmptyObj: DepartureInfo = {
|
||||||
|
timetableId: -1,
|
||||||
|
|
||||||
|
routeTo: '',
|
||||||
|
routeVia: '',
|
||||||
|
|
||||||
|
trainNumber: '',
|
||||||
|
|
||||||
|
departureDate: new Date(0),
|
||||||
|
departureDigits: [],
|
||||||
|
|
||||||
|
delayMinutes: 0,
|
||||||
|
|
||||||
|
tableValues: reactive({
|
||||||
|
routeTo: '',
|
||||||
|
routeVia: '',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
data: () => ({
|
data: () => ({
|
||||||
currentStationName: '',
|
currentStationName: '',
|
||||||
|
|
||||||
seekingTable: [],
|
// seekingTable: [] as { collection: string[]; currentIndex: number }[][],
|
||||||
|
|
||||||
departureList: [] as DepartureInfo[],
|
lastRefreshTime: 0,
|
||||||
|
|
||||||
|
departureList: new Array(7).fill(0).map(() => ({ ...departureInfoEmptyObj })) as DepartureInfo[],
|
||||||
|
departureRoutes: [''],
|
||||||
|
|
||||||
|
currentRouteIndex: 0,
|
||||||
|
|
||||||
stationAbbrevs: stationAbbrevs as { [key: string]: string },
|
stationAbbrevs: stationAbbrevs as { [key: string]: string },
|
||||||
}),
|
}),
|
||||||
@@ -121,97 +153,76 @@ export default defineComponent({
|
|||||||
setup() {
|
setup() {
|
||||||
const selectedStation = inject('selectedStation') as Ref<StationData>;
|
const selectedStation = inject('selectedStation') as Ref<StationData>;
|
||||||
|
|
||||||
console.log(selectedStation.value.stationName);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedStation,
|
selectedStation,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addSeekedValue(desiredValue: string, sourceCollection: string[], startIndex: number = 0) {
|
abbrevStationName(name: string) {
|
||||||
let currentIndex = startIndex - 1;
|
return (name in stationAbbrevs ? stationAbbrevs[name] : name).toUpperCase();
|
||||||
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: '',
|
// d = 0 -> time = time
|
||||||
routeVia: '',
|
// d = time -> time2 = time2-time
|
||||||
|
updateTableRows(time: number) {
|
||||||
|
if (time >= this.lastRefreshTime + 125) {
|
||||||
|
this.departureList.forEach((dep, i) => {
|
||||||
|
if (dep.tableValues.routeTo.toLowerCase() != dep.routeTo.toLowerCase()) {
|
||||||
|
dep.tableValues.routeTo = this.departureRoutes[(this.currentRouteIndex + i) % this.departureRoutes.length];
|
||||||
|
}
|
||||||
|
|
||||||
trainNumber: '',
|
if (dep.tableValues.routeVia.toLowerCase() != dep.routeVia.toLowerCase()) {
|
||||||
|
dep.tableValues.routeVia = this.departureRoutes[(this.currentRouteIndex + i + 1) % this.departureRoutes.length];
|
||||||
departureDate: new Date(0),
|
}
|
||||||
departureDigits: [],
|
|
||||||
|
|
||||||
delayMinutes: 0,
|
|
||||||
currentRouteTo: '',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < this.departureList.length; i++) {
|
this.currentRouteIndex = (this.currentRouteIndex + 1) % this.departureRoutes.length;
|
||||||
if (i > responseArray.length - 1)
|
this.lastRefreshTime = time;
|
||||||
this.departureList[i] = {
|
|
||||||
timetableId: -1,
|
|
||||||
|
|
||||||
routeTo: '',
|
|
||||||
routeVia: '',
|
|
||||||
|
|
||||||
trainNumber: '',
|
|
||||||
|
|
||||||
departureDate: new Date(0),
|
|
||||||
departureDigits: [],
|
|
||||||
|
|
||||||
delayMinutes: 0,
|
|
||||||
currentRouteTo: '',
|
|
||||||
};
|
|
||||||
else this.departureList[i] = { ...responseArray[i] };
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
requestAnimationFrame(this.updateTableRows);
|
||||||
},
|
},
|
||||||
|
|
||||||
async mounted() {
|
fillTable(departureUpdateList: DepartureInfo[] = []) {
|
||||||
this.fillTable();
|
for (let i = 0; i < 7; i++) {
|
||||||
|
if (i <= departureUpdateList.length - 1) {
|
||||||
|
const updateInfo = departureUpdateList[i];
|
||||||
|
const existingInfo = this.departureList[i];
|
||||||
|
|
||||||
this.addSeekedValue('Test', routeValues, 0);
|
// if (updateInfo.delayMinutes != existingInfo.delayMinutes) {
|
||||||
|
// this.departureList[i].delayMinutes = updateInfo.delayMinutes;
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Podmień jeśli
|
||||||
|
// if (updateInfo.timetableId != existingInfo.timetableId) {
|
||||||
|
// this.departureList[i] = updateInfo;
|
||||||
|
// }
|
||||||
|
|
||||||
|
this.departureList[i] = updateInfo;
|
||||||
|
this.departureList[i].tableValues.routeTo = existingInfo.routeTo;
|
||||||
|
this.departureList[i].tableValues.routeVia = existingInfo.routeVia;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.departureList[i] = departureInfoEmptyObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(this.departureList);
|
||||||
|
},
|
||||||
|
shuffleRoutes() {
|
||||||
|
for (let i = 0; i < 25; i++) {
|
||||||
|
const randIndex = Math.floor(Math.random() * routeValues.length);
|
||||||
|
const randRoute = routeValues[randIndex];
|
||||||
|
|
||||||
|
this.departureRoutes.push(randRoute);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.departureRoutes.sort(() => Math.random() - 0.5);
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchDepartureList() {
|
||||||
const trainsAPIResponse: TrainResponse = await (
|
const trainsAPIResponse: TrainResponse = await (
|
||||||
await fetch('https://api.td2.info.pl:9640/?method=getTrainsOnline')
|
await fetch('https://api.td2.info.pl:9640/?method=getTrainsOnline')
|
||||||
).json();
|
).json();
|
||||||
@@ -262,49 +273,46 @@ export default defineComponent({
|
|||||||
const departureDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
|
const departureDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
|
||||||
|
|
||||||
const routeTo = route.split('|')[1];
|
const routeTo = route.split('|')[1];
|
||||||
const routeToAbbrev = this.stationAbbrevs[routeTo] || null;
|
|
||||||
|
|
||||||
(await acc).push({
|
(await acc).push({
|
||||||
timetableId,
|
timetableId,
|
||||||
routeTo: routeToAbbrev || routeTo,
|
routeTo: routeTo,
|
||||||
routeVia,
|
routeVia,
|
||||||
trainNumber: `${trainCategoryCode} ${trainNo}`,
|
trainNumber: `${trainCategoryCode} ${trainNo}`,
|
||||||
departureDate: new Date(departureTime),
|
departureDate: new Date(departureTime),
|
||||||
departureDigits,
|
departureDigits,
|
||||||
delayMinutes: departureDelay,
|
delayMinutes: departureDelay,
|
||||||
currentRouteTo: routeValues[0],
|
|
||||||
|
tableValues: reactive({
|
||||||
|
routeTo: '',
|
||||||
|
routeVia: '',
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!this.departureRoutes.includes(routeVia)) this.departureRoutes.push(routeVia);
|
||||||
|
if (!this.departureRoutes.includes(routeTo)) this.departureRoutes.push(routeTo);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, Promise.resolve([]))
|
}, Promise.resolve([]))
|
||||||
).sort((d1, d2) => (d1.departureDate > d2.departureDate ? 1 : -1));
|
).sort((d1, d2) => (d1.departureDate > d2.departureDate ? 1 : -1));
|
||||||
|
|
||||||
this.fillTable(departureList);
|
this.fillTable(departureList);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// const sortedList: DepartureInfo[] = new Array(8)
|
async mounted() {
|
||||||
// .fill({
|
this.fillTable();
|
||||||
// timetableId: -1,
|
this.fetchDepartureList();
|
||||||
|
this.shuffleRoutes();
|
||||||
|
|
||||||
// routeTo: '',
|
setInterval(() => {
|
||||||
// routeVia: '',
|
this.fetchDepartureList();
|
||||||
|
this.shuffleRoutes();
|
||||||
|
|
||||||
// trainNumber: '',
|
console.log('Loading data');
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
// departureDate: new Date(0),
|
requestAnimationFrame(this.updateTableRows);
|
||||||
// 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);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -315,7 +323,7 @@ export default defineComponent({
|
|||||||
.slot-anim {
|
.slot-anim {
|
||||||
&-enter-active,
|
&-enter-active,
|
||||||
&-leave-active {
|
&-leave-active {
|
||||||
transition: all 80ms ease-in;
|
transition: all 50ms ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-enter-from,
|
&-enter-from,
|
||||||
@@ -354,7 +362,11 @@ export default defineComponent({
|
|||||||
|
|
||||||
.top-pane {
|
.top-pane {
|
||||||
background: white;
|
background: white;
|
||||||
height: 130px;
|
height: 180px;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -419,7 +431,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
.slider-slot {
|
.slider-slot {
|
||||||
background: #010101;
|
background: #010101;
|
||||||
width: 80%;
|
width: 85%;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
line-height: 2em;
|
line-height: 2em;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user