Skip to content

Commit

Permalink
feat: implement handling for multiple activity codes properly
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jun 6, 2024
1 parent 050ba21 commit c8e9a7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions functions/api/get-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface TimingLocation {
lateness: any
associations: Association[] | null
adhocAlerts: any
activities?: string
activities?: string[]
}

export enum AssociationCategory {
Expand Down Expand Up @@ -284,9 +284,14 @@ async function processService(service: TrainService): Promise<void> {
}
}

location.activities = serviceData?.locations.find(l => {
const activities = serviceData?.locations.find(l => {
return l.tiploc === location.tiploc && (l.sta === location.sta || l.std === location.std)
})?.activities
})?.activities as string | undefined

// Split into array with groups of two chars
if (activities) {
location.activities = (activities?.match(/.{2}/g) || []).map(a => a.trim())
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/AmeyLiveTrainAnnouncements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getCallingPoints(
if (s.isCancelled || s.isOperational || s.isPass) return false
if (!stations.includes(s.crs)) return false
// Ignore pick-up only
if (s.activities === 'U') return false
if (s.activities?.includes('U')) return false
return true
})

Expand Down Expand Up @@ -94,7 +94,7 @@ function getCallingPoints(
crsCode: getStation(p),
name: '',
randomId: '',
requestStop: p.activities === 'R',
requestStop: p.activities?.includes('R'),
}

p.associations
Expand All @@ -111,7 +111,7 @@ function getCallingPoints(
if (!stations.includes(s.crs)) return false
return true
})
.map(l => ({ crsCode: l.crs!!, name: l.locationName, randomId: '', requestStop: p.activities === 'R' }))
.map(l => ({ crsCode: l.crs!!, name: l.locationName, randomId: '', requestStop: p.activities?.includes('R') }))
})

if (i === callingPoints.length - 1 && p.associations?.some(a => a.category === AssociationCategory.LinkedTo && a.trainid === '0B00')) {
Expand Down Expand Up @@ -141,7 +141,7 @@ function getCallingPoints(
crsCode: getStation(p),
name: '',
randomId: '',
requestStop: p.activities === 'R',
requestStop: p.activities?.includes('R'),
}

if (p.associations?.some(a => a.category === AssociationCategory.LinkedTo && a.trainid !== '0B00')) {
Expand Down Expand Up @@ -174,7 +174,7 @@ function getCallingPoints(
crsCode: getStation(p),
name: '',
randomId: '',
requestStop: p.activities === 'R',
requestStop: p.activities?.includes('R'),
}
})
.filter(Boolean) as CallingAtPoint[]
Expand Down

0 comments on commit c8e9a7e

Please sign in to comment.