mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
Bump wersji
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "stacjownik",
|
"name": "stacjownik",
|
||||||
"version": "1.10.0",
|
"version": "1.10.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,287 +1,287 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="train-info" tabindex="0">
|
<div class="train-info" tabindex="0">
|
||||||
<section class="train-route">
|
<section class="train-route">
|
||||||
<div class="train_general">
|
<div class="train_general">
|
||||||
<span>
|
<span>
|
||||||
<span class="timetable-id" v-if="train.timetableData">#{{ train.timetableData.timetableId }}</span>
|
<span class="timetable-id" v-if="train.timetableData">#{{ train.timetableData.timetableId }}</span>
|
||||||
|
|
||||||
<span class="timetable_warnings">
|
<span class="timetable_warnings">
|
||||||
<span class="train-badge twr" v-if="train.timetableData?.TWR">TWR</span>
|
<span class="train-badge twr" v-if="train.timetableData?.TWR">TWR</span>
|
||||||
<span class="train-badge skr" v-if="train.timetableData?.SKR">SKR</span>
|
<span class="train-badge skr" v-if="train.timetableData?.SKR">SKR</span>
|
||||||
</span>
|
</span>
|
||||||
<strong v-if="train.timetableData">{{ train.timetableData.category }} </strong>
|
<strong v-if="train.timetableData">{{ train.timetableData.category }} </strong>
|
||||||
<strong>{{ train.trainNo }}</strong>
|
<strong>{{ train.trainNo }}</strong>
|
||||||
<span> | {{ train.driverName }} </span>
|
<span> | {{ train.driverName }} </span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="timetable_route" v-if="train.timetableData">
|
<div class="timetable_route" v-if="train.timetableData">
|
||||||
<strong>{{ train.timetableData.route.replace('|', ' - ') }}</strong>
|
<strong>{{ train.timetableData.route.replace('|', ' - ') }}</strong>
|
||||||
<img
|
<img
|
||||||
v-if="getSceneriesWithComments(train.timetableData).length > 0"
|
v-if="getSceneriesWithComments(train.timetableData).length > 0"
|
||||||
class="image-warning"
|
class="image-warning"
|
||||||
:src="getIcon('warning')"
|
:src="getIcon('warning')"
|
||||||
:title="`${$t('trains.timetable-comments')} (${getSceneriesWithComments(train.timetableData)})`"
|
:title="`${$t('trains.timetable-comments')} (${getSceneriesWithComments(train.timetableData)})`"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr style="margin: 0.25em 0" />
|
<hr style="margin: 0.25em 0" />
|
||||||
|
|
||||||
<div class="timetable_stops" v-if="train.timetableData">
|
<div class="timetable_stops" v-if="train.timetableData">
|
||||||
<span v-if="train.timetableData.followingStops.length > 2">
|
<span v-if="train.timetableData.followingStops.length > 2">
|
||||||
{{ $t('trains.via-title') }}
|
{{ $t('trains.via-title') }}
|
||||||
<span v-html="displayStopList(train.timetableData.followingStops)"></span>
|
<span v-html="displayStopList(train.timetableData.followingStops)"></span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="timetable_progress" style="margin-top: 0.5em" v-if="train.timetableData">
|
<div class="timetable_progress" style="margin-top: 0.5em" v-if="train.timetableData">
|
||||||
<!-- <span> </span> -->
|
<!-- <span> </span> -->
|
||||||
<span class="timetable_progress-bar">
|
<span class="timetable_progress-bar">
|
||||||
<!-- {{ confirmedPercentage(train.timetableData.followingStops) }}% -->
|
<!-- {{ confirmedPercentage(train.timetableData.followingStops) }}% -->
|
||||||
<span class="bar-bg"></span>
|
<span class="bar-bg"></span>
|
||||||
<span
|
<span
|
||||||
class="bar-fg"
|
class="bar-fg"
|
||||||
:style="{ width: `${Math.floor(confirmedPercentage(train.timetableData.followingStops))}%` }"
|
:style="{ width: `${Math.floor(confirmedPercentage(train.timetableData.followingStops))}%` }"
|
||||||
></span>
|
></span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="timetable_progress-distance">
|
<span class="timetable_progress-distance">
|
||||||
{{ currentDistance(train.timetableData.followingStops) }} km /
|
{{ currentDistance(train.timetableData.followingStops) }} km /
|
||||||
<span class="text--primary"> {{ train.timetableData.routeDistance }} km </span>
|
<span class="text--primary"> {{ train.timetableData.routeDistance }} km </span>
|
||||||
|
|
|
|
||||||
<span v-html="currentDelay(train.timetableData.followingStops)"></span>
|
<span v-html="currentDelay(train.timetableData.followingStops)"></span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div class="train-status-badges">
|
<div class="train-status-badges">
|
||||||
<div v-if="!train.currentStationHash" class="train-badge offline">{{ $t('trains.scenery-offline') }}</div>
|
<div v-if="!train.currentStationHash" class="train-badge offline">{{ $t('trains.scenery-offline') }}</div>
|
||||||
<div v-if="!train.online" class="train-badge offline">Offline {{ lastSeenMessage(train.lastSeen) }}</div>
|
<div v-if="!train.online" class="train-badge offline">Offline {{ lastSeenMessage(train.lastSeen) }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="driver_position text--grayed" style="margin-top: 0.25em">
|
<div class="driver_position text--grayed" style="margin-top: 0.25em">
|
||||||
{{ displayTrainPosition(train) }}
|
{{ displayTrainPosition(train) }}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="train-stats">
|
<section class="train-stats">
|
||||||
<div>
|
<div>
|
||||||
<img :src="train.locoURL" loading="lazy" alt="Loco image not found" @error="onImageError" />
|
<img :src="train.locoURL" loading="lazy" alt="Loco image not found" @error="onImageError" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text--grayed">
|
<div class="text--grayed">
|
||||||
{{ train.locoType }}
|
{{ train.locoType }}
|
||||||
<span v-if="train.cars.length > 0">
|
<span v-if="train.cars.length > 0">
|
||||||
• {{ $t('trains.cars') }}:
|
• {{ $t('trains.cars') }}:
|
||||||
<span class="count">{{ train.cars.length }}</span>
|
<span class="count">{{ train.cars.length }}</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span v-for="(stat, i) in STATS.main" :key="stat.name">
|
<span v-for="(stat, i) in STATS.main" :key="stat.name">
|
||||||
<span v-if="i > 0"> • </span>
|
<span v-if="i > 0"> • </span>
|
||||||
<span>{{ `${~~((train as any)[stat.name] * (stat.multiplier || 1))}${stat.unit}` }} </span>
|
<span>{{ `${~~((train as any)[stat.name] * (stat.multiplier || 1))}${stat.unit}` }} </span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import imageMixin from '../../mixins/imageMixin';
|
import imageMixin from '../../mixins/imageMixin';
|
||||||
import trainInfoMixin from '../../mixins/trainInfoMixin';
|
import trainInfoMixin from '../../mixins/trainInfoMixin';
|
||||||
import Train from '../../scripts/interfaces/Train';
|
import Train from '../../scripts/interfaces/Train';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
train: {
|
train: {
|
||||||
type: Object as () => Train,
|
type: Object as () => Train,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
extended: {
|
extended: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [trainInfoMixin, imageMixin],
|
mixins: [trainInfoMixin, imageMixin],
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import '../../styles/responsive.scss';
|
@import '../../styles/responsive.scss';
|
||||||
|
|
||||||
.image-warning {
|
.image-warning {
|
||||||
height: 1em;
|
height: 1em;
|
||||||
|
|
||||||
margin-left: 0.5em;
|
margin-left: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.train-stats {
|
.train-stats {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
margin: 0.5em 0;
|
margin: 0.5em 0;
|
||||||
width: 12em;
|
width: 12em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.train-info {
|
.train-info {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2fr 1fr;
|
grid-template-columns: 2fr 1fr;
|
||||||
grid-template-rows: 1fr;
|
grid-template-rows: 1fr;
|
||||||
|
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
|
||||||
background-color: #1a1a1a;
|
background-color: #1a1a1a;
|
||||||
gap: 0.5em;
|
gap: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable-id {
|
.timetable-id {
|
||||||
margin-right: 0.3em;
|
margin-right: 0.3em;
|
||||||
color: #d2d2d2;
|
color: #d2d2d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_stops {
|
.timetable_stops {
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.train_general {
|
.train_general {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
.train-status-badges {
|
.train-status-badges {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.train-badge {
|
.train-badge {
|
||||||
padding: 0.15em 0.35em;
|
padding: 0.15em 0.35em;
|
||||||
margin-right: 0.3em;
|
margin-right: 0.3em;
|
||||||
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
|
|
||||||
&.twr {
|
&.twr {
|
||||||
background-color: var(--clr-twr);
|
background-color: var(--clr-twr);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.skr {
|
&.skr {
|
||||||
background-color: var(--clr-skr);
|
background-color: var(--clr-skr);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.offline {
|
&.offline {
|
||||||
background-color: #b83b2d;
|
background-color: #b83b2d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_route {
|
.timetable_route {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_warnings {
|
.timetable_warnings {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_progress {
|
.timetable_progress {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_progress-bar {
|
.timetable_progress-bar {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
width: 6em;
|
width: 6em;
|
||||||
height: 1em;
|
height: 1em;
|
||||||
margin: 0.5em 0;
|
margin: 0.5em 0;
|
||||||
|
|
||||||
.bar-fg,
|
.bar-fg,
|
||||||
.bar-bg {
|
.bar-bg {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
height: 1em;
|
height: 1em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-fg {
|
.bar-fg {
|
||||||
background-color: springgreen;
|
background-color: springgreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-bg {
|
.bar-bg {
|
||||||
background-color: #5b5b5b;
|
background-color: #5b5b5b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_progress-distance {
|
.timetable_progress-distance {
|
||||||
margin-right: 0.25em;
|
margin-right: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comments {
|
.comments {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
|
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@include smallScreen() {
|
@include smallScreen() {
|
||||||
.train-info {
|
.train-info {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
gap: 1em 0;
|
gap: 1em 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
font-size: 1.15em;
|
font-size: 1.15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.train-stats {
|
.train-stats {
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.train_general {
|
.train_general {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.train-status-badges {
|
.train-status-badges {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_route {
|
.timetable_route {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timetable_progress {
|
.timetable_progress {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comments {
|
.comments {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
margin: 0 0 0.5em 0;
|
margin: 0 0 0.5em 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+398
-398
@@ -1,398 +1,398 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
import { DataStatus } from '../scripts/enums/DataStatus';
|
import { DataStatus } from '../scripts/enums/DataStatus';
|
||||||
import StationAPIData from '../scripts/interfaces/api/StationAPIData';
|
import StationAPIData from '../scripts/interfaces/api/StationAPIData';
|
||||||
import ScheduledTrain from '../scripts/interfaces/ScheduledTrain';
|
import ScheduledTrain from '../scripts/interfaces/ScheduledTrain';
|
||||||
import Station from '../scripts/interfaces/Station';
|
import Station from '../scripts/interfaces/Station';
|
||||||
import StationRoutes from '../scripts/interfaces/StationRoutes';
|
import StationRoutes from '../scripts/interfaces/StationRoutes';
|
||||||
import Train from '../scripts/interfaces/Train';
|
import Train from '../scripts/interfaces/Train';
|
||||||
import { URLs } from '../scripts/utils/apiURLs';
|
import { URLs } from '../scripts/utils/apiURLs';
|
||||||
import {
|
import {
|
||||||
getLocoURL,
|
getLocoURL,
|
||||||
getStatusTimestamp,
|
getStatusTimestamp,
|
||||||
getStatusID,
|
getStatusID,
|
||||||
getScheduledTrain,
|
getScheduledTrain,
|
||||||
parseSpawns,
|
parseSpawns,
|
||||||
} from '../scripts/utils/storeUtils';
|
} from '../scripts/utils/storeUtils';
|
||||||
import { APIData, StationJSONData, StoreState } from './storeTypes';
|
import { APIData, StationJSONData, StoreState } from './storeTypes';
|
||||||
|
|
||||||
export const useStore = defineStore('store', {
|
export const useStore = defineStore('store', {
|
||||||
state: () =>
|
state: () =>
|
||||||
({
|
({
|
||||||
apiData: {} as unknown,
|
apiData: {} as unknown,
|
||||||
|
|
||||||
stationList: [],
|
stationList: [],
|
||||||
trainList: [],
|
trainList: [],
|
||||||
|
|
||||||
sceneryData: [],
|
sceneryData: [],
|
||||||
lastDispatcherStatuses: [],
|
lastDispatcherStatuses: [],
|
||||||
|
|
||||||
region: { id: 'eu', value: 'PL1' },
|
region: { id: 'eu', value: 'PL1' },
|
||||||
|
|
||||||
trainCount: 0,
|
trainCount: 0,
|
||||||
stationCount: 0,
|
stationCount: 0,
|
||||||
|
|
||||||
webSocket: undefined,
|
webSocket: undefined,
|
||||||
|
|
||||||
dispatcherStatsName: '',
|
dispatcherStatsName: '',
|
||||||
dispatcherStatsData: undefined,
|
dispatcherStatsData: undefined,
|
||||||
|
|
||||||
driverStatsName: '',
|
driverStatsName: '',
|
||||||
driverStatsData: undefined,
|
driverStatsData: undefined,
|
||||||
|
|
||||||
chosenModalTrainId: undefined,
|
chosenModalTrainId: undefined,
|
||||||
|
|
||||||
dataStatuses: {
|
dataStatuses: {
|
||||||
connection: DataStatus.Loading,
|
connection: DataStatus.Loading,
|
||||||
sceneries: DataStatus.Loading,
|
sceneries: DataStatus.Loading,
|
||||||
timetables: DataStatus.Loading,
|
timetables: DataStatus.Loading,
|
||||||
dispatchers: DataStatus.Loading,
|
dispatchers: DataStatus.Loading,
|
||||||
trains: DataStatus.Loading,
|
trains: DataStatus.Loading,
|
||||||
},
|
},
|
||||||
|
|
||||||
listenerLaunched: false,
|
listenerLaunched: false,
|
||||||
} as StoreState),
|
} as StoreState),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
setTrainsOnlineData() {
|
setTrainsOnlineData() {
|
||||||
const { trains } = this.apiData;
|
const { trains } = this.apiData;
|
||||||
|
|
||||||
if (!trains) return [];
|
if (!trains) return [];
|
||||||
|
|
||||||
this.trainList = trains
|
this.trainList = trains
|
||||||
.filter(
|
.filter(
|
||||||
(train) =>
|
(train) =>
|
||||||
train.region === this.region.id && (train.online || train.timetable || train.lastSeen > Date.now() - 180000)
|
train.region === this.region.id && (train.online || train.timetable || train.lastSeen > Date.now() - 180000)
|
||||||
)
|
)
|
||||||
.map((train) => {
|
.map((train) => {
|
||||||
const stock = train.stockString.split(';');
|
const stock = train.stockString.split(';');
|
||||||
const locoType = stock ? stock[0] : train.stockString;
|
const locoType = stock ? stock[0] : train.stockString;
|
||||||
|
|
||||||
const timetable = train.timetable;
|
const timetable = train.timetable;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trainId: train.driverName + train.trainNo.toString(),
|
trainId: train.driverName + train.trainNo.toString(),
|
||||||
|
|
||||||
trainNo: train.trainNo,
|
trainNo: train.trainNo,
|
||||||
mass: train.mass,
|
mass: train.mass,
|
||||||
length: train.length,
|
length: train.length,
|
||||||
speed: train.speed,
|
speed: train.speed,
|
||||||
region: train.region,
|
region: train.region,
|
||||||
|
|
||||||
distance: train.distance,
|
distance: train.distance,
|
||||||
signal: train.signal,
|
signal: train.signal,
|
||||||
online: train.online,
|
online: train.online,
|
||||||
driverId: train.driverId,
|
driverId: train.driverId,
|
||||||
driverName: train.driverName,
|
driverName: train.driverName,
|
||||||
currentStationName: train.currentStationName,
|
currentStationName: train.currentStationName,
|
||||||
currentStationHash: train.currentStationHash,
|
currentStationHash: train.currentStationHash,
|
||||||
connectedTrack: train.connectedTrack,
|
connectedTrack: train.connectedTrack,
|
||||||
locoType,
|
locoType,
|
||||||
locoURL: getLocoURL(locoType),
|
locoURL: getLocoURL(locoType),
|
||||||
cars: stock.slice(1),
|
cars: stock.slice(1),
|
||||||
|
|
||||||
lastSeen: train.lastSeen,
|
lastSeen: train.lastSeen,
|
||||||
|
|
||||||
timetableData: timetable
|
timetableData: timetable
|
||||||
? {
|
? {
|
||||||
timetableId: timetable.timetableId,
|
timetableId: timetable.timetableId,
|
||||||
SKR: timetable.SKR,
|
SKR: timetable.SKR,
|
||||||
TWR: timetable.TWR,
|
TWR: timetable.TWR,
|
||||||
route: timetable.route,
|
route: timetable.route,
|
||||||
category: timetable.category,
|
category: timetable.category,
|
||||||
followingStops: timetable.stopList,
|
followingStops: timetable.stopList,
|
||||||
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
||||||
sceneries: timetable.sceneries,
|
sceneries: timetable.sceneries,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
}) as Train[];
|
}) as Train[];
|
||||||
},
|
},
|
||||||
|
|
||||||
getDispatcherStatus(onlineStationData: StationAPIData) {
|
getDispatcherStatus(onlineStationData: StationAPIData) {
|
||||||
const { dispatchers } = this.apiData;
|
const { dispatchers } = this.apiData;
|
||||||
|
|
||||||
const prevDispatcherStatus = this.lastDispatcherStatuses.find(
|
const prevDispatcherStatus = this.lastDispatcherStatuses.find(
|
||||||
(dispatcher) => dispatcher.hash === onlineStationData.stationHash
|
(dispatcher) => dispatcher.hash === onlineStationData.stationHash
|
||||||
);
|
);
|
||||||
|
|
||||||
const stationStatus = !dispatchers
|
const stationStatus = !dispatchers
|
||||||
? undefined
|
? undefined
|
||||||
: dispatchers.find(
|
: dispatchers.find(
|
||||||
(status: string[]) => status[0] == onlineStationData.stationHash && status[1] == this.region.id
|
(status: string[]) => status[0] == onlineStationData.stationHash && status[1] == this.region.id
|
||||||
) || -1;
|
) || -1;
|
||||||
|
|
||||||
const statusTimestamp =
|
const statusTimestamp =
|
||||||
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusTimestamp : getStatusTimestamp(stationStatus);
|
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusTimestamp : getStatusTimestamp(stationStatus);
|
||||||
const statusID =
|
const statusID =
|
||||||
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hash: onlineStationData.stationHash,
|
hash: onlineStationData.stationHash,
|
||||||
statusID,
|
statusID,
|
||||||
statusTimestamp,
|
statusTimestamp,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getScheduledTrains(stationGeneralInfo: Station['generalInfo'], stationAPIData: StationAPIData) {
|
getScheduledTrains(stationGeneralInfo: Station['generalInfo'], stationAPIData: StationAPIData) {
|
||||||
const stationName = stationAPIData.stationName.toLowerCase();
|
const stationName = stationAPIData.stationName.toLowerCase();
|
||||||
|
|
||||||
stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0));
|
stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0));
|
||||||
|
|
||||||
return this.trainList.reduce((acc: ScheduledTrain[], train) => {
|
return this.trainList.reduce((acc: ScheduledTrain[], train) => {
|
||||||
if (!train.timetableData) return acc;
|
if (!train.timetableData) return acc;
|
||||||
|
|
||||||
const timetable = train.timetableData;
|
const timetable = train.timetableData;
|
||||||
if (!timetable.sceneries.includes(stationAPIData.stationHash)) return acc;
|
if (!timetable.sceneries.includes(stationAPIData.stationHash)) return acc;
|
||||||
|
|
||||||
const stopInfoIndex = timetable.followingStops.findIndex((stop) => {
|
const stopInfoIndex = timetable.followingStops.findIndex((stop) => {
|
||||||
const stopName = stop.stopNameRAW.toLowerCase();
|
const stopName = stop.stopNameRAW.toLowerCase();
|
||||||
|
|
||||||
if (stationName === stopName) return true;
|
if (stationName === stopName) return true;
|
||||||
if (stopName.includes(stationName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
if (stopName.includes(stationName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (stationName.includes(stopName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
if (stationName.includes(stopName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
stopName.includes('podg.') &&
|
stopName.includes('podg.') &&
|
||||||
stopName.split(', podg.')[0] &&
|
stopName.split(', podg.')[0] &&
|
||||||
stationName.includes(stopName.split(', podg.')[0])
|
stationName.includes(stopName.split(', podg.')[0])
|
||||||
)
|
)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
stationGeneralInfo &&
|
stationGeneralInfo &&
|
||||||
stationGeneralInfo.checkpoints &&
|
stationGeneralInfo.checkpoints &&
|
||||||
stationGeneralInfo.checkpoints.length > 0 &&
|
stationGeneralInfo.checkpoints.length > 0 &&
|
||||||
stationGeneralInfo.checkpoints.some((cp) =>
|
stationGeneralInfo.checkpoints.some((cp) =>
|
||||||
cp.checkpointName.toLowerCase().includes(stop.stopNameRAW.toLowerCase())
|
cp.checkpointName.toLowerCase().includes(stop.stopNameRAW.toLowerCase())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (stopInfoIndex == -1) return acc;
|
if (stopInfoIndex == -1) return acc;
|
||||||
|
|
||||||
const scheduledStopTrain = getScheduledTrain(train, stopInfoIndex, stationAPIData.stationName);
|
const scheduledStopTrain = getScheduledTrain(train, stopInfoIndex, stationAPIData.stationName);
|
||||||
|
|
||||||
if (stationGeneralInfo?.checkpoints) {
|
if (stationGeneralInfo?.checkpoints) {
|
||||||
for (const checkpoint of stationGeneralInfo.checkpoints) {
|
for (const checkpoint of stationGeneralInfo.checkpoints) {
|
||||||
const index = timetable.followingStops.findIndex(
|
const index = timetable.followingStops.findIndex(
|
||||||
(stop) => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase()
|
(stop) => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (index == -1) continue;
|
if (index == -1) continue;
|
||||||
|
|
||||||
const scheduledCheckpointTrain = getScheduledTrain(train, index, stationAPIData.stationName);
|
const scheduledCheckpointTrain = getScheduledTrain(train, index, stationAPIData.stationName);
|
||||||
checkpoint.scheduledTrains.push(scheduledCheckpointTrain);
|
checkpoint.scheduledTrains.push(scheduledCheckpointTrain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.push(scheduledStopTrain);
|
acc.push(scheduledStopTrain);
|
||||||
return acc;
|
return acc;
|
||||||
}, []) as ScheduledTrain[];
|
}, []) as ScheduledTrain[];
|
||||||
},
|
},
|
||||||
|
|
||||||
getStationTrains(stationAPIData: StationAPIData) {
|
getStationTrains(stationAPIData: StationAPIData) {
|
||||||
return this.trainList
|
return this.trainList
|
||||||
.filter(
|
.filter(
|
||||||
(train) =>
|
(train) =>
|
||||||
train?.region === this.region.id && train.online && train.currentStationName === stationAPIData.stationName
|
train?.region === this.region.id && train.online && train.currentStationName === stationAPIData.stationName
|
||||||
)
|
)
|
||||||
.map((train) => ({
|
.map((train) => ({
|
||||||
driverName: train.driverName,
|
driverName: train.driverName,
|
||||||
driverId: train.driverId,
|
driverId: train.driverId,
|
||||||
trainNo: train.trainNo,
|
trainNo: train.trainNo,
|
||||||
trainId: train.trainId,
|
trainId: train.trainId,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
setStationsOnlineInfo() {
|
setStationsOnlineInfo() {
|
||||||
const onlineStationNames: string[] = [];
|
const onlineStationNames: string[] = [];
|
||||||
const prevDispatcherStatuses: StoreState['lastDispatcherStatuses'] = [];
|
const prevDispatcherStatuses: StoreState['lastDispatcherStatuses'] = [];
|
||||||
|
|
||||||
this.apiData.stations?.forEach((stationAPIData) => {
|
this.apiData.stations?.forEach((stationAPIData) => {
|
||||||
if (stationAPIData.region !== this.region.id || !stationAPIData.isOnline) return;
|
if (stationAPIData.region !== this.region.id || !stationAPIData.isOnline) return;
|
||||||
const station = this.stationList.find((s) => s.name === stationAPIData.stationName);
|
const station = this.stationList.find((s) => s.name === stationAPIData.stationName);
|
||||||
|
|
||||||
onlineStationNames.push(stationAPIData.stationName);
|
onlineStationNames.push(stationAPIData.stationName);
|
||||||
|
|
||||||
const dispatcherStatus = this.getDispatcherStatus(stationAPIData);
|
const dispatcherStatus = this.getDispatcherStatus(stationAPIData);
|
||||||
prevDispatcherStatuses.push(dispatcherStatus);
|
prevDispatcherStatuses.push(dispatcherStatus);
|
||||||
|
|
||||||
const stationTrains = this.getStationTrains(stationAPIData);
|
const stationTrains = this.getStationTrains(stationAPIData);
|
||||||
const scheduledTrains = this.getScheduledTrains(station?.generalInfo, stationAPIData);
|
const scheduledTrains = this.getScheduledTrains(station?.generalInfo, stationAPIData);
|
||||||
|
|
||||||
const onlineInfo = {
|
const onlineInfo = {
|
||||||
name: stationAPIData.stationName,
|
name: stationAPIData.stationName,
|
||||||
hash: stationAPIData.stationHash,
|
hash: stationAPIData.stationHash,
|
||||||
region: stationAPIData.region,
|
region: stationAPIData.region,
|
||||||
maxUsers: stationAPIData.maxUsers,
|
maxUsers: stationAPIData.maxUsers,
|
||||||
currentUsers: stationAPIData.currentUsers,
|
currentUsers: stationAPIData.currentUsers,
|
||||||
spawns: parseSpawns(stationAPIData.spawnString),
|
spawns: parseSpawns(stationAPIData.spawnString),
|
||||||
dispatcherName: stationAPIData.dispatcherName,
|
dispatcherName: stationAPIData.dispatcherName,
|
||||||
dispatcherRate: stationAPIData.dispatcherRate,
|
dispatcherRate: stationAPIData.dispatcherRate,
|
||||||
dispatcherId: stationAPIData.dispatcherId,
|
dispatcherId: stationAPIData.dispatcherId,
|
||||||
dispatcherExp: stationAPIData.dispatcherExp,
|
dispatcherExp: stationAPIData.dispatcherExp,
|
||||||
dispatcherIsSupporter: stationAPIData.dispatcherIsSupporter,
|
dispatcherIsSupporter: stationAPIData.dispatcherIsSupporter,
|
||||||
stationTrains,
|
stationTrains,
|
||||||
statusTimestamp: dispatcherStatus.statusTimestamp,
|
statusTimestamp: dispatcherStatus.statusTimestamp,
|
||||||
statusID: dispatcherStatus.statusID,
|
statusID: dispatcherStatus.statusID,
|
||||||
scheduledTrains,
|
scheduledTrains,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!station) {
|
if (!station) {
|
||||||
this.stationList.push({
|
this.stationList.push({
|
||||||
name: stationAPIData.stationName,
|
name: stationAPIData.stationName,
|
||||||
onlineInfo,
|
onlineInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
station.onlineInfo = { ...onlineInfo };
|
station.onlineInfo = { ...onlineInfo };
|
||||||
|
|
||||||
this.stationList
|
this.stationList
|
||||||
.filter((station) => !onlineStationNames.includes(station.name) && station.onlineInfo)
|
.filter((station) => !onlineStationNames.includes(station.name) && station.onlineInfo)
|
||||||
.forEach((offlineStation) => {
|
.forEach((offlineStation) => {
|
||||||
offlineStation.onlineInfo = undefined;
|
offlineStation.onlineInfo = undefined;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.apiData.dispatchers != null) this.lastDispatcherStatuses = prevDispatcherStatuses;
|
if (this.apiData.dispatchers != null) this.lastDispatcherStatuses = prevDispatcherStatuses;
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchStationsGeneralInfo() {
|
async fetchStationsGeneralInfo() {
|
||||||
const sceneryData: StationJSONData[] = await (
|
const sceneryData: StationJSONData[] = await (
|
||||||
await axios.get(`${URLs.stacjownikAPI}/api/getSceneries?timestamp=${Math.floor(Date.now() / 1800000)}`)
|
await axios.get(`${URLs.stacjownikAPI}/api/getSceneries?timestamp=${Math.floor(Date.now() / 1800000)}`)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
if (!sceneryData) {
|
if (!sceneryData) {
|
||||||
this.dataStatuses.sceneries = DataStatus.Error;
|
this.dataStatuses.sceneries = DataStatus.Error;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stationList = sceneryData.map((scenery) => ({
|
this.stationList = sceneryData.map((scenery) => ({
|
||||||
name: scenery.name,
|
name: scenery.name,
|
||||||
|
|
||||||
generalInfo: {
|
generalInfo: {
|
||||||
...scenery,
|
...scenery,
|
||||||
authors: scenery.authors?.split(',').map((a) => a.trim()),
|
authors: scenery.authors?.split(',').map((a) => a.trim()),
|
||||||
routes:
|
routes:
|
||||||
scenery.routes
|
scenery.routes
|
||||||
?.split(';')
|
?.split(';')
|
||||||
.filter((routeString) => routeString)
|
.filter((routeString) => routeString)
|
||||||
.reduce(
|
.reduce(
|
||||||
(acc, routeString) => {
|
(acc, routeString) => {
|
||||||
const specs1 = routeString.split('_')[0];
|
const specs1 = routeString.split('_')[0];
|
||||||
const isInternal = specs1.startsWith('!');
|
const isInternal = specs1.startsWith('!');
|
||||||
const name = isInternal ? specs1.replace('!', '') : specs1;
|
const name = isInternal ? specs1.replace('!', '') : specs1;
|
||||||
|
|
||||||
const specs2 = routeString.split('_')[1].split('');
|
const specs2 = routeString.split('_')[1].split('');
|
||||||
const twoWay = specs2[0] == '2';
|
const twoWay = specs2[0] == '2';
|
||||||
const catenary = specs2[1] == 'E';
|
const catenary = specs2[1] == 'E';
|
||||||
const SBL = specs2[2] == 'S';
|
const SBL = specs2[2] == 'S';
|
||||||
const TWB = specs2[3] ? true : false;
|
const TWB = specs2[3] ? true : false;
|
||||||
|
|
||||||
const propName = twoWay
|
const propName = twoWay
|
||||||
? catenary
|
? catenary
|
||||||
? 'twoWayCatenaryRouteNames'
|
? 'twoWayCatenaryRouteNames'
|
||||||
: 'twoWayNoCatenaryRouteNames'
|
: 'twoWayNoCatenaryRouteNames'
|
||||||
: catenary
|
: catenary
|
||||||
? 'oneWayCatenaryRouteNames'
|
? 'oneWayCatenaryRouteNames'
|
||||||
: 'oneWayNoCatenaryRouteNames';
|
: 'oneWayNoCatenaryRouteNames';
|
||||||
|
|
||||||
acc[twoWay ? 'twoWay' : 'oneWay'].push({
|
acc[twoWay ? 'twoWay' : 'oneWay'].push({
|
||||||
name,
|
name,
|
||||||
SBL,
|
SBL,
|
||||||
TWB,
|
TWB,
|
||||||
catenary,
|
catenary,
|
||||||
isInternal,
|
isInternal,
|
||||||
tracks: twoWay ? 2 : 1,
|
tracks: twoWay ? 2 : 1,
|
||||||
});
|
});
|
||||||
if (!isInternal) acc[propName].push(name);
|
if (!isInternal) acc[propName].push(name);
|
||||||
|
|
||||||
if (SBL) acc['sblRouteNames'].push(name);
|
if (SBL) acc['sblRouteNames'].push(name);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
oneWay: [],
|
oneWay: [],
|
||||||
twoWay: [],
|
twoWay: [],
|
||||||
sblRouteNames: [],
|
sblRouteNames: [],
|
||||||
oneWayCatenaryRouteNames: [],
|
oneWayCatenaryRouteNames: [],
|
||||||
oneWayNoCatenaryRouteNames: [],
|
oneWayNoCatenaryRouteNames: [],
|
||||||
twoWayCatenaryRouteNames: [],
|
twoWayCatenaryRouteNames: [],
|
||||||
twoWayNoCatenaryRouteNames: [],
|
twoWayNoCatenaryRouteNames: [],
|
||||||
} as StationRoutes
|
} as StationRoutes
|
||||||
) || {},
|
) || {},
|
||||||
checkpoints: scenery.checkpoints
|
checkpoints: scenery.checkpoints
|
||||||
? scenery.checkpoints.split(';').map((sub) => ({ checkpointName: sub, scheduledTrains: [] }))
|
? scenery.checkpoints.split(';').map((sub) => ({ checkpointName: sub, scheduledTrains: [] }))
|
||||||
: [],
|
: [],
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
connectToWebsocket() {
|
connectToWebsocket() {
|
||||||
const socket = io(URLs.stacjownikAPI, {
|
const socket = io(URLs.stacjownikAPI, {
|
||||||
transports: ['websocket', 'polling'],
|
transports: ['websocket', 'polling'],
|
||||||
rememberUpgrade: true,
|
rememberUpgrade: true,
|
||||||
reconnection: true,
|
reconnection: true,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('connect_error', (err) => {
|
socket.on('connect_error', (err) => {
|
||||||
this.dataStatuses.connection = DataStatus.Error;
|
this.dataStatuses.connection = DataStatus.Error;
|
||||||
this.webSocket = undefined;
|
this.webSocket = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('UPDATE', (data: APIData) => {
|
socket.on('UPDATE', (data: APIData) => {
|
||||||
this.apiData = data;
|
this.apiData = data;
|
||||||
this.dataStatuses.connection = DataStatus.Loaded;
|
this.dataStatuses.connection = DataStatus.Loaded;
|
||||||
this.setOnlineData();
|
this.setOnlineData();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.emit('FETCH_DATA', {}, (data: APIData) => {
|
socket.emit('FETCH_DATA', {}, (data: APIData) => {
|
||||||
this.apiData = data;
|
this.apiData = data;
|
||||||
this.setOnlineData();
|
this.setOnlineData();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.webSocket = socket;
|
this.webSocket = socket;
|
||||||
},
|
},
|
||||||
|
|
||||||
async connectToAPI() {
|
async connectToAPI() {
|
||||||
await this.fetchStationsGeneralInfo();
|
await this.fetchStationsGeneralInfo();
|
||||||
|
|
||||||
this.connectToWebsocket();
|
this.connectToWebsocket();
|
||||||
},
|
},
|
||||||
|
|
||||||
async changeRegion(region: StoreState['region']) {
|
async changeRegion(region: StoreState['region']) {
|
||||||
this.region = region;
|
this.region = region;
|
||||||
|
|
||||||
await this.setOnlineData();
|
await this.setOnlineData();
|
||||||
},
|
},
|
||||||
|
|
||||||
async setOnlineData() {
|
async setOnlineData() {
|
||||||
if (!this.apiData.stations) {
|
if (!this.apiData.stations) {
|
||||||
this.dataStatuses.sceneries = DataStatus.Error;
|
this.dataStatuses.sceneries = DataStatus.Error;
|
||||||
this.dataStatuses.trains = DataStatus.Error;
|
this.dataStatuses.trains = DataStatus.Error;
|
||||||
this.dataStatuses.dispatchers = DataStatus.Error;
|
this.dataStatuses.dispatchers = DataStatus.Error;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataStatuses.sceneries = DataStatus.Loaded;
|
this.dataStatuses.sceneries = DataStatus.Loaded;
|
||||||
this.dataStatuses.trains = !this.apiData.trains ? DataStatus.Warning : DataStatus.Loaded;
|
this.dataStatuses.trains = !this.apiData.trains ? DataStatus.Warning : DataStatus.Loaded;
|
||||||
this.dataStatuses.dispatchers = !this.apiData.dispatchers ? DataStatus.Warning : DataStatus.Loaded;
|
this.dataStatuses.dispatchers = !this.apiData.dispatchers ? DataStatus.Warning : DataStatus.Loaded;
|
||||||
|
|
||||||
this.setTrainsOnlineData();
|
this.setTrainsOnlineData();
|
||||||
this.setStationsOnlineInfo();
|
this.setStationsOnlineInfo();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user