Skip to content

Commit

Permalink
handle nulls correctly in fptwg access model and use CARDINALITY quer…
Browse files Browse the repository at this point in the history
…y for access status 😲
  • Loading branch information
smnorris committed Jan 5, 2024
1 parent da81d41 commit 4c7f28e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions db/views/20_freshwater_fish_habitat_accessibility_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ select
s.localcode_ltree as localcode,
s.feature_code,
case
when a.barriers_ch_cm_co_pk_sk_dnstr = array[]::text[] and a.obsrvtn_upstr_salmon is true then 'OBSERVED'
when a.barriers_ch_cm_co_pk_sk_dnstr = array[]::text[] and a.obsrvtn_upstr_salmon is false then 'INFERRED'
when a.barriers_ch_cm_co_pk_sk_dnstr != array[]::text[] then 'NATURAL_BARRIER'
when cardinality(a.barriers_ch_cm_co_pk_sk_dnstr) = 0 and a.obsrvtn_upstr_salmon is true then 'OBSERVED'
when cardinality(a.barriers_ch_cm_co_pk_sk_dnstr) = 0 and a.obsrvtn_upstr_salmon is false then 'INFERRED'
when cardinality(a.barriers_ch_cm_co_pk_sk_dnstr) > 0 then 'NATURAL_BARRIER'
else NULL
end as model_access_salmon,
case
when a.barriers_st_dnstr = array[]::text[] and a.obsrvtn_upstr_st is true then 'OBSERVED'
when a.barriers_st_dnstr = array[]::text[] and a.obsrvtn_upstr_st is false then 'INFERRED'
when a.barriers_st_dnstr != array[]::text[] then 'NATURAL_BARRIER'
when cardinality(a.barriers_st_dnstr) = 0 and a.obsrvtn_upstr_st is true then 'OBSERVED'
when cardinality(a.barriers_st_dnstr) = 0 and a.obsrvtn_upstr_st is false then 'INFERRED'
when cardinality(a.barriers_st_dnstr) > 0 then 'NATURAL_BARRIER'
else NULL
end as model_access_steelhead,
array_to_string(a.barriers_ch_cm_co_pk_sk_dnstr, ';') as barriers_ch_cm_co_pk_sk_dnstr,
array_to_string(a.barriers_st_dnstr, ';') as barriers_st_dnstr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ column,description
``wscode``,A truncated version of the BC FWA fwa_watershed_code (trailing zeros removed and '-' replaced with '.'
``localcode``,A truncated version of the BC FWA local_watershed_code (trailing zeros removed and '-' replaced with '.'
``feature_code``,"A value based on the Canadian Council of Surveys and Mapping's (CCSM) system for classification of geographic features."
``model_access_salmon``,"Salmon access model result code. Values are 'OBSERVED'; 'INFERRED'; 'NATURAL_BARRIER'. NULL indicates species is not present in watershed group"
``model_access_steelhead``,"Steelhead access model result code. Values are 'OBSERVED'; 'INFERRED'; 'NATURAL_BARRIER'. NULL indicates species is not present in watershed group"
``barriers_ch_cm_co_pk_sk_dnstr``,"IDs of downstream natural barriers to salmon (see `barriers_salmon` table"
``model_access_salmon``,"Salmon access model result code. Values are 'OBSERVED'; 'INFERRED'; 'NATURAL_BARRIER'. NULL indicates species is not documented as present in watershed group"
``model_access_steelhead``,"Steelhead access model result code. Values are 'OBSERVED'; 'INFERRED'; 'NATURAL_BARRIER'. NULL indicates species is not documented as present in watershed group"
``barriers_ch_cm_co_pk_sk_dnstr``,"IDs of downstream natural barriers to salmon (see `barriers_salmon` table)"
``barriers_st_dnstr``,"IDs of downstream natural barriers to steelhead (see `barriers_steelhead` table)"
``barriers_anthropogenic_dnstr``,IDs of anthropogenic barriers downstream
``barriers_pscis_dnstr``,IDs of assessed PSCIS barriers downstream
Expand Down

0 comments on commit 4c7f28e

Please sign in to comment.