mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
nowe pobieranie i przetwarzanie statusów dyżurnych
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
export enum DispatcherStatusID {
|
||||
Unknown = 'unknown',
|
||||
Outdated = 'outdated',
|
||||
Unauthorized = 'not-signed',
|
||||
OnlineNoLimit = 'no-limit',
|
||||
Afk = 'brb',
|
||||
Ending = 'ending',
|
||||
NoSpace = 'no-space',
|
||||
Unavailable = 'unavailable',
|
||||
OnlineWithHours = 'online'
|
||||
}
|
||||
export enum DispatcherStatus {
|
||||
INVALID = -2,
|
||||
UNKNOWN = -1,
|
||||
AFK = 1,
|
||||
ENDING = 2,
|
||||
NO_SPACE = 3,
|
||||
UNAVAILABLE = 4,
|
||||
NOT_LOGGED_IN = 5
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
@@ -7,16 +7,25 @@ import { DriverStatsAPIData } from '../api/DriverStatsAPIData';
|
||||
import { RollingStockGithubData } from '../github_api/StockInfoGithubData';
|
||||
import Station from '../Station';
|
||||
import { ScheduledTrain } from '../ScheduledTrain';
|
||||
import { DispatcherStatusID } from '../../enums/DispatcherStatus';
|
||||
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;
|
||||
|
||||
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: DispatcherStatusID }[];
|
||||
regionOnlineCounters: RegionCounters[];
|
||||
|
||||
lastDispatcherStatuses: { hash: string; statusTimestamp: number; statusID: DispatcherStatus }[];
|
||||
|
||||
sceneryData: any[][];
|
||||
|
||||
@@ -55,6 +64,8 @@ export interface APIData {
|
||||
stations?: StationAPIData[];
|
||||
dispatchers?: string[][];
|
||||
trains?: TrainAPIData[];
|
||||
activeSceneries?: ActiveSceneryAPIData[];
|
||||
|
||||
connectedSocketCount: number;
|
||||
}
|
||||
|
||||
@@ -113,8 +124,7 @@ export interface OnlineScenery {
|
||||
dispatcherExp: number;
|
||||
dispatcherIsSupporter: boolean;
|
||||
|
||||
statusTimestamp: number;
|
||||
statusID: DispatcherStatusID;
|
||||
dispatcherStatus: DispatcherStatus | number;
|
||||
|
||||
isOnline: boolean;
|
||||
|
||||
@@ -125,5 +135,5 @@ export interface OnlineScenery {
|
||||
all: number;
|
||||
confirmed: number;
|
||||
unconfirmed: number;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ function filterTrainList(
|
||||
(searchedDriver.length > 0
|
||||
? train.driverName.toLowerCase().startsWith(searchedDriver.toLowerCase())
|
||||
: true) &&
|
||||
(!train.timetableData ? train.online : train.timetableData) &&
|
||||
isFiltered
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HeadIdsTypes } from '../data/stationHeaderNames';
|
||||
import { DispatcherStatusID } from '../enums/DispatcherStatus';
|
||||
import { DispatcherStatus } from '../enums/DispatcherStatus';
|
||||
import Filter from '../interfaces/Filter';
|
||||
import Station from '../interfaces/Station';
|
||||
|
||||
@@ -19,7 +19,7 @@ export const sortStations = (
|
||||
break;
|
||||
|
||||
case 'status':
|
||||
diff = (a.onlineInfo?.statusTimestamp || 0) - (b.onlineInfo?.statusTimestamp || 0);
|
||||
diff = (a.onlineInfo?.dispatcherStatus || 0) - (b.onlineInfo?.dispatcherStatus || 0);
|
||||
break;
|
||||
|
||||
case 'dispatcher':
|
||||
@@ -81,27 +81,27 @@ export const filterStations = (station: Station, filters: Filter) => {
|
||||
if (!station.onlineInfo && filters['free']) return false;
|
||||
|
||||
if (station.onlineInfo) {
|
||||
const { statusID, statusTimestamp } = station.onlineInfo;
|
||||
const { dispatcherStatus } = station.onlineInfo;
|
||||
|
||||
const isEnding = statusID == DispatcherStatusID.Ending && filters['endingStatus'];
|
||||
const isEnding = dispatcherStatus == DispatcherStatus.ENDING && filters['endingStatus'];
|
||||
|
||||
const isNotSigned =
|
||||
(statusID == 'not-signed' || statusID == 'unavailable') && filters['unavailableStatus'];
|
||||
(dispatcherStatus == DispatcherStatus.NOT_LOGGED_IN ||
|
||||
dispatcherStatus == DispatcherStatus.UNAVAILABLE) &&
|
||||
filters['unavailableStatus'];
|
||||
|
||||
const isAFK = statusID == 'brb' && filters['afkStatus'];
|
||||
const isAFK = dispatcherStatus == DispatcherStatus.AFK && filters['afkStatus'];
|
||||
|
||||
const isNoSpace = statusID == 'no-space' && filters['noSpaceStatus'];
|
||||
const isNoSpace = dispatcherStatus == DispatcherStatus.NO_SPACE && filters['noSpaceStatus'];
|
||||
|
||||
const isOccupied = station.onlineInfo && filters['occupied'];
|
||||
|
||||
const isOnlineInBounds =
|
||||
(filters['onlineFromHours'] < 8 &&
|
||||
statusTimestamp > 0 &&
|
||||
statusTimestamp <= Date.now() + filters['onlineFromHours'] * 3600000) ||
|
||||
(filters['onlineFromHours'] > 0 && statusTimestamp <= 0) ||
|
||||
(filters['onlineFromHours'] == 8 && statusID != 'no-limit');
|
||||
if (isEnding || isNotSigned || isAFK || isNoSpace || isOccupied) return false;
|
||||
|
||||
if (isEnding || isOnlineInBounds || isNotSigned || isAFK || isNoSpace || isOccupied)
|
||||
if (
|
||||
filters['onlineFromHours'] > 0 &&
|
||||
dispatcherStatus <= Date.now() + filters['onlineFromHours'] * 3600000
|
||||
)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,51 +1,15 @@
|
||||
import { DispatcherStatusID } from '../enums/DispatcherStatus';
|
||||
import { ScheduledTrain, StopStatus } from '../interfaces/ScheduledTrain';
|
||||
import Station from '../interfaces/Station';
|
||||
import Train from '../interfaces/Train';
|
||||
import TrainStop from '../interfaces/TrainStop';
|
||||
import StationAPIData from '../interfaces/api/StationAPIData';
|
||||
import { StationTrain, StoreState } from '../interfaces/store/storeTypes';
|
||||
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 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 DispatcherStatusID.OnlineNoLimit;
|
||||
|
||||
return DispatcherStatusID.OnlineWithHours;
|
||||
|
||||
case 1:
|
||||
return DispatcherStatusID.Afk;
|
||||
|
||||
case 2:
|
||||
if (statusTimestamp == 0) return DispatcherStatusID.Ending;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return DispatcherStatusID.NoSpace;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DispatcherStatusID.Unavailable;
|
||||
};
|
||||
|
||||
export const getStatusTimestamp = (stationStatus: any): number => {
|
||||
if (!stationStatus) return -2;
|
||||
|
||||
@@ -218,40 +182,12 @@ export function getCheckpointTrain(
|
||||
};
|
||||
}
|
||||
|
||||
export function getDispatcherStatus(state: StoreState, onlineStationData: StationAPIData) {
|
||||
const { dispatchers } = state.apiData;
|
||||
|
||||
const prevDispatcherStatus = state.lastDispatcherStatuses.find(
|
||||
(dispatcher) => dispatcher.hash === onlineStationData.stationHash
|
||||
);
|
||||
|
||||
const stationStatus = dispatchers?.find(
|
||||
(status: string[]) => status[0] == onlineStationData.stationHash && status[1] == state.region.id
|
||||
);
|
||||
|
||||
const statusTimestamp =
|
||||
prevDispatcherStatus && !dispatchers
|
||||
? prevDispatcherStatus.statusTimestamp
|
||||
: getStatusTimestamp(stationStatus);
|
||||
|
||||
const statusID =
|
||||
prevDispatcherStatus && !dispatchers
|
||||
? prevDispatcherStatus.statusID
|
||||
: getStatusID(stationStatus, onlineStationData.isOnline === 1);
|
||||
|
||||
return {
|
||||
hash: onlineStationData.stationHash,
|
||||
statusID,
|
||||
statusTimestamp
|
||||
};
|
||||
}
|
||||
|
||||
export function getScheduledTrains(
|
||||
trainList: Train[],
|
||||
stationAPIData: StationAPIData,
|
||||
sceneryData: ActiveSceneryAPIData,
|
||||
stationGeneralInfo: Station['generalInfo']
|
||||
): ScheduledTrain[] {
|
||||
const stationName = stationAPIData.stationName.toLocaleLowerCase();
|
||||
const stationName = sceneryData.stationName.toLocaleLowerCase();
|
||||
|
||||
stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0));
|
||||
|
||||
@@ -259,7 +195,7 @@ export function getScheduledTrains(
|
||||
if (!train.timetableData) return acc;
|
||||
|
||||
const timetable = train.timetableData;
|
||||
if (!timetable.sceneries.includes(stationAPIData.stationHash)) return acc;
|
||||
if (!timetable.sceneries.includes(sceneryData.stationHash)) return acc;
|
||||
|
||||
const stopInfoIndex = timetable.followingStops.findIndex((stop) => {
|
||||
const stopName = stop.stopNameRAW.toLowerCase();
|
||||
@@ -277,7 +213,7 @@ export function getScheduledTrains(
|
||||
|
||||
if (stopInfoIndex != -1) {
|
||||
checkpointScheduledTrains.push(
|
||||
getCheckpointTrain(train, stopInfoIndex, stationAPIData.stationName)
|
||||
getCheckpointTrain(train, stopInfoIndex, sceneryData.stationName)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -298,9 +234,7 @@ export function getScheduledTrains(
|
||||
);
|
||||
|
||||
if (index > -1)
|
||||
checkpointScheduledTrains.push(
|
||||
getCheckpointTrain(train, index, stationAPIData.stationName)
|
||||
);
|
||||
checkpointScheduledTrains.push(getCheckpointTrain(train, index, sceneryData.stationName));
|
||||
});
|
||||
|
||||
acc.push(...checkpointScheduledTrains);
|
||||
@@ -312,14 +246,12 @@ export function getStationTrains(
|
||||
trainList: Train[],
|
||||
scheduledTrainList: ScheduledTrain[],
|
||||
region: string,
|
||||
apiStation: StationAPIData
|
||||
scenery: ActiveSceneryAPIData
|
||||
): StationTrain[] {
|
||||
return trainList
|
||||
.filter(
|
||||
(train) =>
|
||||
train?.region === region &&
|
||||
train.online &&
|
||||
train.currentStationName === apiStation.stationName
|
||||
train?.region === region && train.online && train.currentStationName === scenery.stationName
|
||||
)
|
||||
.map((train) => ({
|
||||
driverName: train.driverName,
|
||||
|
||||
Reference in New Issue
Block a user