-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.sql
339 lines (317 loc) · 10.6 KB
/
scripts.sql
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
-- @block
select st.railway,
st.rail_direction,
st.calendar,
sto.train_type,
sto.train_number,
sto.destination_station,
st.station,
array_agg(
sto.departure_time
order by sto.departure_time
)
from odpt.station_timetable st
left join odpt.train_timetable tt on st.railway = tt.railway
left join odpt.station_timetable_object sto on sto.station_timetable = st.id
where tt.railway is null
group by st.railway,
st.rail_direction,
st.calendar,
sto.train_type,
sto.train_number,
sto.destination_station,
st.station
order by st.railway,
st.rail_direction,
st.calendar,
sto.train_type,
sto.train_number,
sto.destination_station,
st.station;
-- @block
select bp.id,
bp.title,
count(*),
array_agg(distinct bt.busroute_pattern),
array_agg(distinct ksjbp.id)
from odpt.bus_timetable_object bto
left join odpt.bus_timetable bt on bt.id = bto.bus_timetable
left join odpt.busstop_pole bp on bto.busstop_pole = bp.id
left join ksj.busstop ksjbp on ksjbp.busstopname = bp.title
where bp.location is null
group by bp.id;
-- @block
select brp.*,
array_length(array_agg(distinct bt.id), 1) as timetables,
array_length(array_agg(distinct bsp.id), 1) as stops,
array_length(
array_agg(distinct bsp.id) filter (
where bsp.location is null
),
1
) as null_stops
from odpt.busroute_pattern brp
left join odpt.bus_timetable bt on bt.busroute_pattern = brp.id
left join odpt.busstop_pole_order bpo on bpo.busroute_pattern = brp.id
left join odpt.busstop_pole bsp on bpo.busstop_pole = bsp.id
where brp.operator = 'KokusaiKogyoBus'
and bt.id is not null
group by brp.id;
-- @block
select *,
st_asText(location)
from odpt.bussttop_pole_order bpo
left join odpt.busstop_pole bp on bpo.busstop_pole = bp.id
where busroute_pattern in (
'KokusaiKogyoBus.Kawa14-2.52314200.1',
'KokusaiKogyoBus.Kawa15-3.52315301.1'
);
-- @block
select *
from odpt.busroute_pattern bp
where id = 'KeioBus.Chou01Ko.381.2';
-- @block
select *,
st_asText(location)
from odpt.busstop_pole
where title in ('南高麗小学校')
or id = 'KokusaiKogyoBus.HannouEki.5001.10';
-- @block
select *
from odpt.station
where id like 'Chichibu.%';
-- @block
select st.station,
st.calendar,
st.rail_direction,
sto.train,
sto.train_type,
sto.train_number,
sto.destination_station,
sto.train_name,
sto.via_railway,
count(sto.departure_time),
array_agg(sto.departure_time),
array_agg(sto.is_last),
array_agg(sto.is_origin) -- select st.*, sto.*
from odpt.station_timetable st
left join odpt.station_timetable_object sto on sto.station_timetable = st.id
where st.railway = 'Keikyu.Airport'
and st.rail_direction = 'Outbound'
group by st.station,
st.calendar,
st.rail_direction,
sto.train,
sto.train_type,
sto.train_number,
sto.destination_station,
sto.train_name,
sto.via_railway ;
-- @block
select station,
departure_time,
destination_station [1] as destination,
train_type
from odpt.station_timetable st
left join odpt.station_timetable_object sto on sto.station_timetable = st.id
where station like 'Keikyu.Main%'
and rail_direction = 'Inbound'
and departure_time > '18:00'
and destination_station [1] = 'Keisei.Oshiage.Aoto'
and calendar = 'SaturdayHoliday';
-- @block
select *
from odpt.train_timetable
limit 10;
-- @block
select coalesce(tt1.departure_time, tt1.arrival_time) - coalesce(tt0.arrival_time, tt0.departure_time) as time,
tt0.*,
tt1.*
from odpt.train_timetable_object tt0
inner join odpt.train_timetable tt on tt0.train_timetable = tt.id
inner join odpt.train_timetable_object tt1 on tt1.train_timetable = tt.id
and tt1.departure_station = 'Keikyu.Airport.HanedaAirportTerminal3'
where tt0.departure_station = 'Keikyu.Airport.HanedaAirportTerminal1and2'
and tt1.i = tt0.i + 1;
-- @block
delete from odpt.train_timetable_object tt
where tt.train_timetable like '%Generated%';
-- @block
delete from odpt.train_timetable tt
where tt.id like '%Generated%';
-- @block
select *
from odpt.train_timetable_object tt
where tt.train_timetable like '%Generated%';
-- @block
select *
from odpt.train_timetable tt
where tt.id like '%Generated%';
-- @block
select
s.title as name,
s.translations->'en' as name_en,
s.translations->'en' as "name:latin",
s.title as "name:nonlatin",
ST_AsEWKT(ST_Centroid(ST_Union(location::geometry))),
sum(passengers)
from (
select station [1] as station,
(
passenger_survey_object->-1->'odptPassengerJourneys'
)::integer * case
when include_alighting then 1
else 2
end as passengers
from odpt.passenger_survey
) as i
join odpt.station s on s.id = station
group by s.title, s.translations->'en'
--having ST_Area(ST_MinimumBoundingCircle(ST_Union(location::geometry))) < 0.0001
order by sum(passengers);
-- @block
select st.station,
st.rail_direction,
sto.departure_time,
r.ascending_rail_direction
from odpt.station_timetable_object sto
inner join odpt.station_timetable st on st.id = sto.station_timetable
inner join odpt.railway r on r.id = 'Keikyu.Airport'
inner join odpt.station_order so on so.railway = r.id
and so.station = st.station
where sto.destination_station = '{Keikyu.Kurihama.KeikyuKurihama}'
and sto.train_type = 'Keikyu.LimitedExpress'
and st.calendar = 'SaturdayHoliday'
and i = (
select case
when rail_direction = ascending_rail_direction then max(i)
else min(i)
end
from (
select so.i,
st.station,
st.rail_direction,
r.ascending_rail_direction
from odpt.station_timetable_object sto
inner join odpt.station_timetable st on st.id = sto.station_timetable
inner join odpt.railway r on r.id = 'Keikyu.Airport'
inner join odpt.station_order so on so.railway = r.id
and so.station = st.station
where sto.destination_station = '{Keikyu.Kurihama.KeikyuKurihama}'
and sto.train_type = 'Keikyu.LimitedExpress'
and st.calendar = 'SaturdayHoliday'
and st.station LIKE 'Keikyu.Airport%'
) as departures
group by rail_direction,
ascending_rail_direction
);
-- @block
select connecting_railway from odpt.station where id like 'Tokyu.DenEnToshi.Mizonokuchi';
--@block
select *
from odpt.station_timetable_object sto
where
station_timetable like 'Keisei.Main.Aoto.Outbound.SaturdayHoliday'
-- destination_station = '{Keisei.Oshiage.Aoto}'
-- and train_type = 'Keikyu.AirportRapidLimitedExpress'
order by station_timetable, departure_time
-- @block
select *
from odpt.train_timetable_object tto
inner join odpt.train_timetable tt on tto.train_timetable = tt.id
inner join odpt.train_timetable_object ttx on ttx.train_timetable = tt.id
where tto.arrival_station = 'TokyoMetro.Yurakucho.Iidabashi'
and train_type = 'TokyoMetro.S-TRAIN'
-- @block
select st.station,
st.rail_direction,
sto.departure_time
from odpt.station_timetable_object sto
inner join odpt.station_timetable st on st.id = sto.station_timetable
where sto.destination_station = '{Keikyu.Main.KanazawaBunko}'
and sto.train_type = 'Keikyu.LimitedExpress'
and st.calendar = 'Weekday'
and st.station = 'Keikyu.Main.KanazawaHakkei'
and sto.note -> 'ja' = null;
-- @block
select *
from odpt.station_timetable_object sto
inner join odpt.station_timetable st on st.id = sto.station_timetable
where sto.destination_station = '{Seibu.Ikebukuro.Hanno}'
and st.calendar = 'SaturdayHoliday'
and st.station like 'Seibu.Ikebukuro.Hibarigaoka'
-- @block
select tt.id, tto.arrival_time, tto.departure_time, tt.origin_station from odpt.train_timetable_object tto
inner join odpt.train_timetable tt on tt.id = tto.train_timetable
where tt.calendar = 'SaturdayHoliday'
and tto.departure_station = any(
select id from odpt.station s where ST_DistanceSphere(location::geometry, (select location::geometry from odpt.station where id = 'Keisei.Oshiage.Oshiage')) < 200
)
and tt.destination_station = '{Keikyu.Airport.HanedaAirportTerminal1and2}'
and tto.i = 0
and tt.previous_train_timetable is null
and tto.departure_time > '22:09'
order by abs(tto.departure_time - '22:16')
-- @block
select *
FROM odpt.train_timetable_object
where train_timetable in (
'JR-East.Musashino.2753M.Weekday',
'JR-East.ShonanShinjuku.2753M.Weekday',
'JR-East.Musashino.903E.Weekday',
'JR-East.Keiyo.903E.Weekday'
);
-- @block
select tto.*
FROM odpt.train_timetable tt
LEFT JOIN odpt.train_type on tt.train_type = odpt.train_type.id
LEFT JOIN odpt.rail_direction rd on tt.rail_direction = rd.id
LEFT JOIN odpt.railway r on tt.railway = r.id
LEFT JOIN odpt.train_timetable_object tto
on tt.id = tto.train_timetable and (
COALESCE(tto.arrival_station, tto.departure_station) not LIKE (r.id || '.%') or
COALESCE(tto.arrival_station, tto.departure_station) = 'JR-East.Keiyo.NishiFunabashi'
)
where tt.id = 'JR-East.Joban.14M.SaturdayHoliday'
-- @block
select
coalesce(tto.departure_station, tto.arrival_station) as station,
train_type,
destination_station,
calendar,
coalesce(departure_time, arrival_time) as time
from odpt.train_timetable tt
inner join odpt.train_timetable_max_index maxindex on tt.id = maxindex.id
inner join odpt.train_timetable_object tto on tto.train_timetable = tt.id and maxindex.i = tto.i
where destination_station[1] != coalesce(tto.departure_station, tto.arrival_station)
and next_train_timetable is null
order by coalesce(departure_time, arrival_time) desc
-- @block
select *
from odpt.train_timetable tt
inner join odpt.train_timetable_object tto on tto.train_timetable = tt.id
where tt.destination_station = '{SaitamaRailway.SaitamaRailway.UrawaMisono}'
and coalesce(tto.departure_station, tto.arrival_station) = 'Tokyu.DenEnToshi.Shibuya'
and tt.calendar = 'Weekday'
and previous_train_timetable is null
and (origin_station is null or origin_station[1] != 'Tokyu.DenEnToshi.Shibuya')
and coalesce(departure_time, arrival_time) >= '13:00:00'
order by coalesce(departure_time, arrival_time) asc
-- @block
select coalesce(tto.departure_station, tto.arrival_station), tt.railway, count(1)
from odpt.train_timetable tt
inner join odpt.train_timetable_object tto on tto.train_timetable = tt.id
inner join odpt.station s on coalesce(tto.departure_station, tto.arrival_station) = s.id
where tt.railway != s.railway
group by coalesce(tto.departure_station, tto.arrival_station), tt.railway
-- @block
select distinct * from gtfs.shapes ORDER BY shape_id, shape_pt_sequence;
-- @block
select *
from odpt.train_timetable_object tto
inner join odpt.train_timetable tt on tto.train_timetable = tt.id
where departure_station = 'TokyoMetro.Yurakucho.Iidabashi'
and tt.destination_station = '{Seibu.Ikebukuro.Kotesashi}'
order by departure_time
-- @block
select * from odpt.busroute_pattern