mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
filtrowanie statusów; poprawki w statystykach
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export enum DispatcherStatusID {
|
||||
Unknown = 'unknown',
|
||||
Outdated = 'outdated',
|
||||
Unauthorized = 'not-signed',
|
||||
OnlineNoLimit = 'no-limit',
|
||||
Afk = 'brb',
|
||||
Ending = 'ending',
|
||||
NoSpace = 'no-space',
|
||||
Unavailable = 'unavailable',
|
||||
OnlineWithHours = 'online'
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Availability } from './store/storeTypes';
|
||||
import { Availability, OnlineScenery } from './store/storeTypes';
|
||||
import { ScheduledTrain } from './ScheduledTrain';
|
||||
import StationRoutes from './StationRoutes';
|
||||
|
||||
@@ -32,33 +32,5 @@ export default interface Station {
|
||||
}[];
|
||||
};
|
||||
|
||||
onlineInfo?: {
|
||||
hash: string;
|
||||
name: string;
|
||||
region: string;
|
||||
|
||||
maxUsers: number;
|
||||
currentUsers: number;
|
||||
|
||||
spawns: { spawnName: string; spawnLength: number; isElectrified: boolean }[];
|
||||
dispatcherRate: number;
|
||||
dispatcherName: string;
|
||||
dispatcherExp: number;
|
||||
dispatcherId: number;
|
||||
dispatcherIsSupporter: boolean;
|
||||
|
||||
statusTimestamp: number;
|
||||
// statusTimeString: string;
|
||||
statusID: string;
|
||||
|
||||
stationTrains?: {
|
||||
driverName: string;
|
||||
driverId: number;
|
||||
trainNo: number;
|
||||
trainId: string;
|
||||
stopStatus?: string;
|
||||
}[];
|
||||
|
||||
scheduledTrains?: ScheduledTrain[];
|
||||
};
|
||||
onlineInfo?: OnlineScenery;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { DriverStatsAPIData } from '../api/DriverStatsAPIData';
|
||||
import { RollingStockGithubData } from '../github_api/StockInfoGithubData';
|
||||
import Station from '../Station';
|
||||
import { ScheduledTrain } from '../ScheduledTrain';
|
||||
import { DispatcherStatusID } from '../../enums/DispatcherStatus';
|
||||
|
||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||
|
||||
@@ -15,7 +16,7 @@ export interface StoreState {
|
||||
apiData: APIData;
|
||||
rollingStockData?: RollingStockGithubData;
|
||||
|
||||
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: string }[];
|
||||
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: DispatcherStatusID }[];
|
||||
|
||||
sceneryData: any[][];
|
||||
|
||||
@@ -113,8 +114,16 @@ export interface OnlineScenery {
|
||||
dispatcherIsSupporter: boolean;
|
||||
|
||||
statusTimestamp: number;
|
||||
statusID: string;
|
||||
statusID: DispatcherStatusID;
|
||||
|
||||
isOnline: boolean;
|
||||
|
||||
stationTrains?: StationTrain[];
|
||||
scheduledTrains?: ScheduledTrain[];
|
||||
|
||||
scheduledTrainCount: {
|
||||
all: number;
|
||||
confirmed: number;
|
||||
unconfirmed: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { HeadIdsTypes } from '../data/stationHeaderNames';
|
||||
import { DispatcherStatusID } from '../enums/DispatcherStatus';
|
||||
import Filter from '../interfaces/Filter';
|
||||
import Station from '../interfaces/Station';
|
||||
|
||||
@@ -90,11 +91,15 @@ export const filterStations = (station: Station, filters: Filter) => {
|
||||
if (station.onlineInfo) {
|
||||
const { statusID, statusTimestamp } = station.onlineInfo;
|
||||
|
||||
const isEnding = statusID == 'ending' && filters['endingStatus'];
|
||||
const isEnding = statusID == DispatcherStatusID.Ending && filters['endingStatus'];
|
||||
|
||||
const isNotSigned =
|
||||
(statusID == 'not-signed' || statusID == 'unavailable') && filters['unavailableStatus'];
|
||||
|
||||
const isAFK = statusID == 'brb' && filters['afkStatus'];
|
||||
|
||||
const isNoSpace = statusID == 'no-space' && filters['noSpaceStatus'];
|
||||
|
||||
const isOccupied = station.onlineInfo && filters['occupied'];
|
||||
|
||||
const isOnlineInBounds =
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DispatcherStatusID } from '../enums/DispatcherStatus';
|
||||
import { ScheduledTrain, StopStatus } from '../interfaces/ScheduledTrain';
|
||||
import Station from '../interfaces/Station';
|
||||
import Train from '../interfaces/Train';
|
||||
@@ -10,34 +11,39 @@ export const getLocoURL = (locoType: string): string =>
|
||||
locoType.includes('EN') ? locoType + 'rb' : locoType
|
||||
}.png`;
|
||||
|
||||
export const getStatusID = (stationStatus: any): string => {
|
||||
if (!stationStatus) return 'unknown';
|
||||
if (stationStatus == -1) return 'not-signed';
|
||||
export const getStatusID = (
|
||||
stationStatus: any[] | undefined,
|
||||
isSWDROnline: boolean
|
||||
): DispatcherStatusID => {
|
||||
if (isSWDROnline && !stationStatus) return DispatcherStatusID.Unauthorized;
|
||||
if (!stationStatus) return DispatcherStatusID.Unknown;
|
||||
|
||||
// if (stationStatus == -1) return DispatcherStatusID.Unauthorized;
|
||||
|
||||
const statusCode = stationStatus[2];
|
||||
const statusTimestamp = stationStatus[3];
|
||||
|
||||
switch (statusCode) {
|
||||
case 0:
|
||||
if (statusTimestamp - Date.now() > 21000000) return 'no-limit';
|
||||
if (statusTimestamp - Date.now() > 21000000) return DispatcherStatusID.OnlineNoLimit;
|
||||
|
||||
return 'online';
|
||||
return DispatcherStatusID.OnlineWithHours;
|
||||
|
||||
case 1:
|
||||
return 'brb';
|
||||
return DispatcherStatusID.Afk;
|
||||
|
||||
case 2:
|
||||
if (statusTimestamp == 0) return 'ending';
|
||||
if (statusTimestamp == 0) return DispatcherStatusID.Ending;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return 'no-space';
|
||||
return DispatcherStatusID.NoSpace;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 'unavailable';
|
||||
return DispatcherStatusID.Unavailable;
|
||||
};
|
||||
|
||||
export const getStatusTimestamp = (stationStatus: any): number => {
|
||||
@@ -219,12 +225,9 @@ export function getDispatcherStatus(state: StoreState, onlineStationData: Statio
|
||||
(dispatcher) => dispatcher.hash === onlineStationData.stationHash
|
||||
);
|
||||
|
||||
const stationStatus = !dispatchers
|
||||
? undefined
|
||||
: dispatchers.find(
|
||||
(status: string[]) =>
|
||||
status[0] == onlineStationData.stationHash && status[1] == state.region.id
|
||||
) || -1;
|
||||
const stationStatus = dispatchers?.find(
|
||||
(status: string[]) => status[0] == onlineStationData.stationHash && status[1] == state.region.id
|
||||
);
|
||||
|
||||
const statusTimestamp =
|
||||
prevDispatcherStatus && !dispatchers
|
||||
@@ -234,7 +237,7 @@ export function getDispatcherStatus(state: StoreState, onlineStationData: Statio
|
||||
const statusID =
|
||||
prevDispatcherStatus && !dispatchers
|
||||
? prevDispatcherStatus.statusID
|
||||
: getStatusID(stationStatus);
|
||||
: getStatusID(stationStatus, onlineStationData.isOnline === 1);
|
||||
|
||||
return {
|
||||
hash: onlineStationData.stationHash,
|
||||
@@ -263,8 +266,8 @@ export function getScheduledTrains(
|
||||
|
||||
return (
|
||||
stationName == stopName ||
|
||||
(!/(po\.|podg\.)/.test(stationName) && stopName.includes(stationName)) ||
|
||||
(!/(po\.|podg\.)/.test(stopName) && stationName.includes(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]))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user