Skip to content

Commit

Permalink
Summarize all SVC types as daily totals per segment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Feb 14, 2025
1 parent 6995363 commit 42044d1
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions volumes/short_term_counting_program/svc_daily_totals.sql
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

Check notice on line 30 in volumes/short_term_counting_program/svc_daily_totals.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT01: Unnecessary trailing whitespace.
UNION

Check notice on line 32 in volumes/short_term_counting_program/svc_daily_totals.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT01: Unnecessary trailing whitespace.
-- 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,

Check failure on line 76 in volumes/short_term_counting_program/svc_daily_totals.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

RF02: Unqualified reference 'count_date' found in select with more than one referenced table/view.
centreline_id,
geom AS centreline_geom,

Check failure on line 78 in volumes/short_term_counting_program/svc_daily_totals.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

RF02: Unqualified reference 'geom' found in select with more than one referenced table/view.
daily_volume

Check failure on line 79 in volumes/short_term_counting_program/svc_daily_totals.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

RF02: Unqualified reference 'daily_volume' found in select with more than one referenced table/view.
FROM daily_totals
JOIN traffic.svc_metadata USING (study_id)
JOIN gis_core.centreline_latest USING (centreline_id);

0 comments on commit 42044d1

Please sign in to comment.