Skip to content

Commit

Permalink
Issue437 (#438)
Browse files Browse the repository at this point in the history
* fix #437

* rename view files so they are called in required order

* update doc for fptwg access models, now with boolean observed column

* commit missed edit

* all views should have simplified wscode column names, remove refresh calls, add draft combined all streams fptwg output
  • Loading branch information
smnorris authored Jan 5, 2024
1 parent feac368 commit d648f78
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 325 deletions.
12 changes: 12 additions & 0 deletions db/views/01_streams_access_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ select
coalesce(ou.obsrvtn_event_upstr, array[]::bigint[]) as obsrvtn_event_upstr,
coalesce(ou.obsrvtn_species_codes_upstr, array[]::text[]) as obsrvtn_species_codes_upstr,
coalesce(od.species_codes_dnstr, array[]::text[]) as species_codes_dnstr,

-- include per-species/species groupings boolean 'observed' accessible columns
case when 'BT' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_bt,
case when 'CH' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_ch,
case when 'CM' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_cm,
case when 'CO' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_co,
case when 'PK' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_pk,
case when 'SK' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_sk,
case when 'ST' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_st,
case when 'WCT' = any(ou.obsrvtn_species_codes_upstr) then true else false end as obsrvtn_upstr_wct,
case when ou.obsrvtn_species_codes_upstr && array['CH','CM','CO','PK','SK'] then true else false end as obsrvtn_upstr_salmon,

cd.crossings_dnstr,
case
when x.aggregated_crossings_id is not null then true
Expand Down
4 changes: 2 additions & 2 deletions db/views/03_crossings_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ select
c.blue_line_key,
c.watershed_key,
c.downstream_route_measure,
c.wscode_ltree,
c.localcode_ltree,
c.wscode_ltree as wscode,
c.localcode_ltree as localcode,
c.watershed_group_code,
c.gnis_stream_name,
c.stream_order,
Expand Down
20 changes: 13 additions & 7 deletions db/views/06_streams_vw.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
drop materialized view if exists bcfishpass.streams_vw;
create materialized view bcfishpass.streams_vw as
drop view if exists bcfishpass.streams_vw;
create view bcfishpass.streams_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand All @@ -10,8 +10,8 @@ select
s.downstream_route_measure,
s.length_metre,
s.waterbody_key,
s.wscode_ltree,
s.localcode_ltree,
s.wscode_ltree as wscode,
s.localcode_ltree as localcode,
s.gnis_name,
s.stream_order,
s.stream_magnitude,
Expand Down Expand Up @@ -39,6 +39,15 @@ select
a.remediated_dnstr_ind,
array_to_string(a.obsrvtn_event_upstr, ';') as obsrvtn_event_upstr,
array_to_string(a.obsrvtn_species_codes_upstr, ';') as obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_bt,
a.obsrvtn_upstr_ch,
a.obsrvtn_upstr_cm,
a.obsrvtn_upstr_co,
a.obsrvtn_upstr_pk,
a.obsrvtn_upstr_sk,
a.obsrvtn_upstr_st,
a.obsrvtn_upstr_wct,
a.obsrvtn_upstr_salmon,
array_to_string(a.species_codes_dnstr, ';') as species_codes_dnstr,
h.spawning_bt as model_spawning_bt,
h.spawning_ch as model_spawning_ch,
Expand Down Expand Up @@ -68,6 +77,3 @@ from bcfishpass.streams s
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id;

create unique index on bcfishpass.streams_vw (segmented_stream_id);
create index on bcfishpass.streams_vw using gist (geom);
24 changes: 4 additions & 20 deletions db/views/streams_bt_vw.sql → db/views/11_streams_bt_vw.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
drop materialized view if exists bcfishpass.streams_bt_vw;
create materialized view bcfishpass.streams_bt_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'BT'
group by segmented_stream_id
)
drop view if exists bcfishpass.streams_bt_vw;

create view bcfishpass.streams_bt_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -46,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_bt,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -55,7 +40,6 @@ select
m.mapping_code_bt as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
24 changes: 4 additions & 20 deletions db/views/streams_ch_vw.sql → db/views/12_streams_ch_vw.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
drop materialized view if exists bcfishpass.streams_ch_vw;
create materialized view bcfishpass.streams_ch_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'CH'
group by segmented_stream_id
)
drop view if exists bcfishpass.streams_ch_vw;

create view bcfishpass.streams_ch_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -46,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_ch,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -55,7 +40,6 @@ select
m.mapping_code_ch as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
24 changes: 3 additions & 21 deletions db/views/streams_cm_vw.sql → db/views/13_streams_cm_vw.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
drop materialized view if exists bcfishpass.streams_cm_vw;
create materialized view bcfishpass.streams_cm_vw as

with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'CM'
group by segmented_stream_id
)
drop view if exists bcfishpass.streams_cm_vw;

create view bcfishpass.streams_cm_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -48,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_cm,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -57,7 +40,6 @@ select
m.mapping_code_cm as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
23 changes: 3 additions & 20 deletions db/views/streams_co_vw.sql → db/views/14_streams_co_vw.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
drop materialized view if exists bcfishpass.streams_co_vw;
drop view if exists bcfishpass.streams_co_vw;

create materialized view bcfishpass.streams_co_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'CO'
group by segmented_stream_id
)
create view bcfishpass.streams_co_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -47,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_co,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -56,7 +40,6 @@ select
m.mapping_code_co as mapping_code,
geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
23 changes: 3 additions & 20 deletions db/views/streams_pk_vw.sql → db/views/15_streams_pk_vw.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
drop materialized view if exists bcfishpass.streams_pk_vw;
drop view if exists bcfishpass.streams_pk_vw;

create materialized view bcfishpass.streams_pk_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'PK'
group by segmented_stream_id
)
create view bcfishpass.streams_pk_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -47,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_pk,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -56,7 +40,6 @@ select
m.mapping_code_pk as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
drop materialized view if exists bcfishpass.streams_salmon_vw;

create materialized view bcfishpass.streams_salmon_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp in ('CH','CM','CO','PK','SK')
group by segmented_stream_id
)
drop view if exists bcfishpass.streams_salmon_vw;

create view bcfishpass.streams_salmon_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -48,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_salmon,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -73,7 +56,6 @@ select
m.mapping_code_salmon as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
23 changes: 3 additions & 20 deletions db/views/streams_sk_vw.sql → db/views/17_streams_sk_vw.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
drop materialized view if exists bcfishpass.streams_sk_vw;
drop view if exists bcfishpass.streams_sk_vw;

create materialized view bcfishpass.streams_sk_vw as
with obs as
(
select
segmented_stream_id,
array_to_string(array_agg(spp), ';') as obsrvtn_species_codes_upstr
from (
select
s.segmented_stream_id,
unnest(o.obsrvtn_species_codes_upstr) as spp
from bcfishpass.streams s
left outer join bcfishpass.streams_upstr_observations o
on s.segmented_stream_id = o.segmented_stream_id
) as f
where spp = 'SK'
group by segmented_stream_id
)
create view bcfishpass.streams_sk_vw as
select
s.segmented_stream_id,
s.linear_feature_id,
Expand Down Expand Up @@ -47,7 +31,7 @@ select
array_to_string(a.barriers_dams_dnstr, ';') as barriers_dams_dnstr,
array_to_string(a.barriers_dams_hydro_dnstr, ';') as barriers_dams_hydro_dnstr,
array_to_string(a.crossings_dnstr, ';') as crossings_dnstr,
o.obsrvtn_species_codes_upstr,
a.obsrvtn_upstr_sk,
a.dam_dnstr_ind,
a.dam_hydro_dnstr_ind,
a.remediated_dnstr_ind,
Expand All @@ -56,7 +40,6 @@ select
m.mapping_code_sk as mapping_code,
s.geom
from bcfishpass.streams s
left outer join obs o on s.segmented_stream_id = o.segmented_stream_id
left outer join bcfishpass.streams_access_vw a on s.segmented_stream_id = a.segmented_stream_id
left outer join bcfishpass.streams_habitat_linear_vw h on s.segmented_stream_id = h.segmented_stream_id
left outer join bcfishpass.streams_mapping_code_vw m on s.segmented_stream_id = m.segmented_stream_id
Expand Down
Loading

0 comments on commit d648f78

Please sign in to comment.