Skip to content

Commit

Permalink
feat: enable rtt import for standing train
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Sep 22, 2024
1 parent 6aac66a commit 03cf074
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/announcement-data/systems/stations/AmeyPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5882,6 +5882,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
standingTrain: {
name: 'Standing train',
component: CustomAnnouncementPane,
importStateFromRttService: this.standingTrainOptionsFromRtt.bind(this),
defaultState: {
chime: 'three',
thisStationCode: this.STATIONS[0],
Expand Down Expand Up @@ -6426,7 +6427,6 @@ export default class AmeyPhil extends StationAnnouncementSystem {
): ITrainApproachingAnnouncementOptions {
const originLocation = rttService.locations[fromLocationIndex]

const callingPoints = RttUtils.getCallingPoints(rttService, fromLocationIndex)
const destinationLocations = originLocation.destination.filter(d => {
if (!d.crs) {
console.warn('Destination location has no CRS', d)
Expand Down Expand Up @@ -6461,4 +6461,58 @@ export default class AmeyPhil extends StationAnnouncementSystem {
originStationCode: originLocation.origin[0].crs ?? existingOptions.originStationCode,
}
}

/**
* @param rttService RTT service data
* @param fromStation The station from which to interpret data from
* @param existingOptions The existing options to copy other settings from (e.g., chime)
* @returns The options to use for the next train announcement
*/
private standingTrainOptionsFromRtt(
rttService: RttResponse,
fromLocationIndex: number,
existingOptions: IStandingTrainAnnouncementOptions,
): IStandingTrainAnnouncementOptions {
const originLocation = rttService.locations[fromLocationIndex]

const callingPoints = RttUtils.getCallingPoints(rttService, fromLocationIndex)
const destinationLocations = originLocation.destination.filter(d => {
if (!d.crs) {
console.warn('Destination location has no CRS', d)
return false
}
return true
})

const h = originLocation.gbttBookedDeparture!!.substring(0, 2)
const m = originLocation.gbttBookedDeparture!!.substring(2, 4)

let platform = originLocation.platform?.toLowerCase() ?? existingOptions.platform
if (!this.PLATFORMS.includes(platform)) platform = existingOptions.platform

return {
announceShortPlatformsAfterSplit: existingOptions.announceShortPlatformsAfterSplit,
coaches: existingOptions.coaches,
firstClassLocation: existingOptions.firstClassLocation,
mindTheGap: existingOptions.mindTheGap,

thisStationCode: originLocation.crs!,
hour: h === '00' ? '00 - midnight' : h,
min: m === '00' ? '00 - hundred-hours' : m,
isDelayed: RttUtils.getIsDelayedDeparture(rttService, fromLocationIndex),
platform,
callingAt: callingPoints,
vias: [],
notCallingAtStations: RttUtils.getCancelledCallingPoints(rttService, fromLocationIndex),
terminatingStationCode: destinationLocations.map(d => d.crs!!)[0],
toc: this.processTocForLiveTrains(
rttService.atocName,
rttService.atocCode,
originLocation.crs!!,
destinationLocations.map(d => d.crs!!)[0],
false,
rttService.serviceUid,
).toLowerCase(),
}
}
}

0 comments on commit 03cf074

Please sign in to comment.