refactor typów danych

This commit is contained in:
2023-11-10 15:04:49 +01:00
parent e82b4b8817
commit f8b4ce103f
84 changed files with 1011 additions and 1173 deletions
@@ -1,49 +0,0 @@
import Filter from '../../interfaces/Filter';
export const filterInitStates: Filter = {
default: false,
notDefault: false,
real: false,
fictional: false,
SPK: false,
SCS: false,
SPE: false,
SUP: false,
noSUP: false,
ręczne: false,
'ręczne+SPK': false,
'ręczne+SCS': false,
mechaniczne: false,
'mechaniczne+SPK': false,
'mechaniczne+SCS': false,
współczesna: false,
kształtowa: false,
historyczna: false,
mieszana: false,
SBL: false,
PBL: false,
minLevel: 0,
maxLevel: 20,
minOneWayCatenary: 0,
minOneWay: 0,
minTwoWayCatenary: 0,
minTwoWay: 0,
'include-selected': false,
'no-1track': false,
'no-2track': false,
free: true,
occupied: false,
ending: false,
nonPublic: false,
unavailable: true,
abandoned: true,
afkStatus: false,
endingStatus: false,
noSpaceStatus: false,
unavailableStatus: false,
unsignedStatus: false,
authors: '',
onlineFromHours: 0
};
-7
View File
@@ -1,7 +0,0 @@
export enum DataStatus {
Initialized = -1,
Loading = 0,
Error = 1,
Loaded = 2,
Warning = 3
}
-9
View File
@@ -1,9 +0,0 @@
export enum DispatcherStatus {
INVALID = -2,
UNKNOWN = -1,
AFK = 1,
ENDING = 2,
NO_SPACE = 3,
UNAVAILABLE = 4,
NOT_LOGGED_IN = 5
}
-14
View File
@@ -1,14 +0,0 @@
export const enum JournalFilterType {
ACTIVE = 'active',
FULFILLED = 'fulfilled',
ABANDONED = 'abandoned',
ALL = 'all',
TWR = 'twr',
SKR = 'skr',
TWR_SKR = 'twr-skr'
}
export enum JournalFilterSection {
TIMETABLE_STATUS = 'timetable-status',
TWRSKR = 'twrskr'
}
-21
View File
@@ -1,21 +0,0 @@
export enum TrainFilterSection {
TRAIN_TYPE = 'TRAIN_TYPE',
TIMETABLE_TYPE = 'TIMETABLE_TYPE',
COMMENTS = 'COMMENTS',
TIMETABLE = 'TIMETABLE'
}
export const enum TrainFilterType {
noComments = 'noComments',
withComments = 'withComments',
twr = 'twr',
skr = 'skr',
common = 'common',
passenger = 'passenger',
freight = 'freight',
other = 'other',
noTimetable = 'noTimetable',
withTimetable = 'withTimetable'
}
-48
View File
@@ -1,48 +0,0 @@
export default interface Filter {
[key: string]: boolean | number | string;
default: boolean;
notDefault: boolean;
real: boolean;
fictional: boolean;
SPK: boolean;
SCS: boolean;
SPE: boolean;
SUP: boolean;
noSUP: boolean;
ręczne: boolean;
'ręczne+SPK': boolean;
'ręczne+SCS': boolean;
mechaniczne: boolean;
'mechaniczne+SPK': boolean;
'mechaniczne+SCS': boolean;
SBL: boolean;
PBL: boolean;
współczesna: boolean;
kształtowa: boolean;
historyczna: boolean;
mieszana: boolean;
minLevel: number;
maxLevel: number;
minOneWayCatenary: number;
minOneWay: number;
minTwoWayCatenary: number;
minTwoWay: number;
'no-1track': boolean;
'no-2track': boolean;
'include-selected': boolean;
free: boolean;
occupied: boolean;
nonPublic: boolean;
unavailable: boolean;
abandoned: boolean;
endingStatus: boolean;
afkStatus: boolean;
noSpaceStatus: boolean;
unavailableStatus: boolean;
unsignedStatus: boolean;
authors: string;
onlineFromHours: number;
}
-6
View File
@@ -1,6 +0,0 @@
export default interface FilterOption {
id: string;
name: string;
value: boolean;
defaultValue: boolean;
}
-38
View File
@@ -1,38 +0,0 @@
interface Scenery {
stationName: string;
stationURL: string;
stationLines: string;
stationProject: string;
reqLevel: string;
supportersOnly: string;
signalType: string;
controlType: string;
SBL: string;
twoWayBlock: string;
routesOneWayCatenary: number;
routesOneWayOther: number;
routesTwoWayCatenary: number;
routesToWayOther: number;
default: boolean;
nonPublic: boolean;
unavailable: boolean;
hasData: boolean;
stops: string[];
checkpoints: string[];
currentDispatcher: string;
currentDispatcherId: number;
currentDispatcherFrom: number;
dispatcherHistory: {
dispatcherName: string;
dispatcherId: number;
dispatcherFrom: number;
dispatcherTo: number;
}[];
}
export default Scenery;
-43
View File
@@ -1,43 +0,0 @@
import TrainStop from './TrainStop';
export enum StopStatus {
'arriving' = 'arriving',
'departed' = 'departed',
'departed-away' = 'departed-away',
'online' = 'online',
'stopped' = 'stopped',
'terminated' = 'terminated'
}
export interface ScheduledTrain {
checkpointName: string;
trainId: string;
trainNo: number;
driverName: string;
driverId: number;
currentStationName: string;
currentStationHash: string;
category: string;
stopInfo: TrainStop;
terminatesAt: string;
beginsAt: string;
prevStationName: string;
nextStationName: string;
arrivingLine: string | null;
departureLine: string | null;
prevDepartureLine: string | null;
nextArrivalLine: string | null;
signal: string;
connectedTrack: string;
stopLabel: string;
stopStatus: StopStatus;
stopStatusID: number;
}
+1 -2
View File
@@ -1,5 +1,4 @@
import { Availability, OnlineScenery } from './store/storeTypes';
import { ScheduledTrain } from './ScheduledTrain';
import { Availability, OnlineScenery, ScheduledTrain } from '../../store/typings';
import StationRoutes from './StationRoutes';
export default interface Station {
-13
View File
@@ -1,13 +0,0 @@
import { DataStatus } from '../enums/DataStatus';
import Station from './Station';
import Train from './Train';
export interface StoreData {
stationList: Station[];
trainList: Train[];
dispatcherCount: number;
sceneryDataStatus: DataStatus;
dispatcherDataStatus: DataStatus;
trainsDataStatus: DataStatus;
}
-23
View File
@@ -1,23 +0,0 @@
import TrainStop from './TrainStop';
export default interface Timetable {
trainNo: number;
success: boolean;
data?: {
trainNo: number;
driverName: string;
driverId: number;
currentStationName: string;
currentStationHash: string;
timetableId: number;
category: string;
route: string;
TWR: boolean;
SKR: boolean;
routeDistance: number;
followingStops: TrainStop[];
followingSceneries: string[];
};
}
+1 -1
View File
@@ -1,4 +1,4 @@
import TrainStop from './TrainStop';
import { TrainStop } from '../../store/typings';
export default interface Train {
trainId: string;
-30
View File
@@ -1,30 +0,0 @@
export default interface TrainStop {
stopName: string;
stopNameRAW: string;
stopType: string;
stopDistance: number;
mainStop: boolean;
arrivalLine: string | null;
// arrivalTimeString: string | null;
arrivalTimestamp: number;
// arrivalRealTimeString: string | null;
arrivalRealTimestamp: number;
arrivalDelay: number;
departureLine: string | null;
// departureTimeString: string | null;
departureTimestamp: number;
// departureRealTimeString: string | null;
departureRealTimestamp: number;
departureDelay: number;
pointId: number;
comments?: any;
beginsHere: boolean;
terminatesHere: boolean;
confirmed: boolean;
stopped: boolean;
stopTime: number | null;
}
@@ -1,7 +0,0 @@
import { TrainFilterSection, TrainFilterType } from '../../enums/TrainFilterType';
export interface TrainFilter {
id: TrainFilterType;
section: TrainFilterSection;
isActive: boolean;
}
@@ -1,27 +0,0 @@
export interface Sum {
routeDistance: number;
}
export interface Max {
routeDistance: number;
}
export interface Min {
routeDistance: number;
}
export interface Avg {
routeDistance: number;
}
export interface Count {
_all: number;
}
export interface DispatcherStatsAPIData {
_sum: Sum;
_max: Max;
_min: Min;
_avg: Avg;
_count: Count;
}
@@ -1,18 +0,0 @@
export interface DispatcherHistory {
id: string;
currentDuration: number;
dispatcherId: number;
dispatcherName: string;
dispatcherLevel: number | null;
dispatcherRate: number;
dispatcherIsSupporter: boolean;
dispatcherStatus?: number;
isOnline: boolean;
lastOnlineTimestamp: number;
region: string;
stationHash: string;
stationName: string;
timestampFrom: number;
timestampTo?: number;
}
@@ -1,27 +0,0 @@
export interface Sum {
routeDistance: number;
confirmedStopsCount: number;
allStopsCount: number;
currentDistance: number;
}
export interface Count {
fulfilled: number;
terminated: number;
_all: number;
}
export interface Max {
routeDistance: number;
}
export interface Avg {
routeDistance: number;
}
export interface DriverStatsAPIData {
_sum: Sum;
_count: Count;
_max: Max;
_avg: Avg;
}
@@ -1,21 +0,0 @@
import { DispatcherStatus } from '../../enums/DispatcherStatus';
export default interface ActiveSceneryAPIData {
dispatcherId: number;
dispatcherName: string;
dispatcherIsSupporter: boolean;
stationName: string;
stationHash: string;
region: string;
maxUsers: number;
currentUsers: number;
spawn: number;
lastSeen: number;
dispatcherExp: number;
nameFromHeader: string;
spawnString: string | null;
networkConnectionString: string;
isOnline: number;
dispatcherRate: number;
dispatcherStatus: DispatcherStatus | number;
}
@@ -1,18 +0,0 @@
export default interface StationAPIData {
dispatcherId: number;
dispatcherName: string;
dispatcherIsSupporter: boolean;
stationName: string;
stationHash: string;
region: string;
maxUsers: number;
currentUsers: number;
spawn: number;
lastSeen: number;
dispatcherExp: number;
nameFromHeader: string;
spawnString: string | null;
networkConnectionString: string;
isOnline: number;
dispatcherRate: number;
}
@@ -1,51 +0,0 @@
import { TimetableHistory } from './TimetablesAPIData';
export interface ITimetablesDailyStats {
totalTimetables: number;
distanceSum: number;
distanceAvg: number;
timetableId: number;
timetableAuthor: string;
timetableDriver: string;
timetableRouteDistance: number;
mostActiveDispatchers: {
name: string;
count: number;
}[];
mostActiveDrivers: {
name: string;
distance: number;
}[];
longestDuties: {
name: string;
duration: number;
station: string;
}[];
}
export interface ITimetablesDailyStatsResponse {
totalTimetables: number;
distanceSum: number;
distanceAvg: number;
maxTimetable: TimetableHistory | null;
mostActiveDispatchers: {
name: string;
count: number;
}[];
mostActiveDrivers: {
name: string;
distance: number;
}[];
longestDuties: {
name: string;
duration: number;
station: string;
}[];
}
@@ -1,67 +0,0 @@
export interface TimetableHistory {
id: number;
createdAt: string;
updatedAt: string;
timetableId: number;
trainNo: number;
trainCategoryCode: string;
driverId: number;
driverName: string;
driverLevel: number | null;
driverIsSupporter: boolean;
route: string;
twr: number;
skr: number;
sceneriesString: string;
currentLocation: string[];
routeDistance: number;
currentDistance: number;
confirmedStopsCount: number;
allStopsCount: number;
beginDate: string;
endDate: string;
scheduledBeginDate: string;
scheduledEndDate: string;
terminated: boolean;
fulfilled: boolean;
authorName?: string;
authorId?: number;
stopsString?: string;
stockString?: string;
stockHistory: string[];
stockMass?: number;
stockLength?: number;
maxSpeed?: number;
hashesString?: string;
currentSceneryName?: string;
currentSceneryHash?: string;
routeSceneries?: string;
checkpointArrivals?: string[];
checkpointDepartures?: string[];
checkpointArrivalsScheduled?: string[];
checkpointDeparturesScheduled?: string[];
checkpointStopTypes?: string[];
}
export interface SceneryTimetableHistory {
timetables: TimetableHistory[];
// totalCount: number;
// sceneryName: string;
}
@@ -1,23 +0,0 @@
import { JournalTimetableSorter } from '../../types/JournalTimetablesTypes';
export interface TimetablesQueryParams {
driverName?: string;
trainNo?: string;
timetableId?: string;
authorName?: string;
timestampFrom?: number;
timestampTo?: number;
issuedFrom?: string;
countFrom?: number;
countLimit?: number;
fulfilled?: number;
terminated?: number;
twr?: number;
skr?: number;
sortBy?: JournalTimetableSorter['id'];
}
@@ -1,68 +0,0 @@
export interface TimetableStop {
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;
}
export interface TrainTimetable {
timetableId: number;
category: string;
route: string;
stopList: TimetableStop[];
TWR: boolean;
SKR: boolean;
sceneries: string[];
}
export interface TrainAPIData {
trainNo: number;
mass: number;
length: number;
speed: number;
stockString: string;
signal: string;
distance: number;
connectedTrack: string;
driverName: string;
driverId: number;
driverIsSupporter: boolean;
driverLevel?: number;
currentStationName: string;
currentStationHash: string;
online: boolean;
lastSeen: number;
region: string;
isTimeout: boolean;
timetable?: TrainTimetable;
}
@@ -1,41 +0,0 @@
export interface Author {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
}
export interface ReleaseAPIData {
url: string;
assets_url: string;
upload_url: string;
html_url: string;
id: number;
author: Author;
node_id: string;
tag_name: string;
target_commitish: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: Date;
published_at: Date;
assets: any[];
tarball_url: string;
zipball_url: string;
body: string;
}
@@ -1,13 +0,0 @@
export interface RollingStockGithubData {
usage: Record<string, string>;
info: RollingStockInfo;
}
export interface RollingStockInfo {
'loco-e': [string, string, string, string, boolean][];
'loco-s': [string, string, string, string, boolean][];
'loco-szt': [string, string, string, string, boolean][];
'loco-ezt': [string, string, string, string, boolean][];
'car-passenger': [string, string, boolean, boolean, string][];
'car-cargo': [string, string, boolean, boolean, string][];
}
-139
View File
@@ -1,139 +0,0 @@
import { Socket } from 'socket.io-client';
import { DataStatus } from '../../enums/DataStatus';
import StationAPIData from '../api/StationAPIData';
import { TrainAPIData } from '../api/TrainAPIData';
import { DispatcherStatsAPIData } from '../api/DispatcherStatsAPIData';
import { DriverStatsAPIData } from '../api/DriverStatsAPIData';
import { RollingStockGithubData } from '../github_api/StockInfoGithubData';
import Station from '../Station';
import { ScheduledTrain } from '../ScheduledTrain';
import { DispatcherStatus } from '../../enums/DispatcherStatus';
import ActiveSceneryAPIData from '../api/SceneryAPIData';
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
export interface RegionCounters {
stationCount: number;
trainsCount: number;
timetablesCount: number;
}
export interface StoreState {
stationList: Station[];
apiData: APIData;
rollingStockData?: RollingStockGithubData;
regionOnlineCounters: RegionCounters[];
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: DispatcherStatus }[];
sceneryData: any[][];
region: { id: string; value: string };
trainCount: number;
stationCount: number;
webSocket?: Socket;
isOffline: boolean;
dispatcherStatsName: string;
dispatcherStatsData?: DispatcherStatsAPIData;
driverStatsName: string;
driverStatsData?: DriverStatsAPIData;
driverStatsStatus: DataStatus;
chosenModalTrainId?: string;
currentStatsTab: 'daily' | 'driver' | null;
dataStatuses: {
connection: DataStatus;
sceneries: DataStatus;
timetables: DataStatus;
dispatchers: DataStatus;
trains: DataStatus;
};
listenerLaunched: boolean;
blockScroll: boolean;
modalLastClickedTarget: EventTarget | null;
}
export interface APIData {
stations?: StationAPIData[];
dispatchers?: string[][];
trains?: TrainAPIData[];
activeSceneries?: ActiveSceneryAPIData[];
connectedSocketCount: number;
}
export interface StationRoutesInfo {
routeName: string;
isElectric: boolean;
isInternal: boolean;
isRouteSBL: boolean;
routeLength: number;
routeSpeed: number;
routeTracks: number;
}
export interface StationJSONData {
name: string;
abbr: string;
url: string;
lines: string;
project: string;
projectUrl: string;
reqLevel: number;
signalType: string;
controlType: string;
SUP: boolean;
// routes: string;
routesInfo: StationRoutesInfo[];
checkpoints: string | null;
authors?: string;
availability: Availability;
}
export interface StationTrain {
driverName: string;
driverId: number;
trainNo: number;
trainId: string;
stopStatus: string;
}
export interface OnlineScenery {
name: string;
hash: string;
region: string;
maxUsers: number;
currentUsers: number;
spawns: { spawnName: string; spawnLength: number; isElectrified: boolean }[];
dispatcherName: string;
dispatcherRate: number;
dispatcherId: number;
dispatcherExp: number;
dispatcherIsSupporter: boolean;
dispatcherStatus: DispatcherStatus | number;
isOnline: boolean;
stationTrains?: StationTrain[];
scheduledTrains?: ScheduledTrain[];
scheduledTrainCount: {
all: number;
confirmed: number;
unconfirmed: number;
};
}
-49
View File
@@ -1,49 +0,0 @@
export default class StorageManager {
static registerStorage(name: string) {
window.localStorage.setItem(name, '1');
}
static unregisterStorage(name: string) {
window.localStorage.removeItem(name);
}
static isRegistered(name: string) {
return window.localStorage.getItem(name) ? true : false;
}
static setBooleanValue(key: string, val: boolean) {
window.localStorage.setItem(key, val.toString());
}
static setNumericValue(key: string, val: number) {
window.localStorage.setItem(key, val.toString());
}
static setStringValue(key: string, val: string) {
window.localStorage.setItem(key, val);
}
static setValue(key: string, val: any) {
if (typeof val == 'boolean') this.setBooleanValue(key, val);
else if (typeof val == 'number') this.setNumericValue(key, val);
else if (typeof val == 'string') this.setStringValue(key, val);
else this.setStringValue(key, val);
}
static removeValue(key: string) {
window.localStorage.removeItem(key);
}
static getBooleanValue(key: string): boolean {
return window.localStorage.getItem(key) === 'true' ? true : false;
}
static getStringValue(key: string): string {
return window.localStorage.getItem(key) || '';
}
static getNumericValue(key: string): number {
const itemValue = window.localStorage.getItem(key);
return itemValue ? parseInt(itemValue) : 0;
}
}
-146
View File
@@ -1,146 +0,0 @@
import { TrainFilter } from '../interfaces/Trains/TrainFilter';
import { TrainFilterType } from '../enums/TrainFilterType';
import Train from '../interfaces/Train';
import TrainStop from '../interfaces/TrainStop';
function confirmedPercentage(stops: TrainStop[] | undefined) {
if (!stops) return -1;
return Number(((stops.filter((stop) => stop.confirmed).length / stops.length) * 100).toFixed(0));
}
function currentDelay(stops: TrainStop[] | undefined) {
if (!stops) return -Infinity;
const delay =
stops.find(
(stop, i) =>
(i == 0 && !stop.confirmed) || (i > 0 && stops[i - 1].confirmed && !stop.confirmed)
)?.departureDelay || 0;
return delay;
}
function filterTrainList(
trainList: Train[],
searchedTrain: string,
searchedDriver: string,
filters: TrainFilter[]
) {
return trainList.filter((train) => {
const isFiltered = filters.every((f) => {
if (f.isActive) return true;
switch (f.id) {
case TrainFilterType.noTimetable:
return train.timetableData;
case TrainFilterType.withTimetable:
return !train.timetableData;
case TrainFilterType.withComments:
return !train.timetableData?.followingStops.some((stop) => stop.comments);
case TrainFilterType.noComments:
return train.timetableData?.followingStops.some((stop) => stop.comments);
case TrainFilterType.twr:
return !train.timetableData?.TWR;
case TrainFilterType.skr:
return !train.timetableData?.SKR;
case TrainFilterType.common:
return train.timetableData?.SKR || train.timetableData?.TWR;
case TrainFilterType.passenger:
return !/^[AMRE]\D{2}$/.test(train.timetableData?.category || '');
case TrainFilterType.freight:
return !train.timetableData?.category.startsWith('T');
case TrainFilterType.other:
return !/^[PXZL]\D{2}$/.test(train.timetableData?.category || '');
default:
return true;
}
});
return (
(searchedTrain.length > 0 ? train.trainNo.toString().startsWith(searchedTrain) : true) &&
(searchedDriver.length > 0
? train.driverName.toLowerCase().startsWith(searchedDriver.toLowerCase())
: true) &&
isFiltered
);
});
}
function sortTrainList(trainList: Train[], sorterActive: { id: string; dir: number }) {
return trainList.sort((a: Train, b: Train) => {
switch (sorterActive.id) {
case 'id':
if ((a.timetableData?.timetableId || -1) > (b.timetableData?.timetableId || -1))
return sorterActive.dir;
return -sorterActive.dir;
case 'mass':
if (a.mass > b.mass) return sorterActive.dir;
return -sorterActive.dir;
case 'routeDistance':
if ((a.timetableData?.routeDistance || -1) > (b.timetableData?.routeDistance || -1))
return sorterActive.dir;
return -sorterActive.dir;
case 'progress':
if (
confirmedPercentage(a.timetableData?.followingStops) >
confirmedPercentage(b.timetableData?.followingStops)
)
return sorterActive.dir;
return -sorterActive.dir;
case 'delay':
if (
currentDelay(a.timetableData?.followingStops) >
currentDelay(b.timetableData?.followingStops)
)
return sorterActive.dir;
return -sorterActive.dir;
case 'speed':
if (a.speed > b.speed) return sorterActive.dir;
return -sorterActive.dir;
case 'timetable':
if (a.trainNo > b.trainNo) return sorterActive.dir;
return -sorterActive.dir;
case 'length':
if (a.length > b.length) return sorterActive.dir;
return -sorterActive.dir;
default:
break;
}
return 0;
});
}
export function filteredTrainList(
trainList: Train[],
searchedTrain: string,
searchedDriver: string,
sorterActive: { id: string; dir: number },
filters: TrainFilter[]
) {
const filtered = filterTrainList(trainList, searchedTrain, searchedDriver, filters);
return [...sortTrainList(filtered, sorterActive)];
}
@@ -1,8 +0,0 @@
export type JournalDispatcherSearcher = {
[key in 'search-dispatcher' | 'search-station' | 'search-date']: string;
};
export interface JournalDispatcherSorter {
id: 'timestampFrom' | 'duration';
dir: -1 | 1;
}
@@ -1,25 +0,0 @@
import { JournalFilterType } from '../../scripts/enums/JournalFilterType';
export type JournalTimetableSearchKey =
| 'search-driver'
| 'search-train'
| 'search-date'
| 'search-dispatcher'
| 'search-issuedFrom';
export type JournalTimetableSorterKey = 'timetableId' | 'beginDate' | 'distance' | 'total-stops';
export type JournalTimetableSearchType = {
[key in JournalTimetableSearchKey]: string;
};
export interface JournalFilter {
id: JournalFilterType;
filterSection: string;
isActive: boolean;
}
export interface JournalTimetableSorter {
id: JournalTimetableSorterKey;
dir: 'asc' | 'desc';
}
+8 -7
View File
@@ -1,6 +1,6 @@
import { Filter } from '../../components/StationsView/typings';
import { Status } from '../../typings/common';
import { HeadIdsTypes } from '../data/stationHeaderNames';
import { DispatcherStatus } from '../enums/DispatcherStatus';
import Filter from '../interfaces/Filter';
import Station from '../interfaces/Station';
export const sortStations = (
@@ -83,16 +83,17 @@ export const filterStations = (station: Station, filters: Filter) => {
if (station.onlineInfo) {
const { dispatcherStatus } = station.onlineInfo;
const isEnding = dispatcherStatus == DispatcherStatus.ENDING && filters['endingStatus'];
const isEnding = dispatcherStatus == Status.ActiveDispatcher.ENDING && filters['endingStatus'];
const isNotSigned =
(dispatcherStatus == DispatcherStatus.NOT_LOGGED_IN ||
dispatcherStatus == DispatcherStatus.UNAVAILABLE) &&
(dispatcherStatus == Status.ActiveDispatcher.NOT_LOGGED_IN ||
dispatcherStatus == Status.ActiveDispatcher.UNAVAILABLE) &&
filters['unavailableStatus'];
const isAFK = dispatcherStatus == DispatcherStatus.AFK && filters['afkStatus'];
const isAFK = dispatcherStatus == Status.ActiveDispatcher.AFK && filters['afkStatus'];
const isNoSpace = dispatcherStatus == DispatcherStatus.NO_SPACE && filters['noSpaceStatus'];
const isNoSpace =
dispatcherStatus == Status.ActiveDispatcher.NO_SPACE && filters['noSpaceStatus'];
const isOccupied = station.onlineInfo && filters['occupied'];
-264
View File
@@ -1,264 +0,0 @@
import { ScheduledTrain, StopStatus } from '../interfaces/ScheduledTrain';
import Station from '../interfaces/Station';
import Train from '../interfaces/Train';
import TrainStop from '../interfaces/TrainStop';
import ActiveSceneryAPIData from '../interfaces/api/SceneryAPIData';
import { StationTrain } from '../interfaces/store/storeTypes';
export const getLocoURL = (locoType: string): string =>
`https://rj.td2.info.pl/dist/img/thumbnails/${
locoType.includes('EN') ? locoType + 'rb' : locoType
}.png`;
export const getStatusTimestamp = (stationStatus: any): number => {
if (!stationStatus) return -2;
const statusCode = stationStatus[2];
const statusTimestamp = stationStatus[3];
switch (statusCode) {
case 0:
case 1:
case 3:
return statusTimestamp;
case 2:
if (statusTimestamp == 0) return 0;
break;
default:
break;
}
return -1;
};
export const parseSpawns = (spawnString: string | null) => {
if (!spawnString) return [];
if (spawnString === 'NO_SPAWN') return [];
return spawnString.split(';').map((spawn) => {
const spawnArray = spawn.split(',');
const spawnName = spawnArray[6] ? spawnArray[6] : spawnArray[0];
const spawnLength = parseInt(spawnArray[2]);
const isElectrified = spawnArray[3] == 'True';
return { spawnName, spawnLength, isElectrified };
});
};
export const getTimestamp = (date: string | null): number => (date ? new Date(date).getTime() : 0);
export const getTrainStopStatus = (
stopInfo: TrainStop,
currentStationName: string,
sceneryName: string
) => {
let stopStatus = StopStatus['arriving'],
stopLabel = '',
stopStatusID = -1;
if (stopInfo.terminatesHere && stopInfo.confirmed) {
stopStatus = StopStatus['terminated'];
stopLabel = 'Skończył bieg';
stopStatusID = 5;
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName == sceneryName) {
stopStatus = StopStatus['departed'];
stopLabel = 'Odprawiony';
stopStatusID = 2;
} else if (!stopInfo.terminatesHere && stopInfo.confirmed && currentStationName != sceneryName) {
stopStatus = StopStatus['departed-away'];
stopLabel = 'Odjechał';
stopStatusID = 4;
} else if (currentStationName == sceneryName && !stopInfo.stopped) {
stopStatus = StopStatus['online'];
stopLabel = 'Na stacji';
stopStatusID = 0;
} else if (currentStationName == sceneryName && stopInfo.stopped) {
stopStatus = StopStatus['stopped'];
stopLabel = 'Postój';
stopStatusID = 1;
} else if (currentStationName != sceneryName) {
stopStatus = StopStatus['arriving'];
stopLabel = 'W drodze';
stopStatusID = 3;
}
return { stopStatus, stopLabel, stopStatusID };
};
export function getCheckpointTrain(
train: Train,
trainStopIndex: number,
sceneryName: string
): ScheduledTrain {
const timetable = train.timetableData!;
const followingStops = timetable.followingStops;
const trainStop = followingStops[trainStopIndex];
const trainStopStatus = getTrainStopStatus(trainStop, train.currentStationName, sceneryName);
let prevStationName = '',
nextStationName = '';
let prevDepartureLine: string | null = null,
nextArrivalLine: string | null = null;
for (let i = trainStopIndex - 1; i >= 0; i--) {
if (/strong|podg/g.test(followingStops[i].stopName)) {
prevStationName = followingStops[i].stopNameRAW.replace(/,.*/g, '');
break;
}
}
for (let i = trainStopIndex + 1; i < followingStops.length; i++) {
if (/strong|podg/g.test(followingStops[i].stopName)) {
nextStationName = followingStops[i].stopNameRAW.replace(/,.*/g, '');
break;
}
}
let departureLine: string | null = null;
let arrivingLine: string | null = null;
for (let i = trainStopIndex; i < followingStops.length; i++) {
const currentStop = followingStops[i];
if (currentStop.departureLine == null) continue;
if (!/-|_|it|sbl/gi.test(currentStop.departureLine)) {
departureLine = currentStop.departureLine;
nextArrivalLine = followingStops[i + 1]?.arrivalLine || null;
break;
}
}
for (let i = trainStopIndex; i >= 0; i--) {
const currentStop = followingStops[i];
if (currentStop.arrivalLine == null) continue;
if (!/-|_|it|sbl/gi.test(currentStop.arrivalLine)) {
arrivingLine = currentStop.arrivalLine;
prevDepartureLine = followingStops[i - 1]?.departureLine || null;
break;
}
}
return {
checkpointName: trainStop.stopNameRAW,
trainNo: train.trainNo,
trainId: train.trainId,
signal: train.signal,
connectedTrack: train.connectedTrack,
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,
nextStationName,
prevStationName,
stopInfo: trainStop,
stopLabel: trainStopStatus.stopLabel,
stopStatus: trainStopStatus.stopStatus,
stopStatusID: trainStopStatus.stopStatusID,
arrivingLine,
departureLine,
nextArrivalLine,
prevDepartureLine
};
}
export function getScheduledTrains(
trainList: Train[],
sceneryData: ActiveSceneryAPIData,
stationGeneralInfo: Station['generalInfo']
): ScheduledTrain[] {
const stationName = sceneryData.stationName.toLocaleLowerCase();
stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0));
return trainList.reduce((acc: ScheduledTrain[], train) => {
if (!train.timetableData) return acc;
const timetable = train.timetableData;
if (!timetable.sceneries.includes(sceneryData.stationHash)) return acc;
const stopInfoIndex = timetable.followingStops.findIndex((stop) => {
const stopName = stop.stopNameRAW.toLowerCase();
return (
stationName == stopName ||
(!/(po\.|podg\.)/.test(stopName) && stopName.includes(stationName)) ||
(!/(po\.|podg\.)/.test(stationName) && stationName.includes(stopName)) ||
(stopName.split(', podg.')[0] !== undefined &&
stationName.startsWith(stopName.split(', podg.')[0]))
);
});
const checkpointScheduledTrains: ScheduledTrain[] = [];
if (stopInfoIndex != -1) {
checkpointScheduledTrains.push(
getCheckpointTrain(train, stopInfoIndex, sceneryData.stationName)
);
}
stationGeneralInfo?.checkpoints?.forEach((checkpoint) => {
if (checkpoint.checkpointName.toLocaleLowerCase() == stationName) return;
if (
checkpointScheduledTrains.findIndex(
(cpTrain) =>
cpTrain.checkpointName.toLocaleLowerCase() ==
checkpoint.checkpointName.toLocaleLowerCase()
) != -1
)
return;
const index = timetable.followingStops.findIndex(
(stop) => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase()
);
if (index > -1)
checkpointScheduledTrains.push(getCheckpointTrain(train, index, sceneryData.stationName));
});
acc.push(...checkpointScheduledTrains);
return acc;
}, []) as ScheduledTrain[];
}
export function getStationTrains(
trainList: Train[],
scheduledTrainList: ScheduledTrain[],
region: string,
scenery: ActiveSceneryAPIData
): StationTrain[] {
return trainList
.filter(
(train) =>
train?.region === region && train.online && train.currentStationName === scenery.stationName
)
.map((train) => ({
driverName: train.driverName,
driverId: train.driverId,
trainNo: train.trainNo,
trainId: train.trainId,
stopStatus:
scheduledTrainList.find((st) => st.trainNo === train.trainNo)?.stopStatus || 'no-timetable'
}));
}