-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Btdag #381
base: master
Are you sure you want to change the base?
Btdag #381
Changes from 55 commits
c4e3c05
534880f
956bb45
e9b24aa
d6e9700
bed366a
18d2e05
39a0e85
ca10bed
f1ce6b6
8af7e0b
d090db1
87e2bf5
03519de
f89ef79
fffa6a8
eeb6b55
2f9209d
21154c8
df569f0
9f0bbc3
98afd58
9e85abf
4a2fb83
86bbc88
1b4848c
10ae474
2547288
9a942bc
ce236f9
c016dbb
dc5771e
5dad382
59649fe
236282f
2ec625f
871df9f
71849f3
7fa08df
f35e68d
b247cb1
7150d10
b9f6b99
345b23b
fdf7a9a
1ccd39d
468c100
7ddb0b7
3d96a7f
508c0dd
2ffa367
7ce942d
55d5abb
c7dafa4
3fdcb36
ee3a698
d40d1bf
c62a421
0db67ae
5cc7bd1
e0c27bd
4f321c3
9e321fb
4164e77
dc763b6
a7216eb
a74c4dd
bd98f89
e341086
e3647aa
385a7f3
576b29d
afacbcc
c7cf1df
d36423a
f06d4b9
3353e20
40b3ce0
65c4a6f
703dcab
5d4d620
342f739
66a8c7b
9b1a9c8
d034dfd
277996a
5f40600
6b6f826
9c29252
7d1a558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
reader_id,bt_id,past_status,current_status,name,int_id,project_name,geom | ||
135,4033,online,offline,Islington,13469826,RESCU,0101000020E61000007FFB3A70CEE053C01E1B81785DCF4540 | ||
175,5121,online,offline,Spanbridge,13455964,RESCU,0101000020E610000026E4839ECDD453C0137EA99F37DB4540 | ||
186,5122,online,offline,York Mills,13450302,RESCU,0101000020E61000005A8121AB5BD553C0B2BAD573D2DF4540 | ||
173,5124,online,offline,Royal York,13469715,RESCU,0101000020E6100000F5A276BF0AE053C0857B65DEAACF4540 | ||
96,5272,online,offline,CO_OS,13466116,Downtown Expansion,0101000020E610000000790A140CDB53C031CB434BC3D34540 | ||
69,5333,online,offline,Mt Pleasant,13454100,Cycle Tracks,0101000020E610000036C8242367D953C00DAB7823F3DC4540 | ||
89,5610,online,offline,Brenyon,13442793,NULL,0101000020E610000042CD902A8ACD53C0AA29C93A1CE74540 | ||
80,5612,online,offline,HB_QP,30021549,Downtown Expansion,0101000020E6100000AE2E02BE36D953C04AED45B41DD54540 | ||
25,5616,online,offline,Glengrove,13455032,NULL,0101000020E61000000F7F4DD6A8D953C0AD1397E315DC4540 | ||
77,5819,online,offline,BD_HP,13466332,NULL,0101000020E610000007600322C4DD53C00169FF03ACD34540 | ||
140,9018,online,offline,KN_SP,13467505,King Pilot,0101000020E6100000F163CC5D4BD953C07B32FFE89BD24540 | ||
162,9021,online,offline,QU_RO,13468436,King Pilot,0101000020E6100000868F882991DC53C0D673D2FBC6D14540 | ||
103,9039,online,offline,DU_DF,13466894,King Pilot,0101000020E61000004A7A185A9DDB53C0A034D42824D34540 | ||
131,9090,online,offline,HB_BA,13464943,Downtown Expansion,0101000020E610000042FC0D2439DA53C0FA43334FAED44540 | ||
98,9093,online,offline,CO_SP,13465489,Downtown Expansion,0101000020E61000009968EB3B9AD953C0EAEA8EC536D44540 | ||
74,9096,online,offline,BD_DF,13465260,Downtown Expansion,0101000020E6100000886F1750DEDB53C0C3EFA65B76D44540 | ||
183,9097,online,offline,WS_QP,13464585,Downtown Expansion,0101000020E6100000FACCFEE5FFD853C072005878F2D44540 | ||
133,9100,online,offline,HB_SP,13464674,Downtown Expansion,0101000020E61000001C171FB0BCD953C06A25BE24DFD44540 | ||
105,9279,online,offline,DU_JO,13464003,East Expansion,0101000020E610000067B4554964D553C0BF0CC68844D54540 | ||
15,9311,online,offline,C,13468814,NULL,0101000020E61000006C21C84109DB53C074EE76BD34D14540 | ||
87,9312,online,offline,BL_RU,13466753,NULL,0101000020E61000009FE5797077DE53C0DEC7D11C59D34540 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE table mohan.bt_segments_new AS ( | ||
WITH lookup AS ( | ||
SELECT analysis_id, from_id, origin.int_id AS source, to_id, dest.int_id AS target | ||
FROM mohan.new_added_detectors | ||
INNER JOIN mohan.bluetooth_nodes origin ON from_id = origin.bluetooth_id | ||
INNER JOIN mohan.bluetooth_nodes dest ON to_id = dest.bluetooth_id | ||
), | ||
results AS ( | ||
SELECT * | ||
FROM lookup | ||
CROSS JOIN LATERAL pgr_dijkstra('SELECT id, source, target, cost FROM gis.centreline_routing_directional inner join gis.centreline on geo_id = id | ||
where fcode != 207001', source::int, target::int, TRUE) | ||
), | ||
lines as ( | ||
SELECT analysis_id, street, direction, from_street, to_street, edge AS geo_id, geom | ||
FROM results | ||
INNER JOIN gis.centreline ON edge=geo_id | ||
INNER JOIN mohan.new_added_detectors USING (analysis_id) | ||
ORDER BY analysis_id | ||
) | ||
SELECT analysis_id, street, direction, from_street, to_street, | ||
CASE WHEN geom_dir != direction THEN ST_reverse(geom) | ||
ELSE geom | ||
END AS | ||
geom | ||
FROM ( | ||
SELECT analysis_id, street, direction, from_street, to_street, | ||
gis.twochar_direction(gis.direction_from_line(ST_linemerge(ST_union(geom)))) AS geom_dir, | ||
ST_linemerge(ST_union(geom)) AS geom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the table should also have a length column |
||
FROM lines | ||
GROUP BY analysis_id, street, direction, from_street, to_street) a) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- FUNCTION: bluetooth.broken_readers(date) | ||
|
||
CREATE OR REPLACE FUNCTION bluetooth.broken_readers( | ||
insert_dt date) | ||
RETURNS void | ||
LANGUAGE 'plpgsql' | ||
|
||
COST 100 | ||
VOLATILE | ||
AS $BODY$ | ||
begin | ||
with x as ( | ||
select reader_id, last_active_date as active_date, active as active_two_days_before, dt as check_date | ||
from bluetooth.reader_status_history | ||
where dt = insert_dt - 1 and active IS TRUE | ||
) | ||
,y as ( | ||
select * | ||
from bluetooth.reader_status_history | ||
left join x using (reader_id) | ||
where bluetooth.reader_status_history.active IS false and (bluetooth.reader_status_history.dt = insert_dt and last_active_date = insert_dt-2) | ||
|
||
) | ||
INSERT INTO bluetooth.broken_readers_log(reader_id, reader_name, check_date) | ||
select reader_id, name, dt | ||
from y | ||
left join bluetooth.reader_locations using(reader_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
where active_two_days_before IS TRUE and active IS false | ||
; | ||
end; $BODY$; | ||
|
||
ALTER FUNCTION bluetooth.broken_readers(date) | ||
OWNER TO bluetooth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bluetooth is not a group or a role, should be |
||
|
||
GRANT EXECUTE ON FUNCTION bluetooth.broken_readers(date) TO PUBLIC; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment to describe what this function is doing |
||
GRANT EXECUTE ON FUNCTION bluetooth.broken_readers(date) TO bluetooth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be either bt_bot or bt_admin_bot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. going to put it as bt_bot as of now |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
-- FUNCTION: bluetooth.reader_locations_dt_update(date) | ||
|
||
-- DROP FUNCTION bluetooth.reader_locations_dt_update(date); | ||
|
||
CREATE OR REPLACE FUNCTION bluetooth.reader_locations_dt_update( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is included in reader_status_history I think this can be deleted |
||
insert_value date) | ||
RETURNS void | ||
LANGUAGE 'plpgsql' | ||
|
||
COST 100 | ||
VOLATILE | ||
AS $BODY$ | ||
begin | ||
--return query | ||
with x AS | ||
(select DISTINCT(analysis_id), | ||
CASE | ||
WHEN MAX (datetime_bin::date)>= (insert_value - 1) then (insert_value - 1) | ||
ELSE MAX (datetime_bin::date) | ||
END | ||
as last_reported, | ||
CASE | ||
WHEN MAX (datetime_bin::date)>= (insert_value-1) then 'True'::text | ||
else 'False'::text | ||
END | ||
AS route_status | ||
,CASE | ||
WHEN max(aggr_5min.datetime_bin::date) >= (insert_value::date - 1) THEN insert_value::date - 1 | ||
ELSE max(aggr_5min.datetime_bin::date) | ||
END AS dt | ||
from | ||
bluetooth.all_analyses | ||
LEFT JOIN bluetooth.aggr_5min USING (analysis_id) | ||
GROUP BY analysis_id) | ||
, y AS ( | ||
SELECT all_analyses.analysis_id, | ||
(all_analyses.route_points -> 0) ->> 'id'::text AS start_route_point_id, | ||
(all_analyses.route_points -> 0) ->> 'name'::text AS start_detector, | ||
(all_analyses.route_points -> 1) ->> 'id'::text AS end_route_point_id, | ||
(all_analyses.route_points -> 1) ->> 'name'::text AS end_detector | ||
FROM bluetooth.all_analyses | ||
) | ||
, z AS ( | ||
SELECT x.analysis_id, | ||
x.last_reported, | ||
x.route_status, | ||
x.dt, | ||
y.start_route_point_id, | ||
y.start_detector, | ||
y.end_route_point_id, | ||
y.end_detector | ||
FROM x | ||
LEFT JOIN y USING (analysis_id) | ||
) | ||
, b AS ( | ||
SELECT z.analysis_id, | ||
z.start_detector AS detector_name, | ||
z.route_status, | ||
z.last_reported | ||
FROM z | ||
) | ||
, c AS ( | ||
SELECT b.analysis_id, | ||
b.detector_name, | ||
b.route_status, | ||
b.last_reported | ||
FROM b | ||
UNION | ||
SELECT z.analysis_id, | ||
z.end_detector AS detector_name, | ||
z.route_status, | ||
z.last_reported | ||
FROM z | ||
) | ||
, active AS ( | ||
SELECT DISTINCT c.detector_name, | ||
max(c.last_reported) AS max, | ||
c.route_status, | ||
bluetooth.detectors_history_final.reader_id as id | ||
FROM c | ||
LEFT JOIN bluetooth.detectors_history_final ON c.detector_name = bluetooth.detectors_history_final.read_name::text | ||
WHERE c.route_status = 'True'::text | ||
GROUP BY c.route_status, c.detector_name, bluetooth.detectors_history_final.reader_id | ||
), final as ( | ||
SELECT DISTINCT c.detector_name, | ||
max(c.last_reported) AS max, | ||
c.route_status, | ||
bluetooth.detectors_history_final.reader_id | ||
FROM c | ||
LEFT JOIN bluetooth.detectors_history_final ON c.detector_name = bluetooth.detectors_history_final.read_name::text | ||
WHERE c.route_status = 'False'::text AND NOT (c.detector_name IN ( SELECT active.detector_name | ||
FROM active)) | ||
GROUP BY c.route_status, c.detector_name, bluetooth.detectors_history_final.reader_id | ||
UNION | ||
SELECT active.detector_name, | ||
active.max, | ||
active.route_status, | ||
active.id | ||
FROM active) | ||
, date_refresh as( | ||
SELECT max(max) as date_last_received, reader_id | ||
from final | ||
where reader_id in (select reader_id from bluetooth.reader_locations) | ||
group by reader_id | ||
order by reader_id) | ||
|
||
UPDATE bluetooth.reader_locations | ||
set date_last_received = (SELECT date_last_received from date_refresh where date_refresh.reader_id = bluetooth.reader_locations.reader_id) | ||
; | ||
end; $BODY$; | ||
|
||
ALTER FUNCTION bluetooth.reader_locations_dt_update(date) | ||
OWNER TO bluetooth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to bt_admins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is supposed to be introducing the new tables you've created, but this comment doesn't make sense where it is, which is under the
ClassOfDevice
heading.This should be placed under the
Internal Tables
, and maybe move the sections for the individual tables above theClassOfDevice
section