mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 13:58:12 +00:00
mocking danych
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,7 @@ import { ScheduledTrain, StopStatus } from '../interfaces/ScheduledTrain';
|
|||||||
import Train from '../interfaces/Train';
|
import Train from '../interfaces/Train';
|
||||||
import TrainStop from '../interfaces/TrainStop';
|
import TrainStop from '../interfaces/TrainStop';
|
||||||
|
|
||||||
export const getLocoURL = (locoType: string): string =>
|
export const getLocoURL = (locoType: string): string => `https://rj.td2.info.pl/dist/img/thumbnails/${locoType.includes('EN') ? locoType + 'rb' : locoType}.png`;
|
||||||
`https://rj.td2.info.pl/dist/img/thumbnails/${locoType.includes('EN') ? locoType + 'rb' : locoType}.png`;
|
|
||||||
|
|
||||||
export const getStatusID = (stationStatus: any): string => {
|
export const getStatusID = (stationStatus: any): string => {
|
||||||
if (!stationStatus) return 'unknown';
|
if (!stationStatus) return 'unknown';
|
||||||
@@ -58,7 +57,7 @@ export const getStatusTimestamp = (stationStatus: any): number => {
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseSpawns = (spawnString: string) => {
|
export const parseSpawns = (spawnString: string | null) => {
|
||||||
if (!spawnString) return [];
|
if (!spawnString) return [];
|
||||||
if (spawnString === 'NO_SPAWN') return [];
|
if (spawnString === 'NO_SPAWN') return [];
|
||||||
|
|
||||||
|
|||||||
+27
-52
@@ -8,13 +8,7 @@ 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, getStatusTimestamp, getStatusID, getScheduledTrain, parseSpawns } from '../scripts/utils/storeUtils';
|
||||||
getLocoURL,
|
|
||||||
getStatusTimestamp,
|
|
||||||
getStatusID,
|
|
||||||
getScheduledTrain,
|
|
||||||
parseSpawns,
|
|
||||||
} from '../scripts/utils/storeUtils';
|
|
||||||
import { APIData, StationJSONData, StoreState } from '../scripts/interfaces/store/storeTypes';
|
import { APIData, StationJSONData, StoreState } from '../scripts/interfaces/store/storeTypes';
|
||||||
import packageInfo from '../../package.json';
|
import packageInfo from '../../package.json';
|
||||||
|
|
||||||
@@ -69,10 +63,7 @@ export const useStore = defineStore('store', {
|
|||||||
if (!trains) return [];
|
if (!trains) return [];
|
||||||
|
|
||||||
this.trainList = trains
|
this.trainList = trains
|
||||||
.filter(
|
.filter((train) => train.region === this.region.id && (train.online || train.timetable || train.lastSeen > Date.now() - 180000))
|
||||||
(train) =>
|
|
||||||
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;
|
||||||
@@ -96,9 +87,8 @@ export const useStore = defineStore('store', {
|
|||||||
currentStationName: train.currentStationName,
|
currentStationName: train.currentStationName,
|
||||||
currentStationHash: train.currentStationHash,
|
currentStationHash: train.currentStationHash,
|
||||||
connectedTrack: train.connectedTrack,
|
connectedTrack: train.connectedTrack,
|
||||||
|
stockList: stock,
|
||||||
locoType,
|
locoType,
|
||||||
locoURL: getLocoURL(locoType),
|
|
||||||
cars: stock.slice(1),
|
|
||||||
|
|
||||||
lastSeen: train.lastSeen,
|
lastSeen: train.lastSeen,
|
||||||
isTimeout: train.isTimeout,
|
isTimeout: train.isTimeout,
|
||||||
@@ -125,20 +115,12 @@ export const useStore = defineStore('store', {
|
|||||||
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 : dispatchers.find((status: string[]) => status[0] == onlineStationData.stationHash && status[1] == this.region.id) || -1;
|
||||||
? undefined
|
|
||||||
: dispatchers.find(
|
|
||||||
(status: string[]) => status[0] == onlineStationData.stationHash && status[1] == this.region.id
|
|
||||||
) || -1;
|
|
||||||
|
|
||||||
const statusTimestamp =
|
const statusTimestamp = prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusTimestamp : getStatusTimestamp(stationStatus);
|
||||||
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusTimestamp : getStatusTimestamp(stationStatus);
|
const statusID = prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
||||||
const statusID =
|
|
||||||
prevDispatcherStatus && !dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hash: onlineStationData.stationHash,
|
hash: onlineStationData.stationHash,
|
||||||
@@ -162,26 +144,17 @@ export const useStore = defineStore('store', {
|
|||||||
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.split(', podg.')[0] && stationName.includes(stopName.split(', podg.')[0])) return true;
|
||||||
stopName.includes('podg.') &&
|
|
||||||
stopName.split(', podg.')[0] &&
|
|
||||||
stationName.includes(stopName.split(', podg.')[0])
|
|
||||||
)
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -194,9 +167,7 @@ export const useStore = defineStore('store', {
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -212,10 +183,7 @@ export const useStore = defineStore('store', {
|
|||||||
|
|
||||||
getStationTrains(stationAPIData: StationAPIData) {
|
getStationTrains(stationAPIData: StationAPIData) {
|
||||||
return this.trainList
|
return this.trainList
|
||||||
.filter(
|
.filter((train) => train?.region === this.region.id && train.online && train.currentStationName === stationAPIData.stationName)
|
||||||
(train) =>
|
|
||||||
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,
|
||||||
@@ -305,9 +273,7 @@ export const useStore = defineStore('store', {
|
|||||||
routes:
|
routes:
|
||||||
scenery.routesInfo.reduce(
|
scenery.routesInfo.reduce(
|
||||||
(acc, route) => {
|
(acc, route) => {
|
||||||
const propName: keyof StationRoutes = `${route.routeTracks == 2 ? 'twoWay' : 'oneWay'}${
|
const propName: keyof StationRoutes = `${route.routeTracks == 2 ? 'twoWay' : 'oneWay'}${route.isElectric ? '' : 'No'}CatenaryRouteNames`;
|
||||||
route.isElectric ? '' : 'No'
|
|
||||||
}CatenaryRouteNames`;
|
|
||||||
|
|
||||||
acc[route.routeTracks == 2 ? 'twoWay' : 'oneWay'].push({
|
acc[route.routeTracks == 2 ? 'twoWay' : 'oneWay'].push({
|
||||||
name: route.routeName,
|
name: route.routeName,
|
||||||
@@ -336,15 +302,24 @@ export const useStore = defineStore('store', {
|
|||||||
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() {
|
async connectToWebsocket() {
|
||||||
|
if (import.meta.env.VITE_APP_WS_DEV === '1') {
|
||||||
|
const mockWebsocketData = await import('../data/mockWebsocketData.json');
|
||||||
|
this.dataStatuses.connection = DataStatus.Loaded;
|
||||||
|
this.apiData = mockWebsocketData as any;
|
||||||
|
this.setOnlineData();
|
||||||
|
|
||||||
|
console.warn('Stacjownik działa w trybie mockowania danych z WS');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const socket = io(URLs.stacjownikAPI, {
|
const socket = io(URLs.stacjownikAPI, {
|
||||||
// transports: ['websocket', 'polling'],
|
// transports: ['websocket', 'polling'],
|
||||||
rememberUpgrade: true,
|
rememberUpgrade: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user