-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.js
More file actions
96 lines (81 loc) 路 2.31 KB
/
Copy pathhelpers.js
File metadata and controls
96 lines (81 loc) 路 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Utility functions for extracting and processing TfL journey data
*/
export function extractAlerts(journeyData) {
const alerts = [];
if (journeyData.alerts) {
alerts.push(...journeyData.alerts);
}
// Check for alerts in journey legs
if (journeyData.journeys) {
journeyData.journeys.forEach(journey => {
if (journey.legs) {
journey.legs.forEach(leg => {
if (leg.alerts) {
alerts.push(...leg.alerts);
}
});
}
});
}
return alerts;
}
export function extractStopPoints(journeyData) {
const stopPoints = [];
if (journeyData.stopPoints) {
stopPoints.push(...journeyData.stopPoints);
}
// Extract stop points from journey legs
if (journeyData.journeys) {
journeyData.journeys.forEach(journey => {
if (journey.legs) {
journey.legs.forEach(leg => {
if (leg.departurePoint) {
stopPoints.push(leg.departurePoint);
}
if (leg.arrivalPoint) {
stopPoints.push(leg.arrivalPoint);
}
if (leg.path && leg.path.stopPoints) {
stopPoints.push(...leg.path.stopPoints);
}
});
}
});
}
return stopPoints;
}
export function extractDisruptions(journeyData) {
const disruptions = [];
if (journeyData.disruptions) {
disruptions.push(...journeyData.disruptions);
}
// Check for disruptions in journey legs
if (journeyData.journeys) {
journeyData.journeys.forEach(journey => {
if (journey.legs) {
journey.legs.forEach(leg => {
if (leg.disruptions) {
disruptions.push(...leg.disruptions);
}
});
}
});
}
return disruptions;
}
export function createSummary(journeyData) {
const summary = {
totalJourneys: journeyData.journeys ? journeyData.journeys.length : 0,
totalAlerts: extractAlerts(journeyData).length,
totalDisruptions: extractDisruptions(journeyData).length,
totalStopPoints: extractStopPoints(journeyData).length,
};
if (journeyData.journeys && journeyData.journeys.length > 0) {
const firstJourney = journeyData.journeys[0];
summary.duration = firstJourney.duration;
summary.startDateTime = firstJourney.startDateTime;
summary.arrivalDateTime = firstJourney.arrivalDateTime;
}
return summary;
}