Pragotron (v0.3)

This commit is contained in:
2022-10-12 21:47:12 +02:00
parent 046859b560
commit f06d13aee3
10 changed files with 501 additions and 323 deletions
+70 -41
View File
@@ -1,12 +1,27 @@
<template>
<div class="scenery-selector" v-if="!selectedStation">
<select name="scenery" id="select-scenery" v-model="selectedStation">
<option :value="null" disabled>Wybierz scenerię</option>
<option v-for="s in onlineStations" :value="s">{{ s.stationName }}</option>
</select>
</div>
<div class="app_content">
<nav class="navbar">
<div v-if="!selectedStation">Pragotron TD2</div>
<button v-else class="back-btn btn--text" @click="selectedStation = null">&lt; powrót</button>
</nav>
<PragotronVue v-else />
<main>
<div class="scenery-selector" v-if="!selectedStation">
<h1>Scenerie online</h1>
<ul class="scenery-list">
<li v-for="(station, i) in onlineStations">
<span v-if="i > 0">&bull;</span>
<button class="btn--text" @click="handleClick(station)">
{{ station.stationName }}
</button>
</li>
</ul>
</div>
<PragotronVue v-else />
</main>
</div>
</template>
<script lang="ts">
@@ -29,7 +44,7 @@ export default defineComponent({
stationCheckpoints: [],
};
const selectedStation = ref(mockStation) as Ref<null | IStationData>;
const selectedStation = ref(null) as Ref<null | IStationData>;
provide('selectedStation', selectedStation);
@@ -40,16 +55,17 @@ export default defineComponent({
data: () => ({
onlineStations: [] as IStationData[],
dataLoaded: false,
}),
async mounted() {
const stationDataArray: ISceneryResponse[] = await (
await fetch('https://spythere.github.io/api/stationData.json')
await fetch(`${import.meta.env.VITE_STACJOWNIK_API_URL}/api/getSceneries`)
).json();
const stationDataJSON = stationDataArray.map((stationData) => ({
stationName: stationData.name,
stationCheckpoints: stationData.checkpoints?.split(';') || [],
stationCheckpoints: stationData.checkpoints?.length > 0 ? stationData.checkpoints.split(';') : [stationData.name],
nameAbbreviation: '',
}));
@@ -75,51 +91,64 @@ export default defineComponent({
return acc;
}, [] as IStationData[])
.sort((s1, s2) => (s1.stationName > s2.stationName ? 1 : -1));
this.dataLoaded = true;
},
methods: {
handleClick(station: IStationData) {
this.selectedStation = station;
},
},
});
</script>
<style lang="scss">
@import url('https://fonts.googleapis.com/css2?family=Monda:wght@400;700&display=swap');
@import './styles.scss';
body,
html {
background: #333;
min-height: 100vh;
padding: 0;
margin: 0;
font-family: 'Monda', sans-serif;
}
input,
button,
select,
option {
font-family: 'Monda', sans-serif;
font-size: 1em;
}
#app {
.app_content {
text-align: center;
display: flex;
flex-direction: column;
min-height: 100vh;
}
nav {
flex: 0 1 auto;
font-size: 1.35em;
padding: 0.25em;
display: flex;
align-items: center;
background-color: $accentBg;
button {
padding: 0;
}
}
main {
flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.scenery-selector {
ul.scenery-list {
display: flex;
justify-content: center;
flex-wrap: wrap;
padding: 1em;
margin: 0 auto;
font-size: 1.3em;
color: white;
select {
margin-top: 1em;
width: 14em;
}
max-width: 1000px;
}
</style>
+291 -168
View File
@@ -1,28 +1,78 @@
<template>
<div class="pragotron">
<div class="filters">
<div>
<label>
<input type="checkbox" v-model="includeNonPassenger" />
Relacje niepasażerskie
</label>
<label>
<input type="checkbox" v-model="includeArrivals" />
Relacje kończące bieg
</label>
</div>
<div>
<label for="checkpoint">
Posterunek:
<select id="checkpoint" v-model="selectedCheckpointName">
<option v-for="cp in selectedStation.stationCheckpoints" :value="cp">{{ cp }}</option>
</select>
</label>
</div>
</div>
<div class="wrapper">
<div class="top-pane">
<span class="title">
<div>{{ selectedStation.stationName.toUpperCase() }}</div>
<div>{{ selectedCheckpointName.toUpperCase() }}</div>
</span>
<div class="headers">
<span>DO STACJI</span>
<span>PRZEZ</span>
<span>GODZ.</span>
<span>POCIĄG</span>
<span>PLAN. ODJ.</span>
<span>OPÓŹN.</span>
<span>PRZEZ</span>
<span>DO STACJI</span>
<span>OPÓŹNIONY</span>
</div>
</div>
<div class="table">
<div class="row" v-for="(departure, i) in departureList" :key="i">
<div class="row" v-for="(departure, i) in filledTable" :key="i">
<div class="row-content">
<span class="route-to">
<span class="departure-date">
<transition name="slot-anim" mode="out-in">
<div class="slider-slot" :key="departure.tableValues.routeTo">
{{ abbrevStationName(departure.tableValues.routeTo) }}
</div>
<span class="slider-slot-digit" :key="departure.tableValues.dateDigits[0]">{{
departure.tableValues.dateDigits[0]
}}</span>
</transition>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.tableValues.dateDigits[1]">
{{ departure.tableValues.dateDigits[1] }}</span
>
</transition>
<span :key="departure.tableValues.dateDigits[1]"> : </span>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.tableValues.dateDigits[2]">
{{ departure.tableValues.dateDigits[2] }}
</span>
</transition>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.tableValues.dateDigits[3]">
{{ departure.tableValues.dateDigits[3] }}
</span>
</transition>
</span>
<span class="train-class">
<transition name="slot-anim" mode="out-in">
<div class="slider-slot" :key="departure.trainNumber">{{ departure.trainNumber }}</div>
</transition>
</span>
@@ -34,37 +84,11 @@
</transition>
</span>
<span class="train-class">
<span class="route-to">
<transition name="slot-anim" mode="out-in">
<div class="slider-slot" :key="departure.trainNumber">{{ departure.trainNumber }}</div>
</transition>
</span>
<span class="departure-date">
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.departureDigits[0]">{{
departure.departureDigits[0]
}}</span>
</transition>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.departureDigits[1]">
{{ departure.departureDigits[1] }}</span
>
</transition>
<span :key="departure.departureDigits[1]"> : </span>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.departureDigits[2]">
{{ departure.departureDigits[2] }}
</span>
</transition>
<transition name="slot-anim" mode="out-in">
<span class="slider-slot-digit" :key="departure.departureDigits[3]">
{{ departure.departureDigits[3] }}
</span>
<div class="slider-slot" :key="departure.tableValues.routeTo">
{{ abbrevStationName(departure.tableValues.routeTo) }}
</div>
</transition>
</span>
@@ -90,13 +114,13 @@ import { defineComponent, inject, reactive, Ref } from 'vue';
import stationAbbrevsJSON from '../data/stationAbbrevs.json';
import routeValues from '../data/routeValues.json';
import { IDeparture } from '../types/IDeparture';
import StationData from '../types/IStationData';
import { ITimetableStop, ITrainResponse } from '../types/ITrainResponse';
import { ITableRow } from '../types/ITableRow';
const stationAbbrevs: { [key: string]: string } = stationAbbrevsJSON;
const departureInfoEmptyObj: IDeparture = {
const departureInfoEmptyObj: ITableRow = {
timetableId: -1,
routeTo: '',
@@ -104,34 +128,47 @@ const departureInfoEmptyObj: IDeparture = {
trainNumber: '',
departureDate: new Date(0),
departureDigits: [],
date: new Date(0),
dateDigits: [' ', ' ', ' ', ' '],
arrivalTimestamp: 0,
departureTimestamp: 0,
checkpointName: '',
delayMinutes: 0,
tableValues: reactive({
tableValues: {
routeTo: '',
routeVia: '',
}),
currentRouteToIndex: 0,
currentRouteViaIndex: 0,
dateDigits: [' ', ' ', ' ', ' '],
},
};
export default defineComponent({
data: () => ({
currentStationName: '',
// seekingTable: [] as { collection: string[]; currentIndex: number }[][],
includeNonPassenger: true,
includeArrivals: true,
apiTrainData: [] as ITrainResponse[],
lastRefreshTime: 0,
updatedDepartureList: [] as ITableRow[],
departureList: new Array(7).fill(0).map(() => ({ ...departureInfoEmptyObj })) as IDeparture[],
departureList: new Array(7).fill(0).map(() => ({ ...departureInfoEmptyObj })) as ITableRow[],
departureRoutes: [''],
dateDigits: [' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
currentRouteIndex: 0,
currentDateDigitIndex: 0,
stationAbbrevs: stationAbbrevs as { [key: string]: string },
selectedCheckpointName: '',
}),
setup() {
@@ -142,7 +179,114 @@ export default defineComponent({
};
},
async mounted() {
this.selectDefaultCheckpoint();
this.shuffleRoutes();
await this.fetchDepartureList();
setInterval(() => {
this.fetchDepartureList();
}, 10000);
requestAnimationFrame(this.update);
},
computed: {
filledTable() {
const filteredData = this.apiTrainData
.reduce((list, train) => {
if (!train.timetable) return list;
const timetable = train.timetable;
const stopInfo: ITimetableStop | undefined = timetable.stopList.find(
(sp) => sp.stopNameRAW.toLowerCase() == this.selectedCheckpointName.toLowerCase()
);
if (!stopInfo || stopInfo.confirmed) return list;
const stopInfoIndex = timetable.stopList.indexOf(stopInfo);
const { departureTimestamp, departureDelay, arrivalTimestamp, departureLine } = stopInfo;
const routeVia =
timetable.stopList.find((stop, i) => {
return (
i > stopInfoIndex &&
// i < timetable.stopList.length - 1,
stop.stopName.includes('strong') &&
stop.stopTime &&
stop.stopTime > 0
);
})?.stopNameRAW || '';
const date = departureLine ? new Date(departureTimestamp) : new Date(arrivalTimestamp);
// [HH, MM, SS] - nienawidzę dat w JavaScripcie
const dateArray = date.toLocaleString('pl-PL').split(', ')[1].split(':') || ['', '', '', ''];
// [H,H,M,M] - ZABIJCIE MNIE BŁAGAM
const dateDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
const routeTo = timetable.route.split('|')[1];
list.push({
trainNumber: `${timetable.category} ${train.trainNo}`,
timetableId: timetable.timetableId,
routeTo: routeTo,
routeVia: routeVia,
date,
dateDigits,
delayMinutes: departureDelay,
checkpointName: this.selectedCheckpointName.toLowerCase(),
arrivalTimestamp,
departureTimestamp,
tableValues: {
routeTo: '',
routeVia: '',
dateDigits: [' ', ' ', ' ', ' '],
currentRouteToIndex: 0,
currentRouteViaIndex: 0
},
});
if (!this.departureRoutes.includes(routeVia)) this.departureRoutes.push(routeVia);
if (!this.departureRoutes.includes(routeTo)) this.departureRoutes.push(routeTo);
return list;
}, [] as ITableRow[])
.filter(
(dep) =>
(this.includeNonPassenger || !/^[T|L|Z|P]/g.test(dep.trainNumber)) &&
(this.includeArrivals || dep.departureTimestamp)
)
.sort((dep1, dep2) => (dep1.date?.getTime() || 0) - (dep2.date?.getTime() || 0));
for (let i = 0; i < this.departureList.length; i++) {
if (i <= filteredData.length - 1) {
const updateInfo = filteredData[i];
const existingInfo = this.departureList[i];
this.departureList[i] = { ...updateInfo };
this.departureList[i].tableValues.routeTo = existingInfo.routeTo;
this.departureList[i].tableValues.routeVia = existingInfo.routeVia;
this.departureList[i].tableValues.dateDigits = [...existingInfo.tableValues.dateDigits];
} else {
this.departureList[i] = departureInfoEmptyObj;
}
}
return this.departureList;
},
},
methods: {
selectDefaultCheckpoint() {
this.selectedCheckpointName = this.selectedStation.stationCheckpoints[0] || this.selectedStation.stationName;
},
abbrevStationName(name: string) {
return (name in stationAbbrevs ? stationAbbrevs[name] : name).toUpperCase();
},
@@ -152,64 +296,114 @@ export default defineComponent({
this.updateTableRows();
this.currentRouteIndex = (this.currentRouteIndex + 1) % this.departureRoutes.length;
// this.currentDateDigitIndex = (this.currentDateDigitIndex + 1) % this.dateDigits.length;
this.lastRefreshTime = time;
}
requestAnimationFrame(this.update);
},
// d = 0 -> time = time
// d = time -> time2 = time2-time
updateTableRows() {
this.departureList.forEach((dep, i) => {
if (dep.tableValues.routeTo.toLowerCase() != dep.routeTo.toLowerCase()) {
dep.tableValues.routeTo = this.departureRoutes[(this.currentRouteIndex + i) % this.departureRoutes.length];
dep.tableValues.routeTo = this.departureRoutes[(dep.tableValues.currentRouteToIndex) % this.departureRoutes.length];
}
if (dep.tableValues.routeVia.toLowerCase() != dep.routeVia.toLowerCase()) {
dep.tableValues.routeVia =
this.departureRoutes[(this.currentRouteIndex + i + 1) % this.departureRoutes.length];
this.departureRoutes[(dep.tableValues.currentRouteViaIndex) % this.departureRoutes.length];
}
dep.tableValues.currentRouteToIndex = (dep.tableValues.currentRouteToIndex + 1) % this.departureRoutes.length;
dep.tableValues.currentRouteViaIndex = (dep.tableValues.currentRouteViaIndex + 1) % this.departureRoutes.length;
dep.tableValues.dateDigits.forEach((digit, j) => {
if (dep.dateDigits[j] != digit)
dep.tableValues.dateDigits[j] =
this.dateDigits[(Number(digit) + 1) % this.dateDigits.length];
});
});
},
fillTable(departureUpdateList: IDeparture[] = []) {
for (let i = 0; i < this.departureList.length; i++) {
if (i <= departureUpdateList.length - 1) {
const updateInfo = departureUpdateList[i];
const existingInfo = this.departureList[i];
// if (updateInfo.delayMinutes != existingInfo.delayMinutes) {
// this.sortedDepartureList[i].delayMinutes = updateInfo.delayMinutes;
// continue;
// }
// // Podmień jeśli
// if (updateInfo.timetableId != existingInfo.timetableId) {
// this.sortedDepartureList[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(departureUpdateList);
},
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.push(randRoute);
}
this.departureRoutes.sort(() => Math.random() - 0.5);
},
// refreshTable(apiData: ITrainResponse[]) {
// const updatedDepartureList = apiData.reduce((list, train) => {
// if (!train.timetable) return list;
// const timetable = train.timetable;
// const stopInfo: ITimetableStop | undefined = timetable.stopList.find(
// (sp) => sp.stopNameRAW.toLowerCase() == this.selectedCheckpointName.toLowerCase()
// );
// if (!stopInfo || stopInfo.confirmed) return list;
// const stopInfoIndex = timetable.stopList.indexOf(stopInfo);
// const { departureTimestamp, departureDelay, arrivalTimestamp, departureLine } = stopInfo;
// const routeVia =
// timetable.stopList.find((stop, i) => {
// return (
// i > stopInfoIndex &&
// // i < timetable.stopList.length - 1,
// stop.stopName.includes('strong') &&
// stop.stopTime &&
// stop.stopTime > 0
// );
// })?.stopNameRAW || '';
// const date = departureLine ? new Date(departureTimestamp) : new Date(arrivalTimestamp);
// // [HH, MM, SS] - nienawidzę dat w JavaScripcie
// const dateArray = date.toLocaleString('pl-PL').split(', ')[1].split(':') || [' ', ' ', ' ', ' '];
// // [H,H,M,M] - ZABIJCIE MNIE BŁAGAM
// const dateDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
// const routeTo = timetable.route.split('|')[1];
// list.push({
// trainNumber: `${timetable.category} ${train.trainNo}`,
// timetableId: timetable.timetableId,
// routeTo: routeTo,
// routeVia: routeVia,
// date,
// dateDigits,
// delayMinutes: departureDelay,
// checkpointName: this.selectedCheckpointName.toLowerCase(),
// arrivalTimestamp,
// departureTimestamp,
// tableValues: {
// routeTo: '',
// routeVia: '',
// },
// });
// if (!this.departureRoutes.includes(routeVia)) this.departureRoutes.push(routeVia);
// if (!this.departureRoutes.includes(routeTo)) this.departureRoutes.push(routeTo);
// return list;
// }, [] as ITableRow[]);
// this.updatedDepartureList = updatedDepartureList;
// },
async fetchDepartureList() {
const trainsAPIResponse: ITrainResponse[] = await (
await fetch(`${import.meta.env.VITE_STACJOWNIK_API_URL}/api/getActiveTrainList`)
@@ -217,83 +411,10 @@ export default defineComponent({
if (!trainsAPIResponse) return;
const updatedDepartureList = trainsAPIResponse.reduce((list, train) => {
if (!train.timetable) return list;
const timetable = train.timetable;
const stopInfo: ITimetableStop | undefined = timetable.stopList.find(
(sp) => sp.stopNameRAW.toLowerCase() == this.selectedStation.stationName.toLowerCase()
);
if (!stopInfo || stopInfo.confirmed) return list;
const stopInfoIndex = timetable.stopList.indexOf(stopInfo);
const { departureTimestamp, departureDelay, arrivalTimestamp, departureLine } = stopInfo;
const routeVia =
timetable.stopList.find((stop, i) => {
return (
i > stopInfoIndex &&
// i < timetable.stopList.length - 1,
stop.stopName.includes('strong') &&
stop.stopTime &&
stop.stopTime > 0
);
})?.stopNameRAW || '';
const departureDate = departureLine ? new Date(departureTimestamp) : undefined;
// [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 = timetable.route.split('|')[1];
list.push({
trainNumber: `${timetable.category} ${train.trainNo}`,
timetableId: timetable.timetableId,
routeTo: routeTo,
routeVia: routeVia,
departureDate: departureDate,
departureDigits: departureDigits,
delayMinutes: departureDelay,
arrivalTimestamp,
departureTimestamp,
tableValues: reactive({
routeTo: '',
routeVia: '',
}),
});
if (!this.departureRoutes.includes(routeVia)) this.departureRoutes.push(routeVia);
if (!this.departureRoutes.includes(routeTo)) this.departureRoutes.push(routeTo);
return list;
}, [] as IDeparture[]);
this.fillTable(
updatedDepartureList
// .filter((dep) => dep.departureDate)
.sort((dep1, dep2) => (dep1.departureDate?.getTime() || 0) - (dep2.departureDate?.getTime() || 0))
);
this.apiTrainData = trainsAPIResponse;
// this.refreshTable(trainsAPIResponse);
},
},
async mounted() {
this.shuffleRoutes();
await this.fetchDepartureList();
setInterval(() => {
this.fetchDepartureList();
}, 10000);
requestAnimationFrame(this.update);
},
});
</script>
@@ -326,22 +447,24 @@ export default defineComponent({
/* ************** */
.pragotron {
width: 1200px;
height: 650px;
background: black;
.filters {
display: flex;
justify-content: space-between;
padding: 0.25em 0;
gap: 0.5em;
}
.wrapper {
height: 100%;
width: 1200px;
height: 650px;
display: flex;
flex-direction: column;
}
.top-pane {
background: white;
background-color: white;
color: black;
height: 180px;
display: flex;
@@ -356,8 +479,9 @@ export default defineComponent({
.headers {
display: grid;
grid-template-columns: 2fr 2fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 2fr 2fr 1fr;
gap: 0 10px;
padding: 0 10px;
text-align: center;
@@ -377,7 +501,10 @@ export default defineComponent({
.row {
&-content {
display: grid;
grid-template-columns: 2fr 2fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 2fr 2fr 1fr;
gap: 0 10px;
padding: 0 10px;
height: 100%;
align-items: center;
@@ -394,24 +521,20 @@ export default defineComponent({
}
.departure-date {
display: flex;
background: black;
.dot {
flex-grow: 1;
}
span {
background: black;
height: 2em;
line-height: 2em;
flex-grow: 2;
width: 100%;
}
}
.slider-slot {
background: #010101;
width: 85%;
width: 100%;
height: 2em;
line-height: 2em;
}
-1
View File
@@ -1,3 +1,2 @@
{
"Aleksandrów Kujawski": "Aleksandrów Kuj."
}
+40
View File
@@ -0,0 +1,40 @@
@import url('https://fonts.googleapis.com/css2?family=Monda:wght@400;700&display=swap');
@import 'theme.scss';
body,
html {
background: $primaryBg;
min-height: 100vh;
color: $primaryText;
padding: 0;
margin: 0;
}
*,
*::before,
*::after {
font-family: 'Monda', sans-serif;
}
ul {
list-style: none;
}
button {
cursor: pointer;
color: white;
font-size: 1em;
&.btn--text {
background: none;
border: none;
outline: none;
}
&:focus-visible {
color: $accentText;
}
}
+7
View File
@@ -0,0 +1,7 @@
$primaryText: white;
$accentText: gold;
$primaryBg: #333;
$secondaryBg: #aaa;
$accentBg: #327ea5;
-21
View File
@@ -1,21 +0,0 @@
interface IDepartureTableValues {
routeTo: string;
routeVia: string;
}
export interface IDeparture {
trainNumber: string;
timetableId: number;
routeTo: string;
routeVia: string;
arrivalTimestamp: number;
departureTimestamp: number;
delayMinutes: number,
departureDate?: Date,
departureDigits: string[],
tableValues: IDepartureTableValues;
}
-21
View File
@@ -1,24 +1,3 @@
/*
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: "Żywiec;Węgierska Górka;Łodygowice;Wilkowice Bystra;BB Leszczyny;BB Lipnik, podg."
15: true
16: false
17: false
*/
export default interface IStationData {
stationName: string;
nameAbbreviation: string;
+28
View File
@@ -0,0 +1,28 @@
interface ITableRowValues {
routeTo: string;
routeVia: string;
currentRouteToIndex: number;
currentRouteViaIndex: number;
dateDigits: string[],
}
export interface ITableRow {
trainNumber: string;
timetableId: number;
routeTo: string;
routeVia: string;
checkpointName: string;
arrivalTimestamp: number;
departureTimestamp: number;
delayMinutes: number,
date?: Date,
dateDigits: string[],
tableValues: ITableRowValues;
}