-
Notifications
You must be signed in to change notification settings - Fork 0
/
mostHeadsigns.ts
149 lines (134 loc) · 3.79 KB
/
mostHeadsigns.ts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
export type TimetableEntry = {
time: string;
exceptions: {
id: string;
}[];
};
export type TimetablePeriod = {
period_id: string;
period_name: string;
weekdays: TimetableEntry[];
saturdays: TimetableEntry[];
sundays_holidays: TimetableEntry[];
};
export type Timetable = {
periods: TimetablePeriod[],
exceptions: {
id: string;
label: string;
text: string;
}[];
patternForDisplay: string;
secondaryPatterns: string[];
};
export type Pattern = {
id: string
line_id: string
route_id: string
short_name: string
direction: number
headsign: string
color: string
text_color: string
valid_on: string[]
municipalities: string[]
localities: string[]
facilities: any[]
shape_id: string
path: Path[]
trips: Trip[]
}
export type Path = {
stop: Stop
stop_sequence: number
allow_pickup: boolean
allow_drop_off: boolean
distance_delta: number
}
export type Stop = {
id: string
name: string
short_name: any
tts_name: string
lat: string
lon: string
locality: string
parish_id: string|null
parish_name: string|null
municipality_id: string
municipality_name: string
district_id: string
district_name: string
region_id: string
region_name: string
wheelchair_boarding: any
facilities: Facility[]
lines: string[]
routes: string[]
patterns: string[]
}
export type Trip = {
id: string
calendar_id: string
calendar_description: string
dates: string[]
schedule: Schedule[]
}
export type Schedule = {
stop_id: string
stop_sequence: number
arrival_time: string
arrival_time_operation: string
travel_time: string
}
export enum Facility {
NEAR_HEALTH_CLINIC = 'near_health_clinic',
NEAR_HOSPITAL = 'near_hospital',
NEAR_UNIVERSITY = 'near_university',
NEAR_SCHOOL = 'school',
NEAR_POLICE_STATION = 'near_police_station',
NEAR_FIRE_STATION = 'near_fire_station',
NEAR_SHOPPING = 'shopping',
NEAR_HISTORIC_BUILDING = 'near_historic_building',
NEAR_TRANSIT_OFFICE = 'transit_office',
LIGHT_RAIL = 'light_rail',
SUBWAY = 'subway',
TRAIN = 'train',
BOAT = 'boat',
AIRPORT = 'airport',
BIKE_SHARING = 'bike_sharing',
BIKE_PARKING = 'bike_parking',
CAR_PARKING = 'car_parking',
}
const API_URL = process.env.API_URL || 'http://localhost:5050';
const index:{
updated_at: string;
pairs:string[] // `${line_id}/${direction_id}/${stop_id}`
} = await fetch(`${API_URL}/timetables`).then(res => res.json());
const lines:{[line:string]:string[]} = {}
for (const pair of index.pairs) {
const [line_id, direction_id, stop_id] = pair.split('/');
if (!lines[line_id]) {
lines[line_id] = [];
}
lines[line_id].push(pair);
}
const patternsWithHeadsignCount:[string, number][] = [];
let i = 0;
for (const patterns in lines) {
console.log(`${++i}/${Object.values(lines).length}`)
const patternId = lines[patterns][0]
const timetableRes = await fetch(`${API_URL}/timetables/${patternId}`);
const timetable: Timetable = await timetableRes.json();
const patternURL = `${API_URL}/patterns/${timetable.patternForDisplay}`;
const patternRes = fetch(patternURL).then(patternRes => patternRes.json());
// console.log(timetable)
const secondaryPatternsPromise = Promise.all(timetable.secondaryPatterns.map(patternId => fetch(`${API_URL}/patterns/${patternId}`).then(patternRes => patternRes.json())));
// console.log(patternURL, timetable.secondaryPatterns.map(patternId => `${API_URL}/patterns/${patternId}`));
const [pattern, secondaryPatterns]:[ Pattern, Pattern[] ] = await Promise.all([patternRes, secondaryPatternsPromise]);
const headsigns = [pattern.headsign, ...secondaryPatterns.map(pattern => pattern.headsign)];
const headsignCount = new Set(headsigns).size;
patternsWithHeadsignCount.push([patternId, headsignCount]);
}
patternsWithHeadsignCount.sort((a, b) => b[1] - a[1]);
console.log(patternsWithHeadsignCount);