TimetableAPI-Upgrade #64

Merged
fred.boniface merged 36 commits from TimetableAPI-Upgrade into main 2024-02-11 15:53:17 +00:00
Showing only changes of commit 7657085bc3 - Show all commits

View File

@ -1,36 +1,46 @@
import type {Service, OB_TrainTT_service, OB_Pis_SimpleObject, OB_TrainTT_stopDetail, Stop} from "@owlboard/ts-types" import type {
Service,
OB_TrainTT_service,
OB_Pis_SimpleObject,
OB_TrainTT_stopDetail,
Stop,
} from "@owlboard/ts-types";
import { logger } from "../../logger.utils";
export function formatTimetableDetail(service: Service, pis: OB_Pis_SimpleObject | null): OB_TrainTT_service { export function formatTimetableDetail(
const formattedService: OB_TrainTT_service = { service: Service,
stpIndicator: service.stpIndicator, pis: OB_Pis_SimpleObject | null
operator: service.operator, ): OB_TrainTT_service {
trainUid: service.trainUid, const formattedService: OB_TrainTT_service = {
headcode: service.headcode, stpIndicator: service.stpIndicator,
powerType: service.powerType, operator: service.operator,
planSpeed: convertStringToNumber(service.planSpeed), trainUid: service.trainUid,
scheduleStart: service.scheduleStartDate, headcode: service.headcode,
scheduleEnd: service.scheduleEndDate, powerType: service.powerType,
daysRun: service.daysRun, planSpeed: convertStringToNumber(service.planSpeed),
stops: formatStops(service.stops), scheduleStart: service.scheduleStartDate,
vstp: service.vstp, scheduleEnd: service.scheduleEndDate,
} daysRun: service.daysRun,
stops: formatStops(service.stops),
vstp: service.vstp,
};
if (pis) { if (pis) {
formattedService.pis = pis; formattedService.pis = pis;
} }
return formattedService return formattedService;
} }
function formatStops(stops: Stop[]): OB_TrainTT_stopDetail[] { function formatStops(stops: Stop[]): OB_TrainTT_stopDetail[] {
// Cleanly coerce Stop[] to OB_TrainTT_stopDetail[] // Cleanly coerce Stop[] to OB_TrainTT_stopDetail[]
const formattedStops: OB_TrainTT_stopDetail[] = [] const formattedStops: OB_TrainTT_stopDetail[] = [];
for (const stop of stops) { for (const stop of stops) {
formattedStops.push(formatStopTimes(stop)) formattedStops.push(formatStopTimes(stop));
} }
return formattedStops return formattedStops;
} }
function formatStopTimes(stop: Stop): OB_TrainTT_stopDetail { function formatStopTimes(stop: Stop): OB_TrainTT_stopDetail {
@ -38,7 +48,7 @@ function formatStopTimes(stop: Stop): OB_TrainTT_stopDetail {
let formattedStop: OB_TrainTT_stopDetail = { let formattedStop: OB_TrainTT_stopDetail = {
tiploc: stop.tiploc, tiploc: stop.tiploc,
isPublic: false, isPublic: false,
} };
if (stop.publicArrival) { if (stop.publicArrival) {
formattedStop.publicArrival = stop.publicArrival; formattedStop.publicArrival = stop.publicArrival;
formattedStop.isPublic = true; formattedStop.isPublic = true;
@ -53,14 +63,14 @@ function formatStopTimes(stop: Stop): OB_TrainTT_stopDetail {
if (stop.wttDeparture) { if (stop.wttDeparture) {
formattedStop.wttDeparture = stop.wttDeparture; formattedStop.wttDeparture = stop.wttDeparture;
} }
return formattedStop return formattedStop;
} }
function convertStringToNumber(str: string): number { function convertStringToNumber(str: string): number {
const number = parseFloat(str) const number = parseFloat(str);
if (isNaN(number)) { if (isNaN(number)) {
return 0; return 0;
} else { } else {
return number return number;
} }
} }