Skip to content

Commit

Permalink
Merge pull request #416 from cymed/add-vw_tww_infiltration_installation
Browse files Browse the repository at this point in the history
Add specialised view for infiltration installation
  • Loading branch information
ponceta authored Sep 23, 2024
2 parents 20aafa9 + 91d6336 commit 34dccd1
Show file tree
Hide file tree
Showing 4 changed files with 853 additions and 24 deletions.
5 changes: 5 additions & 0 deletions datamodel/app/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pirogue import MultipleInheritance, SimpleJoins, SingleInheritance
from triggers.set_defaults_and_triggers import set_defaults_and_triggers
from view.vw_tww_additional_ws import vw_tww_additional_ws
from view.vw_tww_infiltration_installation import vw_tww_infiltration_installation
from view.vw_tww_reach import vw_tww_reach
from view.vw_tww_wastewater_structure import vw_tww_wastewater_structure
from view.vw_wastewater_structure import vw_wastewater_structure
Expand Down Expand Up @@ -41,6 +42,7 @@ def create_app(
drop_schema: Optional[bool] = False,
tww_reach_extra: Optional[Path] = None,
tww_wastewater_structure_extra: Optional[Path] = None,
tww_ii_extra: Optional[Path] = None,
wastewater_structure_extra: Optional[Path] = None,
):
"""
Expand All @@ -50,6 +52,7 @@ def create_app(
:param pg_service: the PostgreSQL service, if not given it will be determined from environment variable in Pirogue
:param tww_reach_extra: YAML file path of the definition of additional columns for vw_tww_reach view
:param tww_wastewater_structure_extra: YAML file path of the definition of additional columns for vw_tww_wastewater_structure_extra view
:param tww_ii_extra: YAML file path of the definition of additional columns for vw_tww_infiltration_installation_extra view
:param wastewater_structure_extra: YAML file path of the definition of additional columns for vw_wastewater_structure_extra view
"""
cwd = Path(__file__).parent.resolve()
Expand All @@ -69,6 +72,7 @@ def create_app(
run_sql_file("functions/14_geometry_functions.sql", pg_service, variables)
run_sql_file("functions/update_catchment_area_totals.sql", pg_service, variables)
run_sql_file("functions/organisation_functions.sql", pg_service, variables)
run_sql_file("functions/meta_functions.sql", pg_service, variables)

# open YAML files
if tww_reach_extra:
Expand Down Expand Up @@ -159,6 +163,7 @@ def create_app(
vw_tww_wastewater_structure(
srid, pg_service=pg_service, extra_definition=tww_wastewater_structure_extra
)
vw_tww_infiltration_installation(srid, pg_service=pg_service, extra_definition=tww_ii_extra)
vw_tww_reach(pg_service=pg_service, extra_definition=tww_reach_extra)
vw_tww_additional_ws(srid, pg_service=pg_service)

Expand Down
20 changes: 20 additions & 0 deletions datamodel/app/functions/meta_functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE OR REPLACE FUNCTION tww_app.check_all_nulls(rec record, prefix varchar(2),ignored_postfix text[] default Array['obj_id','identifier'])
RETURNS bool
AS
$BODY$
DECLARE
rec_jsonb jsonb;
BEGIN

rec_jsonb := (
SELECT jsonb_object_agg(key, to_jsonb(rec)->key)
FROM jsonb_object_keys(to_jsonb(rec)) key
WHERE LEFT(key, 2) = prefix
AND NOT(ltrim(key, prefix||'_') =ANY(ignored_postfix))
);

-- Check if all remaining values are NULL
RETURN jsonb_strip_nulls(rec_jsonb)::text = '{{}}' OR jsonb_strip_nulls(rec_jsonb)::text IS NULL;
END;
$BODY$
LANGUAGE plpgsql;
Loading

0 comments on commit 34dccd1

Please sign in to comment.