Skip to content

Commit

Permalink
#42 Fixed avg spd calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jovenc committed Jan 21, 2020
1 parent 20ce94d commit e4a48df
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions congestion_data_aggregation/create-table-metrics_test.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
--Using all data
CREATE TABLE congestion.metrics_test AS

SELECT segment_id,
time_bin,
SELECT *,
avg_spd / baseline_spd AS tti,
(pct95_tt - avg_tt)/avg_tt AS bi

FROM (
SELECT a.segment_id,
a.datetime_bin::time AS time_bin,
COUNT(datetime_bin) AS num_bins,
b.seg_length,
AVG(a.segment_tt_avg_all) AS avg_tt,
PERCENTILE_CONT (0.95) WITHIN GROUP (ORDER BY a.segment_tt_avg_all ASC) AS pct95_tt,
b.seg_length / AVG(a.segment_tt_avg_all) AS avg_spd,
b.seg_length / AVG(a.segment_tt_avg_all) * 3.6 AS avg_spd,
b.spd_baseline_10pct_all AS baseline_spd
FROM congestion.tt_segments_30min_test a
LEFT JOIN congestion.tt_segments_baseline_test b
USING (segment_id)
WHERE a.segment_tt_avg_all IS NOT NULL
GROUP BY segment_id, datetime_bin::time, b.seg_length, b.spd_baseline_10pct_all
ORDER BY segment_id, datetime_bin::time
) abc
) abc

0 comments on commit e4a48df

Please sign in to comment.