diff --git a/swmm_views/02_vw_swmm_junctions.sql b/swmm_views/02_vw_swmm_junctions.sql index aa40fd8bb..9eacc38e0 100644 --- a/swmm_views/02_vw_swmm_junctions.sql +++ b/swmm_views/02_vw_swmm_junctions.sql @@ -12,19 +12,24 @@ SELECT NULL::float as InitDepth, NULL::float as SurchargeDepth, NULL::float as PondedArea, - ws.identifier::text as description, - ma.obj_id as tag, - wn.situation_geometry as geom + ws.identifier::text as description, + CONCAT_WS(',', 'manhole', mf.value_en) as tag, + wn.situation_geometry as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.manhole ma LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ma.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id +LEFT JOIN qgep_vl.manhole_function mf on ma.function = mf.code WHERE wn.obj_id IS NOT NULL AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) ---AND function != 4798 -- separating_structure -> used in swmm dividers +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) -UNION ALL +UNION -- special structures SELECT @@ -34,17 +39,22 @@ SELECT NULL::float as InitDepth, NULL::float as SurchargeDepth, NULL::float as PondedArea, - ws.identifier::text as description, - ss.obj_id as tag, - wn.situation_geometry as geom + ws.identifier::text as description, + CONCAT_WS(',','special_structure', ssf.value_en) as tag, + wn.situation_geometry as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.special_structure ss LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ss.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id +LEFT JOIN qgep_vl.special_structure_function ssf on ss.function = ssf.code WHERE wn.obj_id IS NOT NULL AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) ---AND function != 4799 -- separating_structure -> used in swmm dividers +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) AND function NOT IN ( -- must be the same list in vw_swmm_storages 6397, --"pit_without_drain" -- 245, --"drop_structure" @@ -68,12 +78,75 @@ AND function NOT IN ( -- must be the same list in vw_swmm_storages 3676, --"stormwater_retention_tank" 5575, --"stormwater_retention_channel" 5576, --"stormwater_storage_channel" -3677, --"stormwater_composite_tank" -5372 --"stormwater_overflow" +3677 --"stormwater_composite_tank" +-- 5372 -- "stormwater_overflow" -- 5373, --"floating_material_separator" -- 383 , --"side_access" -- 227, --"jetting_manhole" -- 4799, --"separating_structure" -- 3008, --"unknown" -- 2745, --"vortex_manhole" -); +) + +UNION + +-- wastewater_node not linked to wastewater structures +SELECT + from_wn.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, + from_wn.obj_id as description, + 'junction without structure' as tag, + from_wn.situation_geometry as geom, + CASE + WHEN ws.status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state +FROM qgep_od.reach as re +LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text +LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure +LEFT JOIN qgep_od.reach_point rp_from ON rp_from.obj_id::text = re.fk_reach_point_from::text +LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewater_networkelement +LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text +-- Get wastewater structure linked to the from node +LEFT JOIN qgep_od.wastewater_networkelement we ON from_wn.obj_id = we.obj_id +LEFT JOIN qgep_od.wastewater_structure ws_node ON we.fk_wastewater_structure::text = ws_node.obj_id::text +-- select only the primary channels pwwf.* +WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +-- select only operationals and "planned" +AND ws.status IN (6530, 6533, 8493, 6529, 6526, 7959) +and ws_node is null + +UNION + +SELECT + to_wn.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, + to_wn.obj_id as description, + 'junction without structure' as tag, + to_wn.situation_geometry as geom, + CASE + WHEN ws.status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state +FROM qgep_od.reach as re +LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text +LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure +LEFT JOIN qgep_od.reach_point rp_to ON rp_to.obj_id::text = re.fk_reach_point_from::text +LEFT JOIN qgep_od.wastewater_node to_wn on to_wn.obj_id = rp_to.fk_wastewater_networkelement +LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text +-- Get wastewater structure linked to the from node +LEFT JOIN qgep_od.wastewater_networkelement we ON to_wn.obj_id = we.obj_id +LEFT JOIN qgep_od.wastewater_structure ws_node ON we.fk_wastewater_structure::text = ws_node.obj_id::text +-- select only the primary channels pwwf.* +WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +-- select only operationals and "planned" +AND ws.status IN (6530, 6533, 8493, 6529, 6526, 7959) +and ws_node is null; diff --git a/swmm_views/04_vw_swmm_conduits.sql b/swmm_views/04_vw_swmm_conduits.sql index 1e5bde03f..6d1741637 100644 --- a/swmm_views/04_vw_swmm_conduits.sql +++ b/swmm_views/04_vw_swmm_conduits.sql @@ -21,18 +21,35 @@ SELECT coalesce((rp_to.level-to_wn.bottom_level),0) as OutletOffset, 0 as InitFlow, 0 as MaxFlow, - ne.identifier::text as description, - ne.fk_wastewater_structure as tag, - ST_Simplify(ST_CurveToLine(progression_geometry), 20, TRUE)::geometry(LineStringZ, %(SRID)s) as geom + ws.identifier::text as description, + cfh.value_en as tag, + ST_SimplifyPreserveTopology(ST_CurveToLine(progression_geometry), 0.5)::geometry(LineStringZ, %(SRID)s) as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.reach as re LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text - LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure - LEFT JOIN qgep_od.reach_point rp_from ON rp_from.obj_id::text = re.fk_reach_point_from::text LEFT JOIN qgep_od.reach_point rp_to ON rp_to.obj_id::text = re.fk_reach_point_to::text - LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewater_networkelement LEFT JOIN qgep_od.wastewater_node to_wn on to_wn.obj_id = rp_to.fk_wastewater_networkelement LEFT JOIN qgep_od.channel ch on ch.obj_id::text = ws.obj_id::text -WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074); +LEFT JOIN qgep_vl.channel_function_hydraulic cfh on cfh.code = ch.function_hydraulic +-- select only the primary channels pwwf.* +WHERE ch.function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +-- select only operationals and "planned" +AND status IN (6530, 6533, 8493, 6529, 6526, 7959); +-- 6526 "other.calculation_alternative" +-- 6529 "other.project" +-- 7959 "other.planned" +-- 6530 "operational.tentative" +-- 6533 "operational.will_be_suspended" +-- 8493 "operational" + +-- 6532 "abanndoned.filled" +-- 3027 "unknown" +-- 3633 "inoperative" +-- 6523 "abanndoned.suspended_not_filled" +-- 6524 "abanndoned.suspended_unknown" diff --git a/swmm_views/05_vw_swmm_dividers.sql b/swmm_views/05_vw_swmm_dividers.sql index 332f32355..95d381842 100644 --- a/swmm_views/05_vw_swmm_dividers.sql +++ b/swmm_views/05_vw_swmm_dividers.sql @@ -9,17 +9,23 @@ SELECT st_x(wn.situation_geometry) as X_coordinate, st_y(wn.situation_geometry) as Y_coordinate, ws.identifier as description, - 'manhole' as tag, + CONCAT_WS(',', 'manhole', mf.value_en) as tag, wn.bottom_level as invert_elev, (co.level-wn.bottom_level) as max_depth, - '???' as diverted_link + '???' as diverted_link, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.manhole ma LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ma.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id +LEFT JOIN qgep_vl.manhole_function mf on ma.function = mf.code WHERE function = 4798 -- separating_structure AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) UNION ALL @@ -28,14 +34,20 @@ SELECT st_x(wn.situation_geometry) as X_coordinate, st_y(wn.situation_geometry) as Y_coordinate, ws.identifier as description, - 'special_stucture' as tag, + CONCAT_WS(',','special_structure', ssf.value_en) as tag, wn.bottom_level as invert_elev, (co.level-wn.bottom_level) as max_depth, - '???' as diverted_link + '???' as diverted_link, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.special_structure ss LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ss.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id +LEFT JOIN qgep_vl.special_structure_function ssf on ss.function = ssf.code WHERE function = 4799 -- separating_structure -AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074); +AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959); diff --git a/swmm_views/07_vw_swmm_losses.sql b/swmm_views/07_vw_swmm_losses.sql index d1e2c3b07..1b5e7c661 100644 --- a/swmm_views/07_vw_swmm_losses.sql +++ b/swmm_views/07_vw_swmm_losses.sql @@ -13,7 +13,11 @@ SELECT DISTINCT WHEN ts.obj_id IS NOT NULL THEN 'YES' ELSE 'NO' END as flap_gate, - 0::float as Seepage + 0::float as Seepage, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.reach re LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text LEFT JOIN qgep_od.pipe_profile pp on pp.obj_id = re.fk_pipe_profile @@ -22,4 +26,5 @@ LEFT JOIN qgep_od.wastewater_node from_wn on from_wn.obj_id = rp_from.fk_wastewa LEFT JOIN qgep_od.throttle_shut_off_unit ts ON ts.fk_wastewater_node = from_wn.obj_id LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id = ne.fk_wastewater_structure WHERE ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) ; -- wastewater node of the downstream wastewater node diff --git a/swmm_views/08_vw_swmm_outfalls.sql b/swmm_views/08_vw_swmm_outfalls.sql index cd5fb369a..5f2d8c6f2 100644 --- a/swmm_views/08_vw_swmm_outfalls.sql +++ b/swmm_views/08_vw_swmm_outfalls.sql @@ -13,10 +13,16 @@ SELECT NULL::varchar as RouteTo, CONCAT(ws.identifier, ', ', ws.remark) as description, dp.obj_id::varchar as tag, - wn.situation_geometry as geom + wn.situation_geometry as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.discharge_point as dp LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = dp.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id WHERE wn.obj_id IS NOT NULL -AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074); +AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) +; diff --git a/swmm_views/09_vw_swmm_subcatchments.sql b/swmm_views/09_vw_swmm_subcatchments.sql index d0e669178..a6a5c4882 100644 --- a/swmm_views/09_vw_swmm_subcatchments.sql +++ b/swmm_views/09_vw_swmm_subcatchments.sql @@ -1,24 +1,38 @@ + -------- -- View for the swmm module class subcatchments -- 20190329 qgep code sprint SB, TP -------- + CREATE OR REPLACE VIEW qgep_swmm.vw_subcatchments AS SELECT - replace(ca.obj_id, ' ', '_') as Name, - ('raingage@' || replace(ca.obj_id, ' ', '_'))::varchar as RainGage, - coalesce(fk_wastewater_networkelement_rw_current, replace(ca.obj_id, ' ', '_')) as Outlet, + concat(replace(ca.obj_id, ' ', '_'), '_', state) as Name, + concat('raingage@', replace(ca.obj_id, ' ', '_'))::varchar as RainGage, + CASE + WHEN state = 'rw_current' then fk_wastewater_networkelement_rw_current + WHEN state = 'rw_planned' then fk_wastewater_networkelement_rw_planned + WHEN state = 'ww_current' then fk_wastewater_networkelement_ww_current + WHEN state = 'ww_planned' then fk_wastewater_networkelement_ww_planned + ELSE replace(ca.obj_id, ' ', '_') + END as Outlet, CASE when surface_area is null then st_area(perimeter_geometry) when surface_area < 0.01 then st_area(perimeter_geometry) - else surface_area + else surface_area * 10000 -- conversion for ha to m2 END as Area, - discharge_coefficient_rw_current as percImperv, -- take from catchment_area instead of default value CASE - WHEN wn.situation_geometry IS NOT NULL + 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 + ELSE 0 + END as percImperv, -- take from catchment_area instead of default value + CASE + WHEN wn_geom IS NOT NULL THEN ( - st_maxdistance(wn.situation_geometry, ST_ExteriorRing(perimeter_geometry)) - + st_distance(wn.situation_geometry, ST_ExteriorRing(perimeter_geometry)) + st_maxdistance(wn_geom, ST_ExteriorRing(perimeter_geometry)) + + st_distance(wn_geom, ST_ExteriorRing(perimeter_geometry)) )/2 ELSE ( @@ -31,48 +45,107 @@ SELECT NULL::varchar as SnowPack, -- default value CONCAT(ca.identifier, ', ', ca.remark) as description, ca.obj_id as tag, - ST_Simplify(ST_CurveToLine(perimeter_geometry), 5, TRUE)::geometry(Polygon, %(SRID)s) as geom -FROM qgep_od.catchment_area as ca -LEFT JOIN qgep_od.wastewater_networkelement we on we.obj_id = ca.fk_wastewater_networkelement_rw_current -LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id -WHERE fk_wastewater_networkelement_rw_current IS NOT NULL; -- to avoid unconnected catchments + ST_SimplifyPreserveTopology(ST_CurveToLine(perimeter_geometry), 0.5)::geometry(Polygon, %(SRID)s) as geom, + CASE + WHEN state = 'rw_current' OR state = 'ww_current' THEN 'current' + WHEN state = 'rw_planned' OR state = 'ww_planned' THEN 'planned' + ELSE 'planned' + END as state +FROM ( + SELECT ca.*, wn.situation_geometry as wn_geom, 'rw_current' as state FROM qgep_od.catchment_area as ca + INNER JOIN qgep_od.wastewater_networkelement we on we.obj_id = ca.fk_wastewater_networkelement_rw_current + LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id + UNION ALL + SELECT ca.*, wn.situation_geometry as wn_geom, 'rw_planned' as state FROM qgep_od.catchment_area as ca + INNER JOIN qgep_od.wastewater_networkelement we on we.obj_id = ca.fk_wastewater_networkelement_rw_planned + LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id + UNION ALL + SELECT ca.*, wn.situation_geometry as wn_geom, 'ww_current' as state FROM qgep_od.catchment_area as ca + INNER JOIN qgep_od.wastewater_networkelement we on we.obj_id = ca.fk_wastewater_networkelement_ww_current + LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id + UNION ALL + SELECT ca.*, wn.situation_geometry as wn_geom,'ww_planned' as state FROM qgep_od.catchment_area as ca + INNER JOIN qgep_od.wastewater_networkelement we on we.obj_id = ca.fk_wastewater_networkelement_ww_planned + LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id +) as ca; + -- Creates subarea related to the subcatchment CREATE OR REPLACE VIEW qgep_swmm.vw_subareas AS SELECT - replace(ca.obj_id, ' ', '_') as Subcatchment, + concat(replace(ca.obj_id, ' ', '_'), '_', state) as Subcatchment, 0.01 as NImperv, -- default value, Manning's n for overland flow over the impervious portion of the subcatchment 0.1 as NPerv,-- default value, Manning's n for overland flow over the pervious portion of the subcatchment CASE - WHEN sr.surface_storage IS NOT NULL THEN sr.surface_storage + WHEN surface_storage IS NOT NULL THEN surface_storage ELSE 0.05 -- default value END as SImperv,-- Depth of depression storage on the impervious portion of the subcatchment (inches or millimeters) CASE - WHEN sr.surface_storage IS NOT NULL THEN sr.surface_storage + WHEN surface_storage IS NOT NULL THEN surface_storage ELSE 0.05 -- default value END as SPerv,-- Depth of depression storage on the pervious portion of the subcatchment (inches or millimeters) 25 as PctZero,-- default value, Percent of the impervious area with no depression storage. 'OUTLET'::varchar as RouteTo, NULL::float as PctRouted, - CONCAT(ca.identifier, ', ', ca.remark) as description, - ca.obj_id::varchar as tag + ca.identifier || ', ' || ca.remark as description, + ca.obj_id::varchar as tag, + state as state +FROM +( +SELECT ca.*, sr.surface_storage, 'rw_current' as state FROM qgep_od.catchment_area as ca LEFT JOIN qgep_od.surface_runoff_parameters sr ON ca.obj_id = sr.fk_catchment_area -WHERE fk_wastewater_networkelement_rw_current IS NOT NULL; -- to avoid unconnected catchments +WHERE fk_wastewater_networkelement_rw_current IS NOT NULL -- to avoid unconnected catchments +UNION ALL +SELECT ca.*, sr.surface_storage, 'ww_current' as state +FROM qgep_od.catchment_area as ca +LEFT JOIN qgep_od.surface_runoff_parameters sr ON ca.obj_id = sr.fk_catchment_area +WHERE fk_wastewater_networkelement_ww_current IS NOT NULL -- to avoid unconnected catchments +UNION ALL +SELECT ca.*, sr.surface_storage, 'rw_planned' as state +FROM qgep_od.catchment_area as ca +LEFT JOIN qgep_od.surface_runoff_parameters sr ON ca.obj_id = sr.fk_catchment_area +WHERE fk_wastewater_networkelement_rw_planned IS NOT NULL -- to avoid unconnected catchments +UNION ALL +SELECT ca.*, sr.surface_storage, 'ww_planned' as state +FROM qgep_od.catchment_area as ca +LEFT JOIN qgep_od.surface_runoff_parameters sr ON ca.obj_id = sr.fk_catchment_area +WHERE fk_wastewater_networkelement_ww_planned IS NOT NULL -- to avoid unconnected catchments +) as ca; -- Creates Dry Weather Flow related to the catchment area CREATE OR REPLACE VIEW qgep_swmm.vw_dwf AS SELECT - fk_wastewater_networkelement_rw_current as Node, -- id of the junction + CASE + WHEN state = 'current' THEN fk_wastewater_networkelement_rw_current + WHEN state = 'planned' THEN fk_wastewater_networkelement_rw_planned + END as Node, -- id of the junction 'FLOW'::varchar as Constituent, CASE - WHEN surface_area IS NOT NULL THEN population_density_current * surface_area * 160 / (24 * 60 * 60) - ELSE population_density_current * ST_Area(perimeter_geometry) * 160 / (24 * 60 * 60) + WHEN surface_area IS NOT NULL + THEN + CASE + WHEN state = 'current' THEN population_density_current * surface_area * 160 / (24 * 60 * 60) + WHEN state = 'planned' THEN population_density_planned * surface_area * 160 / (24 * 60 * 60) + END + ELSE + CASE + WHEN state = 'current' THEN population_density_current * ST_Area(perimeter_geometry) * 160 / (24 * 60 * 60) + WHEN state = 'planned' THEN population_density_planned * ST_Area(perimeter_geometry) * 160 / (24 * 60 * 60) + END END as Baseline, -- 160 Litre / inhabitant /day - 'dailyPatternDWF'::varchar as Patterns + 'dailyPatternDWF'::varchar as Patterns, + state as state +FROM +( +SELECT ca.*,'current' as state FROM qgep_od.catchment_area as ca -WHERE fk_wastewater_networkelement_rw_current IS NOT NULL; -- to avoid unconnected catchments - +WHERE fk_wastewater_networkelement_rw_current IS NOT NULL -- to avoid unconnected catchments +UNION ALL +SELECT ca.*,'planned' as state +FROM qgep_od.catchment_area as ca +WHERE fk_wastewater_networkelement_rw_planned IS NOT NULL -- to avoid unconnected catchments +) as ca; -- Creates a default raingage for each subcatchment CREATE OR REPLACE VIEW qgep_swmm.vw_raingages AS @@ -82,21 +155,50 @@ SELECT '0:15'::varchar as Interval, '1.0'::varchar as SCF, 'TIMESERIES default_qgep_raingage_timeserie'::varchar as Source, - st_centroid(perimeter_geometry)::geometry(Point, %(SRID)s) as geom + st_centroid(perimeter_geometry)::geometry(Point, %(SRID)s) as geom, + state +FROM +( +SELECT ca.*,'current' as state FROM qgep_od.catchment_area as ca -WHERE fk_wastewater_networkelement_rw_current IS NOT NULL; -- to avoid unconnected catchments +WHERE fk_wastewater_networkelement_rw_current IS NOT NULL -- to avoid unconnected catchments +UNION +SELECT ca.*,'planned' as state +FROM qgep_od.catchment_area as ca +WHERE fk_wastewater_networkelement_rw_planned IS NOT NULL -- to avoid unconnected catchments +UNION +SELECT ca.*,'current' as state +FROM qgep_od.catchment_area as ca +WHERE fk_wastewater_networkelement_ww_current IS NOT NULL -- to avoid unconnected catchments +UNION +SELECT ca.*,'planned' as state +FROM qgep_od.catchment_area as ca +WHERE fk_wastewater_networkelement_ww_planned IS NOT NULL -- to avoid unconnected catchments +) as ca; -- Creates default infiltration for each subcatchment CREATE OR REPLACE VIEW qgep_swmm.vw_infiltration AS SELECT - replace(ca.obj_id, ' ', '_') as Subcatchment, + CASE + WHEN state = 'current' THEN concat(replace(ca.obj_id, ' ', '_'), '_', 'rw_current') + WHEN state = 'planned' THEN concat(replace(ca.obj_id, ' ', '_'), '_', 'rw_planned') + END as Subcatchment, 3 as MaxRate, 0.5 as MinRate, 4 as Decay, 7 as DryTime, - 0 as MaxInfil + 0 as MaxInfil, + state +FROM +( +SELECT ca.*,'current' as state +FROM qgep_od.catchment_area as ca +WHERE fk_wastewater_networkelement_rw_current IS NOT NULL -- to avoid unconnected catchments +UNION ALL +SELECT ca.*,'planned' as state FROM qgep_od.catchment_area as ca -WHERE fk_wastewater_networkelement_rw_current IS NOT NULL; -- to avoid unconnected catchments; +WHERE fk_wastewater_networkelement_rw_planned IS NOT NULL -- to avoid unconnected catchments +) as ca; -- creates coverages diff --git a/swmm_views/11_vw_swmm_pumps.sql b/swmm_views/11_vw_swmm_pumps.sql index dbfd2cc13..667d888fe 100644 --- a/swmm_views/11_vw_swmm_pumps.sql +++ b/swmm_views/11_vw_swmm_pumps.sql @@ -17,8 +17,13 @@ SELECT pu.start_level as StartupDepth, pu.stop_level as ShutoffDepth, overflow.identifier as description, - pu.obj_id::varchar as tag + pu.obj_id::varchar as tag, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.pump pu JOIN qgep_od.overflow overflow ON pu.obj_id::text = overflow.obj_id::text LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = pu.obj_id::text -WHERE ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074); +WHERE ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959); diff --git a/swmm_views/13_vw_swmm_storages.sql b/swmm_views/13_vw_swmm_storages.sql index 35a0c23e5..7dd720d88 100644 --- a/swmm_views/13_vw_swmm_storages.sql +++ b/swmm_views/13_vw_swmm_storages.sql @@ -18,14 +18,19 @@ SELECT NULL as Psi, NULL as Ksat, -- conductivity NULL as IMD, - CONCAT(ws.identifier, ', ', ws.remark) as description, - ss.obj_id as tag, - wn.situation_geometry as geom + ws.identifier::text as description, + CONCAT_WS(',','special_structure', ssf.value_en) as tag, + wn.situation_geometry as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.special_structure ss LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ss.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id LEFT JOIN qgep_od.cover co on ws.fk_main_cover = co.obj_id +LEFT JOIN qgep_vl.special_structure_function ssf on ss.function = ssf.code WHERE ss.function IN ( -- must be the same list in vw_swmm_junctions 6397, --"pit_without_drain" -- 245, --"drop_structure" @@ -49,8 +54,8 @@ WHERE ss.function IN ( -- must be the same list in vw_swmm_junctions 3676, --"stormwater_retention_tank" 5575, --"stormwater_retention_channel" 5576, --"stormwater_storage_channel" -3677, --"stormwater_composite_tank" -5372 --"stormwater_overflow" +3677 --"stormwater_composite_tank" +-- 5372 --"stormwater_overflow" -- 5373, --"floating_material_separator" -- 383 , --"side_access" -- 227, --"jetting_manhole" @@ -59,6 +64,7 @@ WHERE ss.function IN ( -- must be the same list in vw_swmm_junctions -- 2745, --"vortex_manhole" ) AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959) UNION ALL SELECT wn.obj_id as Name, @@ -73,16 +79,19 @@ SELECT 0 as Fevap, NULL as Psi, (((absorption_capacity * 60 * 60) / 1000) / effective_area) * 1000 as Ksat, -- conductivity (liter/s * 60 * 60) -> liter/h, (liter/h / 1000) -> m3/h, (m/h *1000) -> mm/h - NULL as IMD, - --st_x(wn.situation_geometry) as X_coordinate, - --st_y(wn.situation_geometry) as Y_coordinate, - CONCAT(ws.identifier, ', ', ws.remark) as description, - ii.obj_id as tag, - wn.situation_geometry as geom + NULL as IMD, + ws.identifier::text as description, + CONCAT_WS(',','infiltration_installation', iik.value_en) as tag, + wn.situation_geometry as geom, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.infiltration_installation as ii LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ii.obj_id::text LEFT JOIN qgep_od.wastewater_networkelement we ON we.fk_wastewater_structure::text = ws.obj_id::text LEFT JOIN qgep_od.wastewater_node wn on wn.obj_id = we.obj_id +LEFT JOIN qgep_vl.infiltration_installation_kind iik on ii.kind = iik.code WHERE ii.kind IN ( --3282 --"with_soil_passage" --3285 --"without_soil_passage" @@ -96,4 +105,5 @@ WHERE ii.kind IN ( --278 --"adsorbing_well" --3283 --"infiltration_pipe_sections_gallery" ) -AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074); +AND ws._function_hierarchic in (5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074) +AND status IN (6530, 6533, 8493, 6529, 6526, 7959); diff --git a/swmm_views/14_vw_swmm_xsections.sql b/swmm_views/14_vw_swmm_xsections.sql index 655972185..c89c425fb 100644 --- a/swmm_views/14_vw_swmm_xsections.sql +++ b/swmm_views/14_vw_swmm_xsections.sql @@ -24,10 +24,16 @@ SELECT DISTINCT 0 as Geom3, 0 as Geom4, 1 as Barrels, - NULL as Culvert + NULL as Culvert, + CASE + WHEN status IN (7959, 6529, 6526) THEN 'planned' + ELSE 'current' + END as state FROM qgep_od.reach re LEFT JOIN qgep_od.pipe_profile pp on pp.obj_id = re.fk_pipe_profile LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.obj_id::text = re.obj_id::text LEFT JOIN qgep_od.wastewater_structure ws ON ws.obj_id::text = ne.fk_wastewater_structure::text LEFT JOIN qgep_od.channel ch ON ch.obj_id::text = ws.obj_id::text -WHERE ch.function_hierarchic = ANY (ARRAY[5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074]); +WHERE ch.function_hierarchic = ANY (ARRAY[5066, 5068, 5069, 5070, 5064, 5071, 5062, 5072, 5074]) +-- select only operationals and "planned" +AND status IN (6530, 6533, 8493, 6529, 6526, 7959); \ No newline at end of file diff --git a/test/test_swmm.py b/test/test_swmm.py index 074c123b6..2deb08535 100644 --- a/test/test_swmm.py +++ b/test/test_swmm.py @@ -27,61 +27,61 @@ def test_count_vw_aquifers(self): self.assert_count("vw_aquifers", "qgep_swmm", 0) def test_count_vw_conduits(self): - self.assert_count("vw_conduits", "qgep_swmm", 17200) + self.assert_count("vw_conduits", "qgep_swmm", 5095) def test_count_vw_coordinates(self): - self.assert_count("vw_coordinates", "qgep_swmm", 12159) + self.assert_count("vw_coordinates", "qgep_swmm", 6686) def test_count_vw_coverages(self): self.assert_count("vw_coverages", "qgep_swmm", 0) def test_count_vw_dividers(self): - self.assert_count("vw_dividers", "qgep_swmm", 43) + self.assert_count("vw_dividers", "qgep_swmm", 41) def test_count_vw_dwf(self): - self.assert_count("vw_dwf", "qgep_swmm", 1259) + self.assert_count("vw_dwf", "qgep_swmm", 1352) def test_count_vw_infiltration(self): - self.assert_count("vw_infiltration", "qgep_swmm", 1259) + self.assert_count("vw_infiltration", "qgep_swmm", 1352) def test_count_vw_junctions(self): - self.assert_count("vw_junctions", "qgep_swmm", 10806) + self.assert_count("vw_junctions", "qgep_swmm", 4575) def test_count_vw_landuses(self): self.assert_count("vw_landuses", "qgep_swmm", 6) def test_count_vw_losses(self): - self.assert_count("vw_losses", "qgep_swmm", 2348) + self.assert_count("vw_losses", "qgep_swmm", 1053) def test_count_vw_outfalls(self): - self.assert_count("vw_outfalls", "qgep_swmm", 68) + self.assert_count("vw_outfalls", "qgep_swmm", 54) def test_count_vw_polygons(self): - self.assert_count("vw_polygons", "qgep_swmm", 5952) + self.assert_count("vw_polygons", "qgep_swmm", 16007) def test_count_vw_pumps(self): self.assert_count("vw_pumps", "qgep_swmm", 0) def test_count_vw_raingages(self): - self.assert_count("vw_raingages", "qgep_swmm", 1259) + self.assert_count("vw_raingages", "qgep_swmm", 2035) def test_count_vw_storages(self): - self.assert_count("vw_storages", "qgep_swmm", 26) + self.assert_count("vw_storages", "qgep_swmm", 23) def test_count_vw_subareas(self): - self.assert_count("vw_subareas", "qgep_swmm", 1259) + self.assert_count("vw_subareas", "qgep_swmm", 2035) def test_count_vw_subcatchments(self): - self.assert_count("vw_subcatchments", "qgep_swmm", 1259) + self.assert_count("vw_subcatchments", "qgep_swmm", 2035) def test_count_vw_tags(self): - self.assert_count("vw_tags", "qgep_swmm", 29359) + self.assert_count("vw_tags", "qgep_swmm", 11782) def test_count_vw_vertices(self): - self.assert_count("vw_vertices", "qgep_swmm", 32) + self.assert_count("vw_vertices", "qgep_swmm", 643) def test_count_vw_xsections(self): - self.assert_count("vw_xsections", "qgep_swmm", 17200) + self.assert_count("vw_xsections", "qgep_swmm", 5095) if __name__ == '__main__': unittest.main()