-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summarize all SVC types as daily totals per segment
- Loading branch information
1 parent
6995363
commit 42044d1
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
CREATE OR REPLACE VIEW traffic.svc_daily_totals AS | ||
|
||
WITH daily_totals AS ( | ||
-- speed studies | ||
SELECT | ||
study_id, | ||
count_date, | ||
SUM( | ||
vol_1_19_kph | ||
+ vol_20_25_kph | ||
+ vol_26_30_kph | ||
+ vol_31_35_kph | ||
+ vol_36_40_kph | ||
+ vol_41_45_kph | ||
+ vol_46_50_kph | ||
+ vol_51_55_kph | ||
+ vol_56_60_kph | ||
+ vol_61_65_kph | ||
+ vol_66_70_kph | ||
+ vol_71_75_kph | ||
+ vol_76_80_kph | ||
+ vol_81_160_kph | ||
) AS daily_volume | ||
FROM traffic.svc_study_speed | ||
WHERE count_date >= '2019-01-01' | ||
GROUP BY | ||
study_id, | ||
count_date | ||
HAVING COUNT(*) = 2 * 4 * 24 | ||
|
||
UNION | ||
|
||
-- volume studies | ||
SELECT | ||
study_id, | ||
count_date, | ||
SUM(volume) AS daily_volume | ||
FROM traffic.svc_study_volume | ||
WHERE count_date >= '2019-01-01' | ||
GROUP BY | ||
study_id, | ||
count_date | ||
HAVING COUNT(*) = 2 * 4 * 24 | ||
|
||
UNION | ||
|
||
-- classification studies | ||
SELECT | ||
study_id, | ||
count_date, | ||
SUM( | ||
-- check that these are mutually exclusive | ||
motorcycle | ||
+ cars | ||
+ "2a_4t" | ||
+ buses | ||
+ "2a_su" | ||
+ "3a_su" | ||
+ "4a_su" | ||
+ "4a_st" | ||
+ "5a_st" | ||
+ "6a_st" | ||
+ "5a_mt" | ||
+ "6a_mt" | ||
) AS daily_volume | ||
FROM traffic.svc_study_class | ||
WHERE count_date >= '2019-01-01' | ||
GROUP BY | ||
study_id, | ||
count_date | ||
HAVING COUNT(*) = 2 * 4 * 24 | ||
) | ||
|
||
SELECT | ||
study_id, | ||
count_date, | ||
centreline_id, | ||
geom AS centreline_geom, | ||
daily_volume | ||
FROM daily_totals | ||
JOIN traffic.svc_metadata USING (study_id) | ||
JOIN gis_core.centreline_latest USING (centreline_id); |