mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
Ładowanie danych nt pociągów i rozkładów jazdy z API Stacjownika
This commit is contained in:
@@ -46,7 +46,7 @@ export default interface Station {
|
||||
dispatcherIsSupporter: boolean;
|
||||
|
||||
statusTimestamp: number;
|
||||
statusTimeString: string;
|
||||
// statusTimeString: string;
|
||||
statusID: string;
|
||||
|
||||
stationTrains?: {
|
||||
|
||||
@@ -6,13 +6,8 @@ export interface StoreData {
|
||||
stationList: Station[];
|
||||
trainList: Train[];
|
||||
|
||||
activeTrainCount: number;
|
||||
activeStationCount: number;
|
||||
|
||||
dataConnectionStatus: DataStatus;
|
||||
|
||||
timetableDataStatus: DataStatus;
|
||||
sceneryDataStatus: DataStatus;
|
||||
dispatcherDataStatus: DataStatus;
|
||||
trainsDataStatus: DataStatus;
|
||||
trainsDataStatus: DataStatus;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ export default interface Train {
|
||||
TWR: boolean;
|
||||
SKR: boolean;
|
||||
routeDistance: number;
|
||||
sceneries: string[];
|
||||
};
|
||||
|
||||
stopStatus: string;
|
||||
stopLabel: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default interface TrainStop {
|
||||
export default interface TrainStop {
|
||||
stopName: string;
|
||||
stopNameRAW: string;
|
||||
stopType: string;
|
||||
@@ -6,19 +6,19 @@ export default interface TrainStop {
|
||||
mainStop: boolean;
|
||||
|
||||
arrivalLine: string | null;
|
||||
arrivalTimeString: string | null;
|
||||
// arrivalTimeString: string | null;
|
||||
arrivalTimestamp: number;
|
||||
arrivalRealTimeString: string | null;
|
||||
// arrivalRealTimeString: string | null;
|
||||
arrivalRealTimestamp: number;
|
||||
arrivalDelay: number;
|
||||
|
||||
departureLine: string | null;
|
||||
departureTimeString: string | null;
|
||||
// departureTimeString: string | null;
|
||||
departureTimestamp: number;
|
||||
departureRealTimeString: string | null;
|
||||
// departureRealTimeString: string | null;
|
||||
departureRealTimestamp: number;
|
||||
departureDelay: number;
|
||||
pointId: string;
|
||||
pointId: number;
|
||||
|
||||
comments?: any;
|
||||
|
||||
|
||||
@@ -1,19 +1,62 @@
|
||||
import StationAPIData from "./StationAPIData";
|
||||
|
||||
export default interface TrainAPIData {
|
||||
trainNo: number;
|
||||
driverId: number;
|
||||
|
||||
mass: number;
|
||||
length: number;
|
||||
speed: number;
|
||||
stockString: string;
|
||||
|
||||
signal: string;
|
||||
distance: number;
|
||||
connectedTrack: string;
|
||||
|
||||
driverName: string;
|
||||
driverId: number;
|
||||
driverIsSupporter: boolean;
|
||||
station: StationAPIData;
|
||||
dataSignal: string;
|
||||
dataSceneryConnection: string;
|
||||
dataDistance: number;
|
||||
dataCon: string;
|
||||
dataSpeed: number;
|
||||
dataMass: number;
|
||||
dataLength: number;
|
||||
region: string;
|
||||
isOnline: boolean;
|
||||
|
||||
currentStationName: string;
|
||||
currentStationHash: string;
|
||||
|
||||
online: boolean;
|
||||
lastSeen: number;
|
||||
|
||||
region: string;
|
||||
|
||||
timetable?: {
|
||||
timetableId: number;
|
||||
category: string;
|
||||
route: string;
|
||||
|
||||
stopList: {
|
||||
stopName: string;
|
||||
stopNameRAW: string;
|
||||
stopType: string;
|
||||
stopDistance: number;
|
||||
pointId: number;
|
||||
|
||||
mainStop: boolean;
|
||||
|
||||
arrivalLine: string;
|
||||
arrivalTimestamp: number;
|
||||
arrivalRealTimestamp: number;
|
||||
arrivalDelay: number;
|
||||
|
||||
departureLine: string;
|
||||
departureTimestamp: number;
|
||||
departureRealTimestamp: number;
|
||||
departureDelay: number;
|
||||
|
||||
comments?: any;
|
||||
|
||||
beginsHere: boolean;
|
||||
terminatesHere: boolean;
|
||||
confirmed: boolean;
|
||||
stopped: boolean;
|
||||
stopTime: number;
|
||||
}[];
|
||||
|
||||
TWR: boolean;
|
||||
SKR: boolean;
|
||||
sceneries: string[];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ export const URLs = {
|
||||
sceneryData: "https://spythere.github.io/api/stationData.json",
|
||||
sceneryDataDev: "http://127.0.0.1:8000/data",
|
||||
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
|
||||
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
||||
dispatchers: "https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1",
|
||||
stacjownikAPI: "https://stacjownik.herokuapp.com",
|
||||
getTimetableURL: (trainNo: string | number, region = "eu") => `https://api.td2.info.pl:9640/?method=readFromSWDR&value=getTimetable%3B${trainNo}%3B${region}`
|
||||
stacjownikAPIDev: "http://localhost:3001"
|
||||
// trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
|
||||
// getTimetableURL: (trainNo: string | number, region = "eu") => `https://api.td2.info.pl:9640/?method=readFromSWDR&value=getTimetable%3B${trainNo}%3B${region}`
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
import Station from "../interfaces/Station";
|
||||
import Timetable from "../interfaces/Timetable";
|
||||
import Train from "../interfaces/Train";
|
||||
import TrainStop from "../interfaces/TrainStop";
|
||||
|
||||
export const getLocoURL = (locoType: string): string => (`https://rj.td2.info.pl/dist/img/thumbnails/${locoType.includes("EN") ? locoType + "rb" : locoType}.png`)
|
||||
@@ -72,15 +71,7 @@ export const parseSpawns = (spawnString: string) => {
|
||||
|
||||
export const getTimestamp = (date: string | null): number => (date ? new Date(date).getTime() : 0);
|
||||
|
||||
export const timestampToString = (timestamp: number | null): string =>
|
||||
timestamp
|
||||
? new Date(timestamp).toLocaleTimeString("pl-PL", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit"
|
||||
})
|
||||
: "";
|
||||
|
||||
export const getTrainStopStatus = (stopInfo: TrainStop, currentStationName: string, station: Station) => {
|
||||
export const getTrainStopStatus = (stopInfo: TrainStop, currentStationName: string, stationName: string) => {
|
||||
let stopStatus = "",
|
||||
stopLabel = "",
|
||||
stopStatusID = -1;
|
||||
@@ -89,27 +80,49 @@ export const getTrainStopStatus = (stopInfo: TrainStop, currentStationName: stri
|
||||
stopStatus = "terminated";
|
||||
stopLabel = "Skończył bieg";
|
||||
stopStatusID = 5;
|
||||
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName == station.name) {
|
||||
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName == stationName) {
|
||||
stopStatus = "departed";
|
||||
stopLabel = "Odprawiony";
|
||||
stopStatusID = 2;
|
||||
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName != station.name) {
|
||||
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName != stationName) {
|
||||
stopStatus = "departed-away";
|
||||
stopLabel = "Odjechał";
|
||||
stopStatusID = 4;
|
||||
} else if (currentStationName == station.name && !stopInfo.stopped) {
|
||||
} else if (currentStationName == stationName && !stopInfo.stopped) {
|
||||
stopStatus = "online";
|
||||
stopLabel = "Na stacji";
|
||||
stopStatusID = 0;
|
||||
} else if (currentStationName == station.name && stopInfo.stopped) {
|
||||
} else if (currentStationName == stationName && stopInfo.stopped) {
|
||||
stopStatus = "stopped";
|
||||
stopLabel = "Postój";
|
||||
stopStatusID = 1;
|
||||
} else if (currentStationName != station.name) {
|
||||
} else if (currentStationName != stationName) {
|
||||
stopStatus = "arriving";
|
||||
stopLabel = "W drodze";
|
||||
stopStatusID = 3;
|
||||
}
|
||||
|
||||
return { stopStatus, stopLabel, stopStatusID };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export function getScheduledTrain(train: Train, trainStop: TrainStop, stationName: string) {
|
||||
const timetable = train.timetableData!;
|
||||
const trainStopStatus = getTrainStopStatus(trainStop, train.currentStationName, stationName);
|
||||
|
||||
return {
|
||||
trainNo: train.trainNo,
|
||||
driverName: train.driverName,
|
||||
driverId: train.driverId,
|
||||
currentStationName: train.currentStationName,
|
||||
currentStationHash: train.currentStationHash,
|
||||
category: timetable.category,
|
||||
beginsAt: timetable.followingStops[0].stopNameRAW,
|
||||
terminatesAt: timetable.followingStops[timetable.followingStops.length - 1].stopNameRAW,
|
||||
nearestStop: "",
|
||||
stopInfo: trainStop,
|
||||
stopLabel: trainStopStatus.stopLabel,
|
||||
stopStatus: trainStopStatus.stopStatus,
|
||||
stopStatusID: trainStopStatus.stopStatusID
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user