Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Sep 22, 2024
2 parents 2b5521f + 03cf074 commit a343484
Showing 1 changed file with 108 additions and 1 deletion.
109 changes: 108 additions & 1 deletion src/announcement-data/systems/stations/AmeyPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5770,6 +5770,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
approachingTrain: {
name: 'Approaching train',
component: CustomAnnouncementPane,
importStateFromRttService: this.approachingTrainOptionsFromRtt.bind(this),
defaultState: {
chime: 'three',
platform: this.PLATFORMS[1],
Expand Down Expand Up @@ -5881,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 @@ -6384,16 +6386,121 @@ export default class AmeyPhil extends StationAnnouncementSystem {
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 {
chime: existingOptions.chime,
announceShortPlatformsAfterSplit: existingOptions.announceShortPlatformsAfterSplit,
coaches: existingOptions.coaches,
firstClassLocation: existingOptions.firstClassLocation,

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(),
}
}

/**
* @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 approachingTrainOptionsFromRtt(
rttService: RttResponse,
fromLocationIndex: number,
existingOptions: ITrainApproachingAnnouncementOptions,
): ITrainApproachingAnnouncementOptions {
const originLocation = rttService.locations[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 {
chime: existingOptions.chime,

hour: h === '00' ? '00 - midnight' : h,
min: m === '00' ? '00 - hundred-hours' : m,
isDelayed: RttUtils.getIsDelayedDeparture(rttService, fromLocationIndex),
platform,
vias: [],
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(),
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: originLocation.platform || existingOptions.platform,
platform,
callingAt: callingPoints,
vias: [],
notCallingAtStations: RttUtils.getCancelledCallingPoints(rttService, fromLocationIndex),
Expand Down

0 comments on commit a343484

Please sign in to comment.