From 56f93de281c2a4ebd3fc34cd4d9e72f60e9ea235 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 10:08:38 +0100 Subject: [PATCH 01/11] Refactor discharge coefficient case statements Updated discharge coefficient cases to check for NULL values before assignment. --- .../app/view/swmm_views/09_vw_swmm_subcatchments.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql index b2e7c2227..152e534aa 100644 --- a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql +++ b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql @@ -20,10 +20,10 @@ SELECT ELSE (ca.surface_area::numeric)::double precision END AS Area, CASE - WHEN state = 'rw_current' then discharge_coefficient_rw_current - WHEN state = 'rw_planned' then discharge_coefficient_rw_planned - WHEN state = 'ww_current' then discharge_coefficient_ww_current - WHEN state = 'ww_planned' then discharge_coefficient_ww_planned + WHEN state = 'rw_current' AND discharge_coefficient_rw_current IS NOT NULL then discharge_coefficient_rw_current + WHEN state = 'rw_planned' AND discharge_coefficient_rw_planned IS NOT NULL then discharge_coefficient_rw_planned + WHEN state = 'ww_current' AND discharge_coefficient_ww_current IS NOT NULL then discharge_coefficient_ww_current + WHEN state = 'ww_planned' AND discharge_coefficient_ww_planned IS NOT NULL then discharge_coefficient_ww_planned ELSE 0 END as percImperv, -- take from catchment_area instead of default value CASE From 7c640f40360785c046d361a4c3c9dc7c28928719 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:42:05 +0100 Subject: [PATCH 02/11] Replace NULL with 0.0 for depth and area fields From https://github.com/QGEP/datamodel/pull/232/commits --- .../view/swmm_views/02_vw_swmm_junctions.sql | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/datamodel/app/view/swmm_views/02_vw_swmm_junctions.sql b/datamodel/app/view/swmm_views/02_vw_swmm_junctions.sql index 14befc540..26dc794be 100644 --- a/datamodel/app/view/swmm_views/02_vw_swmm_junctions.sql +++ b/datamodel/app/view/swmm_views/02_vw_swmm_junctions.sql @@ -8,9 +8,9 @@ SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, (co.level-wn.bottom_level) as MaxDepth, - NULL::float as InitDepth, - NULL::float as SurchargeDepth, - NULL::float as PondedArea, + 0.0::float as InitDepth, + 0.0::float as SurchargeDepth, + 0.0::float as PondedArea, ws.identifier::text as description, CONCAT_WS(',', 'manhole', mf.value_en) as tag, wn.situation3d_geometry as geom, @@ -41,9 +41,9 @@ SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, (co.level-wn.bottom_level) as MaxDepth, - NULL::float as InitDepth, - NULL::float as SurchargeDepth, - NULL::float as PondedArea, + 0.0::float as InitDepth, + 0.0::float as SurchargeDepth, + 0.0::float as PondedArea, ws.identifier::text as description, CONCAT_WS(',','special_structure', ss_fu.value_en) as tag, wn.situation3d_geometry as geom, @@ -106,9 +106,9 @@ SELECT coalesce(from_wn.obj_id, concat('from_node@',re.obj_id)) as Name, coalesce(from_wn.bottom_level, 0) as InvertElev, 0 as MaxDepth, - NULL::float as InitDepth, - NULL::float as SurchargeDepth, - NULL::float as PondedArea, + 0.0::float as InitDepth, + 0.0::float as SurchargeDepth, + 0.0::float as PondedArea, coalesce(from_wn.obj_id, concat('from_node@',re.obj_id)) as description, 'junction without structure' as tag, coalesce(from_wn.situation3d_geometry, ST_StartPoint(re.progression3d_geometry)) as geom, @@ -142,9 +142,9 @@ SELECT coalesce(to_wn.obj_id, concat('to_node@',re.obj_id)) as Name, coalesce(to_wn.bottom_level, 0) as InvertElev, 0 as MaxDepth, - NULL::float as InitDepth, - NULL::float as SurchargeDepth, - NULL::float as PondedArea, + 0.0::float as InitDepth, + 0.0::float as SurchargeDepth, + 0.0::float as PondedArea, coalesce(to_wn.obj_id, concat('to_node@',re.obj_id)) as description, 'junction without structure' as tag, coalesce(to_wn.situation3d_geometry, ST_EndPoint(re.progression3d_geometry)) as geom, From 22b4fa0120119e7f4c33fc0856ac89698491407c Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:44:19 +0100 Subject: [PATCH 03/11] Set default values for Geom2 and Culvert to 0 Changed default values from NULL to 0 for Geom2 and Culvert. From https://github.com/QGEP/datamodel/pull/232/commits --- datamodel/app/view/swmm_views/23_vw_swmm_xsections.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datamodel/app/view/swmm_views/23_vw_swmm_xsections.sql b/datamodel/app/view/swmm_views/23_vw_swmm_xsections.sql index 0a53c3326..fabb9aff5 100644 --- a/datamodel/app/view/swmm_views/23_vw_swmm_xsections.sql +++ b/datamodel/app/view/swmm_views/23_vw_swmm_xsections.sql @@ -29,15 +29,15 @@ SELECT DISTINCT ELSE re.clear_height/1000::float/pp.height_width_ratio END WHEN pp.height_width_ratio IS NULL THEN 0.002 --ROMA: TODO default value for width to be set - ELSE 0.002 --ROMA: TODO default value for width to be set + ELSE 0.002 --TODO default value for width to be set END - ELSE NULL + ELSE 0 -- default set to 0 instead of NULL END as Geom2, --Geom3 = code -> used only for arch profile, but this code value is nowhere to be set in the TWW model 0 as Geom3, 0 as Geom4, 1 as Barrels, - NULL as Culvert, + 0 as Culvert, -- default set to 0 instead of NULL CASE WHEN ws_st.vsacode IN (7959, 6529, 6526) THEN 'planned' ELSE 'current' From 16dfd99d856a7e5a90403904d8db0849fc54bc35 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:47:41 +0100 Subject: [PATCH 04/11] Change outfall Type and StageData logic in SQL view From https://github.com/QGEP/datamodel/pull/232/commits --- .../view/swmm_views/08_vw_swmm_outfalls.sql | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql index 8267fe714..21efaaa48 100644 --- a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql +++ b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql @@ -6,10 +6,16 @@ CREATE OR REPLACE VIEW tww_app.swmm_vw_outfalls AS SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, - 'FREE'::varchar as Type, - NULL as StageData, + CASE + WHEN waterlevel_hydraulic NOT IS NULL THEN 'FIXED' + ELSE 'FREE' + END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations + CASE + WHEN waterlevel_hydraulic NOT IS NULL THEN waterlevel_hydraulic + ELSE 0 + END as StageData, 'NO'::varchar as tide_gate, - NULL::varchar as RouteTo, + '0'::varchar as RouteTo, ws.identifier as description, dp.obj_id::varchar as tag, wn.situation3d_geometry as geom, @@ -36,10 +42,16 @@ UNION SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, - 'FREE'::varchar as Type, - NULL as StageData, + CASE + WHEN waterlevel_hydraulic NOT IS NULL THEN 'FIXED' + ELSE 'FREE' + END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations + CASE + WHEN waterlevel_hydraulic NOT IS NULL THEN waterlevel_hydraulic + ELSE 0 + END as StageData, 'NO'::varchar as tide_gate, - NULL::varchar as RouteTo, + '0'::varchar as RouteTo, ws.identifier as description, ii.obj_id::varchar as tag, wn.situation3d_geometry as geom, From cab562d216aa3df1c04bace902cbeee30a513801 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:49:12 +0100 Subject: [PATCH 05/11] Enhance view with detailed comments on raingage fields Updated the view to include detailed comments for each column, explaining the format, interval, SCF, and source of the rainfall data. From https://github.com/QGEP/datamodel/pull/232/commits --- datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql b/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql index 62cb970a6..5cd411792 100644 --- a/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql +++ b/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql @@ -2,10 +2,10 @@ CREATE OR REPLACE VIEW tww_app.swmm_vw_raingages AS SELECT ('raingage@' , replace(ca.obj_id, ' ', '_'), '_', ca.state)::varchar as Name, - 'INTENSITY'::varchar as Format, - '0:15'::varchar as Interval, - '1.0'::varchar as SCF, - 'TIMESERIES default_tww_raingage_timeserie'::varchar as Source, + 'INTENSITY'::varchar as Format, -- Format in which the rain data are supplied: INTENSITY: each rainfall value is an average rate in inches/hour (or mm/hour) over the recording interval. VOLUME: each rainfall value is the volume of rain that fell in the recording interval (in inches or millimeters). CUMULATIVE: each rainfall value represents the cumulative rainfall that has occurred since the start of the last series of non-zero values (in inches or millimeters). + '0:15'::varchar as Interval, -- Recording time interval between gage readings in decimal hours or hours:minutes format. + '1.0'::varchar as SCF, -- Snow Catch Factor Factor that corrects gage readings for snowfall. + 'TIMESERIES default_tww_raingage_timeserie'::varchar as Source, -- Source of rainfall data; either TIMESERIES for user-defined time series data or FILE for an external data file. st_centroid(perimeter_geometry)::geometry(Point, {SRID}) as geom, state, CASE From 60417dc952b6c03350d8cb9432b579161269f082 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:50:06 +0100 Subject: [PATCH 06/11] Enhance comment for Source field in raingages view Updated the comment for the Source field to include additional information from SWMM Documentation. https://github.com/QGEP/datamodel/pull/232/commits --- datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql b/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql index 5cd411792..b701b7d0e 100644 --- a/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql +++ b/datamodel/app/view/swmm_views/12_vw_swmm_raingages.sql @@ -5,7 +5,7 @@ SELECT 'INTENSITY'::varchar as Format, -- Format in which the rain data are supplied: INTENSITY: each rainfall value is an average rate in inches/hour (or mm/hour) over the recording interval. VOLUME: each rainfall value is the volume of rain that fell in the recording interval (in inches or millimeters). CUMULATIVE: each rainfall value represents the cumulative rainfall that has occurred since the start of the last series of non-zero values (in inches or millimeters). '0:15'::varchar as Interval, -- Recording time interval between gage readings in decimal hours or hours:minutes format. '1.0'::varchar as SCF, -- Snow Catch Factor Factor that corrects gage readings for snowfall. - 'TIMESERIES default_tww_raingage_timeserie'::varchar as Source, -- Source of rainfall data; either TIMESERIES for user-defined time series data or FILE for an external data file. + 'TIMESERIES default_tww_raingage_timeserie'::varchar as Source, -- Source of rainfall data; either TIMESERIES for user-defined time series data or FILE for an external data file. see Rain Gage Properties of SWMM Documentation for furhter information. st_centroid(perimeter_geometry)::geometry(Point, {SRID}) as geom, state, CASE From 7271b50032835b83c08158d473d1fcca68ed3017 Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 11:59:02 +0100 Subject: [PATCH 07/11] Update 09_vw_swmm_subcatchments.sql https://github.com/QGEP/datamodel/pull/232/commits --- datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql index 152e534aa..626346ed7 100644 --- a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql +++ b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql @@ -41,7 +41,7 @@ SELECT END as Width, -- Width of overland flow path estimation 0.5 as percSlope, -- default value 0 as CurbLen, -- default value - NULL::varchar as SnowPack, -- default value + 0::varchar as SnowPack, -- default value CASE WHEN fk_wastewater_networkelement_ww_current is not null THEN From f09ea200fbdc823a24d77e14e1d0aab0ab03244a Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 12:16:02 +0100 Subject: [PATCH 08/11] Update 09_vw_swmm_subcatchments.sql --- datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql index 626346ed7..b460b6050 100644 --- a/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql +++ b/datamodel/app/view/swmm_views/09_vw_swmm_subcatchments.sql @@ -41,7 +41,7 @@ SELECT END as Width, -- Width of overland flow path estimation 0.5 as percSlope, -- default value 0 as CurbLen, -- default value - 0::varchar as SnowPack, -- default value + 'default_snow_pack'::varchar as SnowPack, -- default value CASE WHEN fk_wastewater_networkelement_ww_current is not null THEN From 1b3015c05fb2d26f5c51b063a2f667364b30909e Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 13:51:18 +0100 Subject: [PATCH 09/11] Update 08_vw_swmm_outfalls.sql Typo from QGEP commit --- datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql index 21efaaa48..880330144 100644 --- a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql +++ b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql @@ -43,11 +43,11 @@ SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, CASE - WHEN waterlevel_hydraulic NOT IS NULL THEN 'FIXED' + WHEN waterlevel_hydraulic IS NOT NULL THEN 'FIXED' ELSE 'FREE' END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations CASE - WHEN waterlevel_hydraulic NOT IS NULL THEN waterlevel_hydraulic + WHEN waterlevel_hydraulic IS NOT NULL THEN waterlevel_hydraulic ELSE 0 END as StageData, 'NO'::varchar as tide_gate, From ccdacf5570e3665cea17ba285339aeeb91020a5a Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 13:52:22 +0100 Subject: [PATCH 10/11] Update 08_vw_swmm_outfalls.sql --- datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql index 880330144..d03fbd9cc 100644 --- a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql +++ b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql @@ -7,11 +7,11 @@ SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, CASE - WHEN waterlevel_hydraulic NOT IS NULL THEN 'FIXED' + WHEN waterlevel_hydraulic IS NOT NULL THEN 'FIXED' ELSE 'FREE' END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations CASE - WHEN waterlevel_hydraulic NOT IS NULL THEN waterlevel_hydraulic + WHEN waterlevel_hydraulic IS NOT NULL THEN waterlevel_hydraulic ELSE 0 END as StageData, 'NO'::varchar as tide_gate, From 93c2af6b103f93dcefbad264c316abf93acf111d Mon Sep 17 00:00:00 2001 From: tproduit Date: Tue, 11 Nov 2025 14:22:01 +0100 Subject: [PATCH 11/11] Update 08_vw_swmm_outfalls.sql waterlevel_hydraulic is not available for infiltration installation --- .../app/view/swmm_views/08_vw_swmm_outfalls.sql | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql index d03fbd9cc..30a014edc 100644 --- a/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql +++ b/datamodel/app/view/swmm_views/08_vw_swmm_outfalls.sql @@ -7,11 +7,11 @@ SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, CASE - WHEN waterlevel_hydraulic IS NOT NULL THEN 'FIXED' + WHEN dp.waterlevel_hydraulic IS NOT NULL THEN 'FIXED' ELSE 'FREE' END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations CASE - WHEN waterlevel_hydraulic IS NOT NULL THEN waterlevel_hydraulic + WHEN dp.waterlevel_hydraulic IS NOT NULL THEN dp.waterlevel_hydraulic ELSE 0 END as StageData, 'NO'::varchar as tide_gate, @@ -42,14 +42,8 @@ UNION SELECT wn.obj_id as Name, coalesce(wn.bottom_level,0) as InvertElev, - CASE - WHEN waterlevel_hydraulic IS NOT NULL THEN 'FIXED' - ELSE 'FREE' - END as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations - CASE - WHEN waterlevel_hydraulic IS NOT NULL THEN waterlevel_hydraulic - ELSE 0 - END as StageData, + 'FREE' as Type, -- Type of outfall boundary condition: FREE: outfall stage determined by minimum of critical flow depth and normal flow depth in the connecting conduit. NORMAL: outfall stage based on normal flow depth in the connecting conduit. FIXED: outfall stage set to a fixed value. TIDAL: outfall stage given by a table of tide elevation versus time of day. TIMESERIES: outfall stage supplied from a time series of elevations + 0 as StageData, 'NO'::varchar as tide_gate, '0'::varchar as RouteTo, ws.identifier as description,