diff --git a/ud/fct/ud_gw_fct_pg2epa_main.sql b/ud/fct/ud_gw_fct_pg2epa_main.sql index 21b672cf3..11333ab11 100644 --- a/ud/fct/ud_gw_fct_pg2epa_main.sql +++ b/ud/fct/ud_gw_fct_pg2epa_main.sql @@ -84,7 +84,7 @@ BEGIN IF v_count = 0 THEN RETURN ('{"status":"Failed","message":{"level":1, "text":"There is no sector selected. Please select at least one"}}')::json; END IF; - + -- drop temp tables DROP TABLE IF EXISTS temp_t_arc_flowregulator; DROP TABLE IF EXISTS temp_t_lid_usage; @@ -102,6 +102,7 @@ BEGIN DROP TABLE IF EXISTS temp_anl_arc; DROP TABLE IF EXISTS temp_anl_node; DROP TABLE IF EXISTS temp_anl_gully; + DROP TABLE IF EXISTS temp_anl_polygon; DROP TABLE IF EXISTS temp_rpt_inp_raingage; DROP TABLE IF EXISTS temp_rpt_inp_node; DROP TABLE IF EXISTS temp_rpt_inp_arc; @@ -220,7 +221,7 @@ BEGIN ELSIF v_step=6 THEN PERFORM gw_fct_pg2epa_check_result(v_input); - + -- deleting arcs without nodes UPDATE temp_t_arc t SET epa_type = 'TODELETE' FROM (SELECT a.id FROM temp_t_arc a LEFT JOIN temp_t_node ON node_1=node_id WHERE temp_t_node.node_id is null) a WHERE t.id = a.id; UPDATE temp_t_arc t SET epa_type = 'TODELETE' FROM (SELECT a.id FROM temp_t_arc a LEFT JOIN temp_t_node ON node_2=node_id WHERE temp_t_node.node_id is null) a WHERE t.id = a.id; @@ -233,9 +234,9 @@ BEGIN (SELECT id FROM temp_t_node LEFT JOIN (SELECT node_1 as node_id FROM temp_t_arc UNION SELECT node_2 FROM temp_t_arc) a USING (node_id) WHERE a.node_id IS NULL) a WHERE t.id = a.id; DELETE FROM temp_t_node WHERE epa_type = 'TODELETE'; - + -- create return - EXECUTE 'SELECT gw_fct_create_return($${"data":{"parameters":{"functionId":2646, "isEmbebed":false}}}$$::json)' INTO v_return; + EXECUTE 'SELECT gw_fct_create_return($${"data":{"parameters":{"functionId":2646, "isEmbebed":false}}}$$::json)' INTO v_return; SELECT gw_fct_pg2epa_export_inp(p_data) INTO v_file; v_body = gw_fct_json_object_set_key((v_return->>'body')::json, 'file', v_file); v_return = gw_fct_json_object_set_key(v_return, 'body', v_body); @@ -261,7 +262,7 @@ BEGIN SELECT result_id, node_id, top_elev, ymax, elev, node_type, nodecat_id, epa_type, sector_id, state, state_type, annotation, y0, ysur, apond, the_geom, expl_id, addparam, parent, arcposition, fusioned_node FROM temp_t_node; - + -- move result data UPDATE rpt_cat_result r set network_stats = t.network_stats FROM temp_t_rpt_cat_result t WHERE r.result_id = t.result_id; diff --git a/updates/40/40000/ud/ddl.sql b/updates/40/40000/ud/ddl.sql index 6e3cc458e..065be3bfd 100644 --- a/updates/40/40000/ud/ddl.sql +++ b/updates/40/40000/ud/ddl.sql @@ -339,7 +339,7 @@ ALTER TABLE config_form_fields ENABLE TRIGGER gw_trg_config_control; ALTER TABLE sys_feature_type DROP CONSTRAINT sys_feature_type_check; INSERT INTO sys_feature_type VALUES ('FLWREG', 5); ALTER TABLE sys_feature_type ADD CONSTRAINT sys_feature_type_check CHECK (((id)::text = -ANY (ARRAY[('ARC'::character varying)::text, ('CONNEC'::character varying)::text, ('ELEMENT'::character varying)::text, +ANY (ARRAY[('ARC'::character varying)::text, ('CONNEC'::character varying)::text, ('ELEMENT'::character varying)::text, ('GULLY'::character varying)::text, ('LINK'::character varying)::text, ('NODE'::character varying)::text, ('VNODE'::character varying)::text, ('FLWREG'::character varying)::text]))); @@ -349,14 +349,118 @@ INSERT INTO sys_feature_class VALUES ('ORIFICE', 'FLWREG', 'ORIFICE', ''); INSERT INTO sys_feature_class VALUES ('WEIR', 'FLWREG', 'WEIR', ''); INSERT INTO sys_feature_class VALUES ('PUMP', 'FLWREG', 'PUMP', ''); INSERT INTO sys_feature_class VALUES ('OUTLET', 'FLWREG', 'OUTLET', ''); -ALTER TABLE sys_feature_class ADD CONSTRAINT sys_feature_cat_check CHECK (((id)::text = ANY (ARRAY[('CHAMBER'::character varying)::text, -('CONDUIT'::character varying)::text, ('CONNEC'::character varying)::text, ('GULLY'::character varying)::text, +ALTER TABLE sys_feature_class ADD CONSTRAINT sys_feature_cat_check CHECK (((id)::text = ANY (ARRAY[('CHAMBER'::character varying)::text, +('CONDUIT'::character varying)::text, ('CONNEC'::character varying)::text, ('GULLY'::character varying)::text, ('JUNCTION'::character varying)::text, ('MANHOLE'::character varying)::text, ('NETELEMENT'::character varying)::text, -('NETGULLY'::character varying)::text, ('NETINIT'::character varying)::text, ('OUTFALL'::character varying)::text, -('SIPHON'::character varying)::text, ('STORAGE'::character varying)::text, ('VALVE'::character varying)::text, -('VARC'::character varying)::text, ('WACCEL'::character varying)::text, ('WJUMP'::character varying)::text, +('NETGULLY'::character varying)::text, ('NETINIT'::character varying)::text, ('OUTFALL'::character varying)::text, +('SIPHON'::character varying)::text, ('STORAGE'::character varying)::text, ('VALVE'::character varying)::text, +('VARC'::character varying)::text, ('WACCEL'::character varying)::text, ('WJUMP'::character varying)::text, ('WWTP'::character varying)::text, ('ELEMENT'::character varying)::text, ('LINK'::character varying)::text, ('ORIFICE'::character varying)::text, ('WEIR'::character varying)::text, ('PUMP'::character varying)::text, ('OUTLET'::character varying)::text]))); +-- 21/01/2025 +ALTER TABLE temp_node RENAME TO _temp_node; +ALTER TABLE _temp_node RENAME CONSTRAINT temp_node_pkey TO _temp_node_pkey; +ALTER TABLE _temp_node RENAME CONSTRAINT temp_node_node_id_unique TO _temp_node_node_id_unique; + +DROP INDEX IF EXISTS temp_node_epa_type; +DROP INDEX IF EXISTS temp_node_index; +DROP INDEX IF EXISTS temp_node_node_id; +DROP INDEX IF EXISTS temp_node_node_type; +DROP INDEX IF EXISTS temp_node_nodeparent; +DROP INDEX IF EXISTS temp_node_result_id; + +CREATE TABLE temp_node ( + id serial4 NOT NULL, + result_id varchar(30) NULL, + node_id varchar(16) NOT NULL, + top_elev numeric(12, 3) NULL, + ymax numeric(12, 3) NULL, + elev numeric(12, 3) NULL, + node_type varchar(30) NULL, + nodecat_id varchar(30) NULL, + epa_type varchar(16) NULL, + sector_id int4 NULL, + state int2 NULL, + state_type int2 NULL, + annotation varchar(254) NULL, + dma_id int4 NULL, + y0 numeric(12, 4) NULL, + ysur numeric(12, 4) NULL, + apond numeric(12, 4) NULL, + the_geom public.geometry(point, 25831) NULL, + expl_id int4 NULL, + addparam text NULL, + parent varchar(16) NULL, + arcposition int2 NULL, + fusioned_node text NULL, + age int4 NULL, + CONSTRAINT temp_node_node_id_unique UNIQUE (node_id), + CONSTRAINT temp_node_pkey PRIMARY KEY (id) +); +CREATE INDEX temp_node_epa_type ON temp_node USING btree (epa_type); +CREATE INDEX temp_node_index ON temp_node USING gist (the_geom); +CREATE INDEX temp_node_node_id ON temp_node USING btree (node_id); +CREATE INDEX temp_node_node_type ON temp_node USING btree (node_type); +CREATE INDEX temp_node_nodeparent ON temp_node USING btree (parent); +CREATE INDEX temp_node_result_id ON temp_node USING btree (result_id); +CREATE INDEX temp_node_dma_id ON temp_node USING btree (dma_id); + +ALTER TABLE temp_arc RENAME TO _temp_arc; +ALTER TABLE temp_arc RENAME CONSTRAINT temp_arc_pkey TO _temp_arc_pkey; + +DROP INDEX IF EXISTS temp_arc_arc_id; +DROP INDEX IF EXISTS temp_arc_arc_type; +DROP INDEX IF EXISTS temp_arc_epa_type; +DROP INDEX IF EXISTS temp_arc_index; +DROP INDEX IF EXISTS temp_arc_node_1_type; +DROP INDEX IF EXISTS temp_arc_node_2_type; +DROP INDEX IF EXISTS temp_arc_result_id; + + +CREATE TABLE temp_arc ( + id serial4 NOT NULL, + result_id varchar(30) NULL, + arc_id varchar(16) NOT NULL, + node_1 varchar(16) NULL, + node_2 varchar(16) NULL, + elevmax1 numeric(12, 3) NULL, + elevmax2 numeric(12, 3) NULL, + arc_type varchar(30) NULL, + arccat_id varchar(30) NULL, + epa_type varchar(16) NULL, + sector_id int4 NULL, + state int2 NULL, + state_type int2 NULL, + annotation varchar(254) NULL, + dma_id int4 NULL, + length numeric(12, 3) NULL, + n numeric(12, 3) NULL, + the_geom public.geometry(linestring, 25831) NULL, + expl_id int4 NULL, + addparam text NULL, + arcparent varchar(16) NULL, + q0 float8 NULL, + qmax float8 NULL, + barrels int4 NULL, + slope float8 NULL, + flag bool NULL, + culvert varchar(10) NULL, + kentry numeric(12, 4) NULL, + kexit numeric(12, 4) NULL, + kavg numeric(12, 4) NULL, + flap varchar(3) NULL, + seepage numeric(12, 4) NULL, + age int4 NULL, + CONSTRAINT temp_arc_pkey PRIMARY KEY (id) +); +CREATE INDEX temp_arc_arc_id ON temp_arc USING btree (arc_id); +CREATE INDEX temp_arc_arc_type ON temp_arc USING btree (arc_type); +CREATE INDEX temp_arc_epa_type ON temp_arc USING btree (epa_type); +CREATE INDEX temp_arc_index ON temp_arc USING gist (the_geom); +CREATE INDEX temp_arc_node_1_type ON temp_arc USING btree (node_1); +CREATE INDEX temp_arc_node_2_type ON temp_arc USING btree (node_2); +CREATE INDEX temp_arc_dma_id ON temp_arc USING btree (dma_id); +CREATE INDEX temp_arc_result_id ON temp_arc USING btree (result_id); \ No newline at end of file diff --git a/updates/40/40000/ud/dml.sql b/updates/40/40000/ud/dml.sql index a36b738ea..d1cfd04e1 100644 --- a/updates/40/40000/ud/dml.sql +++ b/updates/40/40000/ud/dml.sql @@ -2525,3 +2525,13 @@ INSERT INTO config_form_tabs (formname, tabname, "label", tooltip, sys_role, tab "disabled": false } ]'::json, 0, '{4,5}'); + +INSERT INTO temp_node (id, result_id, node_id, top_elev, ymax, elev, node_type, nodecat_id, epa_type, sector_id, state, state_type, annotation, dma_id, y0, ysur, apond, the_geom, expl_id, addparam, parent, arcposition, fusioned_node, age) +SELECT id, result_id, node_id, top_elev, ymax, elev, node_type, nodecat_id, epa_type, sector_id, state, state_type, annotation, NULL, y0, ysur, apond, the_geom, expl_id, addparam, parent, arcposition, fusioned_node, age +FROM _temp_node; + +INSERT INTO temp_arc (id, result_id, arc_id, node_1, node_2, elevmax1, elevmax2, arc_type, arccat_id, epa_type, sector_id, state, state_type, annotation, dma_id, length, n, the_geom, expl_id, +addparam, arcparent, q0, qmax, barrels, slope, flag, culvert, kentry, kexit, kavg, flap, seepage, age) +SELECT id, result_id, arc_id, node_1, node_2, elevmax1, elevmax2, arc_type, arccat_id, epa_type, sector_id, state, state_type, annotation, NULL, length, n, the_geom, expl_id, +addparam, arcparent, q0, qmax, barrels, slope, flag, culvert, kentry, kexit, kavg, flap, seepage, age +FROM _temp_arc; \ No newline at end of file diff --git a/updates/40/40000/utils/dml_issue_30.sql b/updates/40/40000/utils/dml_issue_30.sql index 6bb59136d..952f9131e 100644 --- a/updates/40/40000/utils/dml_issue_30.sql +++ b/updates/40/40000/utils/dml_issue_30.sql @@ -812,7 +812,7 @@ except_msg = 'links over nodarc (go2epa)', query_text = 'select link_id as arc_id, conneccat_id as arccat_id, a.expl_id, l.the_geom FROM t_link l, temp_t_arc a WHERE st_dwithin(st_endpoint(l.the_geom), a.the_geom, 0.001) AND a.epa_type NOT IN (''CONDUIT'', ''PIPE'', ''VIRTUALVALVE'', ''VIRTUALPUMP'')', info_msg = 'No links over nodarc found', project_type = 'ud', -except_table = 'anl_node', +except_table = 'anl_arc' function_name = '[gw_fct_pg2epa_check_network]', active = true WHERE fid = 404; @@ -945,9 +945,9 @@ query_text = ' WITH outlayer AS (SELECT ((value::json->>''elevation'')::json->>''max'')::numeric as max_elev, ((value::json->>''elevation'')::json->>''min'')::numeric as min_elev FROM config_param_system WHERE parameter = ''epa_outlayer_values'') - select node_id, nodecat_id from outlayer, node where elevation < min_elev or elevation > max_elev + select node_id, nodecat_id from outlayer, node where top_elev < min_elev or top_elev > max_elev union - select connec_id, conneccat_id from outlayer, connec where elevation < min_elev or elevation > max_elev', + select connec_id, conneccat_id from outlayer, connec where top_elev < min_elev or top_elev > max_elev', except_table = null, function_name = '[gw_fct_pg2epa_check_result]', active = true @@ -1026,7 +1026,7 @@ except_level = 3, except_msg = 'Controls with links (arc o nodarc) are not present on this result', info_msg = 'All Controls has correct link id (arc or nodarc) values.', query_text = ' - (SELECT a.id, a.arc_id as controls, b.arc_id as templayer FROM + SELECT * FROM (SELECT a.id, a.arc_id as controls, b.arc_id as templayer FROM (SELECT substring(split_part(text,''LINK '', 2) FROM ''[^ ]+''::text) arc_id, id, sector_id FROM inp_controls WHERE active is true)a LEFT JOIN temp_t_arc b USING (arc_id) WHERE b.arc_id IS NULL AND a.arc_id IS NOT NULL diff --git a/utils/fct/gw_fct_create_logreturn.sql b/utils/fct/gw_fct_create_logreturn.sql index eaacc34a0..41389cb21 100644 --- a/utils/fct/gw_fct_create_logreturn.sql +++ b/utils/fct/gw_fct_create_logreturn.sql @@ -76,7 +76,7 @@ BEGIN v_result := concat ('{"geometryType":"Point", "features":',v_result,',"category_field":"descript"}'); ELSIF v_returntype = 'line' THEN - + v_result = null; SELECT jsonb_agg(features.feature) INTO v_result FROM ( @@ -89,9 +89,9 @@ BEGIN ) row) features; v_result := COALESCE(v_result, '{}'); v_result = concat ('{"geometryType":"LineString", "features":',v_result, ',"category_field":"descript"}'); - + ELSIF v_returntype = 'polygon' THEN - + SELECT jsonb_agg(features.feature) INTO v_result FROM ( SELECT jsonb_build_object( diff --git a/utils/fct/gw_fct_create_logtables.sql b/utils/fct/gw_fct_create_logtables.sql index 3944238e8..fff8b1193 100644 --- a/utils/fct/gw_fct_create_logtables.sql +++ b/utils/fct/gw_fct_create_logtables.sql @@ -102,7 +102,9 @@ BEGIN AND cur_user = current_user'::text) as ct(cur_user varchar(50), inp_options_interval_from text, inp_options_interval_to text))row INTO v_options; - SELECT count(*) INTO v_doublen2a FROM v_edit_inp_pump WHERE pump_type = 'PRESSPUMP'; + IF v_project_type = 'WS' THEN + SELECT count(*) INTO v_doublen2a FROM v_edit_inp_pump WHERE pump_type = 'PRESSPUMP'; + END IF; SELECT value INTO v_patternmethod FROM config_param_user WHERE parameter = 'inp_options_patternmethod' AND cur_user=current_user; SELECT value INTO v_dscenario FROM config_param_user WHERE parameter = 'inp_options_dscenario_priority' AND cur_user=current_user; diff --git a/utils/fct/gw_fct_create_querytables.sql b/utils/fct/gw_fct_create_querytables.sql index f7e9cb3bd..c5deec5ad 100644 --- a/utils/fct/gw_fct_create_querytables.sql +++ b/utils/fct/gw_fct_create_querytables.sql @@ -85,9 +85,9 @@ BEGIN IF v_epacheck THEN v_filter = concat(v_filter, ' AND sector_id IN (select sector_id from selector_sector where cur_user = current_user)'); + DROP TABLE IF EXISTS t_inp_pump; EXECUTE 'CREATE TEMP TABLE t_inp_pump AS SELECT * FROM v_edit_inp_pump'||v_filter; IF v_project_type = 'WS' THEN DROP TABLE IF EXISTS t_inp_pipe; EXECUTE 'CREATE TEMP TABLE t_inp_pipe AS SELECT * FROM v_edit_inp_pipe'||v_filter; - DROP TABLE IF EXISTS t_inp_pump; EXECUTE 'CREATE TEMP TABLE t_inp_pump AS SELECT * FROM v_edit_inp_pump'||v_filter; DROP TABLE IF EXISTS t_inp_valve; EXECUTE 'CREATE TEMP TABLE t_inp_valve AS SELECT * FROM v_edit_inp_valve'||v_filter; DROP TABLE IF EXISTS t_inp_junction; EXECUTE 'CREATE TEMP TABLE t_inp_junction AS SELECT * FROM v_edit_inp_junction'||v_filter; DROP TABLE IF EXISTS t_inp_reservoir; EXECUTE 'CREATE TEMP TABLE t_inp_reservoir AS SELECT * FROM v_edit_inp_reservoir'||v_filter; @@ -97,7 +97,20 @@ BEGIN DROP TABLE IF EXISTS t_inp_virtualpump; EXECUTE 'CREATE TEMP TABLE t_inp_virtualpump AS SELECT * FROM v_edit_inp_virtualpump'||v_filter; ELSIF v_project_type = 'UD' THEN - DROP TABLE IF EXISTS t_inp_gully;EXECUTE 'CREATE TEMP TABLE t_inp_gully AS SELECT * FROM v_edit_inp_gully'||v_filter; + DROP TABLE IF EXISTS t_inp_conduit; EXECUTE 'CREATE TEMP TABLE t_inp_conduit AS SELECT * FROM v_edit_inp_conduit'||v_filter; + DROP TABLE IF EXISTS t_inp_outlet; EXECUTE 'CREATE TEMP TABLE t_inp_outlet AS SELECT * FROM v_edit_inp_outlet'||v_filter; + DROP TABLE IF EXISTS t_inp_orifice; EXECUTE 'CREATE TEMP TABLE t_inp_orifice AS SELECT * FROM v_edit_inp_orifice'||v_filter; + DROP TABLE IF EXISTS t_inp_weir; EXECUTE 'CREATE TEMP TABLE t_inp_weir AS SELECT * FROM v_edit_inp_weir'||v_filter; + DROP TABLE IF EXISTS t_inp_virtual; EXECUTE 'CREATE TEMP TABLE t_inp_virtual AS SELECT * FROM v_edit_inp_virtual'||v_filter; + DROP TABLE IF EXISTS t_inp_storage; EXECUTE 'CREATE TEMP TABLE t_inp_storage AS SELECT * FROM v_edit_inp_storage'||v_filter; + DROP TABLE IF EXISTS t_inp_subcatchment; EXECUTE 'CREATE TEMP TABLE t_inp_subcatchment AS SELECT * FROM v_edit_inp_subcatchment'; + DROP TABLE IF EXISTS t_inp_junction; EXECUTE 'CREATE TEMP TABLE t_inp_junction AS SELECT * FROM v_edit_inp_junction'||v_filter; + DROP TABLE IF EXISTS t_inp_outfall; EXECUTE 'CREATE TEMP TABLE t_inp_outfall AS SELECT * FROM v_edit_inp_outfall'||v_filter; + DROP TABLE IF EXISTS t_inp_divider; EXECUTE 'CREATE TEMP TABLE t_inp_divider AS SELECT * FROM v_edit_inp_divider'||v_filter; + DROP TABLE IF EXISTS t_inp_subc2outlet; EXECUTE 'CREATE TEMP TABLE t_inp_subc2outlet AS SELECT * FROM v_edit_inp_subc2outlet'; + DROP TABLE IF EXISTS t_inp_netgully; EXECUTE 'CREATE TEMP TABLE t_inp_netgully AS SELECT * FROM v_edit_inp_netgully'||v_filter; + DROP TABLE IF EXISTS t_inp_gully; EXECUTE 'CREATE TEMP TABLE t_inp_gully AS SELECT * FROM v_edit_inp_gully'||v_filter; + DROP TABLE IF EXISTS t_raingage; EXECUTE 'CREATE TEMP TABLE t_raingage AS SELECT * FROM v_edit_raingage'; END IF; END IF; @@ -105,15 +118,24 @@ BEGIN DROP TABLE IF EXISTS t_audit_check_data; EXECUTE 'CREATE TEMP TABLE t_audit_check_data AS SELECT * FROM audit_check_data'; DROP TABLE IF EXISTS t_audit_check_project; EXECUTE 'CREATE TEMP TABLE t_audit_check_project AS SELECT * FROM audit_check_project'; - ALTER TABLE t_audit_check_data ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.audit_check_data_id_seq'::regclass); -- create anl tables - DROP TABLE IF EXISTS t_anl_node; EXECUTE 'CREATE TEMP TABLE t_anl_node AS SELECT * FROM anl_node WHERE cur_user = current_user'; + DROP TABLE IF EXISTS t_anl_node; EXECUTE 'CREATE TEMP TABLE t_anl_node AS SELECT * FROM anl_node WHERE cur_user = current_user'; DROP TABLE IF EXISTS t_anl_arc; EXECUTE 'CREATE TEMP TABLE t_anl_arc AS SELECT * FROM anl_arc WHERE cur_user = current_user'; DROP TABLE IF EXISTS t_anl_connec; EXECUTE 'CREATE TEMP TABLE t_anl_connec AS SELECT * FROM anl_connec WHERE cur_user = current_user'; DROP TABLE IF EXISTS t_anl_polygon; EXECUTE 'CREATE TEMP TABLE t_anl_polygon AS SELECT * FROM anl_polygon WHERE cur_user = current_user'; + ALTER TABLE t_audit_check_data ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.audit_check_data_id_seq'::regclass); + ALTER TABLE t_anl_node ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.anl_node_id_seq'::regclass); + ALTER TABLE t_anl_node ALTER COLUMN cur_user SET DEFAULT '"current_user"()'; + ALTER TABLE t_anl_arc ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.anl_arc_id_seq'::regclass); + ALTER TABLE t_anl_arc ALTER COLUMN cur_user SET DEFAULT '"current_user"()'; + ALTER TABLE t_anl_connec ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.anl_connec_id_seq'::regclass); + ALTER TABLE t_anl_connec ALTER COLUMN cur_user SET DEFAULT '"current_user"()'; + ALTER TABLE t_anl_polygon ALTER COLUMN id SET DEFAULT nextval('SCHEMA_NAME.anl_polygon_id_seq'::regclass); + ALTER TABLE t_anl_polygon ALTER COLUMN cur_user SET DEFAULT '"current_user"()'; + -- Return RETURN '{"status":"ok"}'; diff --git a/utils/fct/gw_fct_pg2epa_check_data.sql b/utils/fct/gw_fct_pg2epa_check_data.sql index 5c74903e7..40fb69a00 100644 --- a/utils/fct/gw_fct_pg2epa_check_data.sql +++ b/utils/fct/gw_fct_pg2epa_check_data.sql @@ -54,12 +54,12 @@ BEGIN --raise exception 'v_sql %', v_sql; -- create log tables EXECUTE 'SELECT gw_fct_create_logtables($${"data":{"parameters":{"fid":'||v_fid||'}}}$$::json)'; - + END IF; -- getting sys_fprocess to be executed - v_querytext = 'select * from sys_fprocess where project_type in (lower('||quote_literal(v_project_type)||'), ''utils'') - and addparam is null and query_text is not null and function_name ilike ''%pg2epa_check_data%'' and active order by fid asc'; + v_querytext = 'SELECT * FROM sys_fprocess WHERE project_type IN (LOWER('||quote_literal(v_project_type)||'), ''utils'') + AND addparam IS NULL AND (query_text IS NOT NULL AND query_text <> '''') AND function_name ILIKE ''%pg2epa_check_data%'' AND active ORDER BY fid ASC'; -- loop for checks for v_rec in execute v_querytext diff --git a/utils/fct/gw_fct_pg2epa_check_network.sql b/utils/fct/gw_fct_pg2epa_check_network.sql index d40d1f0fe..4a935c5ff 100644 --- a/utils/fct/gw_fct_pg2epa_check_network.sql +++ b/utils/fct/gw_fct_pg2epa_check_network.sql @@ -54,11 +54,11 @@ BEGIN -- get input data v_result_id = ((p_data->>'data')::json->>'parameters')::json->>'resultId'; v_fid := ((p_data ->>'data')::json->>'parameters')::json->>'fid'; - + -- get project type v_project_type = (SELECT project_type FROM sys_version ORDER BY id DESC LIMIT 1); v_version = (SELECT giswater FROM sys_version ORDER BY id DESC LIMIT 1); - + -- get options data SELECT value INTO v_linkoffsets FROM config_param_user WHERE parameter = 'inp_options_link_offsets' AND cur_user = current_user; SELECT value INTO v_minlength FROM config_param_user WHERE parameter = 'inp_options_minlength' AND cur_user = current_user; @@ -68,7 +68,7 @@ BEGIN v_deldisconnetwork = (SELECT value::json->>'delDisconnNetwork' FROM config_param_user WHERE parameter='inp_options_debug' AND cur_user=current_user)::boolean; v_deldrynetwork = (SELECT value::json->>'delDryNetwork' FROM config_param_user WHERE parameter='inp_options_debug' AND cur_user=current_user)::boolean; v_removedemands = (SELECT value::json->>'removeDemandOnDryNodes' FROM config_param_user WHERE parameter='inp_options_debug' AND cur_user=current_user)::boolean; - + -- preparing table for check disconnected/dry network (139/232) DROP TABLE IF EXISTS t_pgr_go2epa_arc; CREATE TEMP TABLE t_pgr_go2epa_arc AS SELECT * FROM temp_t_arc; DROP TABLE IF EXISTS t_pgr_go2epa_node; CREATE TEMP TABLE t_pgr_go2epa_node AS SELECT * FROM temp_t_node; @@ -85,17 +85,17 @@ BEGIN join t_pgr_go2epa_node n2 on n2.node_id = node_2 ') c WHERE n.id::int = c.node; - + -- setting those node with sectors without inlet to sector_id = 0 - UPDATE t_pgr_go2epa_node SET sector_id = 0 WHERE sector_id NOT IN + UPDATE t_pgr_go2epa_node SET sector_id = 0 WHERE sector_id NOT IN (SELECT DISTINCT sector_id FROM (SELECT DISTINCT sector_id, epa_type FROM t_pgr_go2epa_node WHERE epa_type IN ('INLET', 'RESERVOIR', 'TANK'))a); -- update arc graph UPDATE t_pgr_go2epa_arc SET sector_id = n.sector_id FROM t_pgr_go2epa_node n WHERE node_id = node_1; UPDATE t_pgr_go2epa_arc SET sector_id = n.sector_id FROM t_pgr_go2epa_node n WHERE node_id = node_2; - IF v_project_type = 'WS' THEN - + IF v_project_type = 'WS' THEN + -- update arc graph for dry (232) DELETE FROM t_pgr_go2epa_arc WHERE status = 'CLOSED'; @@ -108,9 +108,9 @@ BEGIN join t_pgr_go2epa_node n2 on n2.node_id = node_2 ') c WHERE n.id::int = c.node; - + -- setting those node with dma_id without inlet to dma_id = 0 - UPDATE t_pgr_go2epa_node SET dma_id = 0 WHERE dma_id NOT IN + UPDATE t_pgr_go2epa_node SET dma_id = 0 WHERE dma_id NOT IN (SELECT DISTINCT dma_id FROM (SELECT DISTINCT dma_id, epa_type FROM t_pgr_go2epa_node WHERE epa_type IN ('INLET', 'RESERVOIR', 'TANK'))a); -- update arc graph @@ -124,7 +124,7 @@ BEGIN and addparam is null and query_text is not null and function_name ilike ''%pg2epa_check%'' and active order by fid asc'; -- loop for checks - for v_rec in execute v_querytext + for v_rec in execute v_querytext loop EXECUTE 'select gw_fct_check_fprocess($${"client":{"device":4, "infoType":1, "lang":"ES"}, "form":{},"feature":{},"data":{"parameters":{"functionFid":'||v_fid||', "checkFid":"'||v_rec.fid||'"}}}$$)'; @@ -132,20 +132,20 @@ BEGIN -- remove disconnected network IF v_deldisconnetwork THEN - - UPDATE temp_t_arc a SET sector_id = sector_id FROM t_pgr_go2epa_arc t WHERE t.sector_id = 0 AND t.arc_id = a.arc_id; - UPDATE temp_t_node a SET sector_id = sector_id FROM t_pgr_go2epa_node t WHERE t.sector_id = 0 AND t.arc_id = a.arc_id; + + UPDATE temp_t_arc a SET sector_id = t.sector_id FROM t_pgr_go2epa_arc t WHERE t.sector_id = 0 AND t.id = a.id; + UPDATE temp_t_node a SET sector_id = t.sector_id FROM t_pgr_go2epa_node t WHERE t.sector_id = 0 AND t.id = a.id; DELETE FROM temp_t_arc WHERE sector_id = 0; DELETE FROM temp_t_node WHERE sector_id = 0; GET DIAGNOSTICS v_count = row_count; IF v_count > 0 THEN INSERT INTO temp_audit_check_data (fid, criticity, error_message) - VALUES (v_fid, 2, + VALUES (v_fid, 2, concat('WARNING-227: {delDisconnectNetwork} is enabled and ',v_count,' arcs have been removed.')); ELSE INSERT INTO temp_audit_check_data (fid, criticity, error_message) - VALUES (v_fid, 1, + VALUES (v_fid, 1, concat('INFO: {delDisconnectNetwork} is enabled but nothing have been removed.')); END IF; END IF; @@ -158,24 +158,24 @@ BEGIN DELETE FROM temp_t_arc WHERE dma_id = 0; DELETE FROM temp_t_node WHERE dma_id = 0; GET DIAGNOSTICS v_count = row_count; - + IF v_count > 0 THEN INSERT INTO temp_audit_check_data (fid, criticity, error_message) - VALUES (v_fid, 2, + VALUES (v_fid, 2, concat('WARNING-227: {delDryNetwork} is enabled and ',v_count,' arcs have been removed.')); ELSE INSERT INTO temp_audit_check_data (fid, criticity, error_message) - VALUES (v_fid, 1, + VALUES (v_fid, 1, concat('INFO: {delDryNetwork} is enabled but nothing have been removed.')); END IF; END IF; - + -- remove dry demands IF v_removedemands THEN - UPDATE temp_t_node n SET demand = 0, addparam = gw_fct_json_object_set_key(a.addparam::json, 'removedDemand'::text, true::boolean) + UPDATE temp_t_node n SET demand = 0, addparam = gw_fct_json_object_set_key(a.addparam::json, 'removedDemand'::text, true::boolean) FROM t_pgr_go2epa_node a WHERE a.node_id = n.node_id; GET DIAGNOSTICS v_count = row_count; - + IF v_count > 0 THEN INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 2, concat( @@ -186,27 +186,27 @@ BEGIN END IF; DELETE FROM temp_audit_check_data WHERE fid = 227 AND error_message like '%Dry node(s) with demand%' AND cur_user = current_user; END IF; - + RAISE NOTICE '7 - Stats'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0,concat('')); INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0,concat('BASIC STATS')); INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0,concat('-------------------')); - + IF v_project_type = 'WS' THEN SELECT sum(length)/1000 INTO v_sumlength FROM temp_t_arc; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Total length (Km) : ',v_sumlength,'.')); - + SELECT min(elevation), max(elevation) INTO v_min, v_max FROM temp_t_node; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for node elevation. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); - + SELECT min(length), max(length) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'PIPE'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for pipe length. Minimun and maximum values are: (',v_min,' - ',v_max,' ).')); - + SELECT min(diameter), max(diameter) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'PIPE'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for pipe diameter. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); @@ -223,17 +223,17 @@ BEGIN SELECT sum(length)/1000 INTO v_sumlength FROM temp_t_arc; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Total length (Km) : ',coalesce(v_sumlength,0::numeric),'.')); - + IF v_linkoffsets = 'ELEVATION' THEN - + UPDATE temp_t_arc SET length = null where length = 0; - - SELECT min(((elevmax1-elevmax2)/coalesce(length,0.1))::numeric(12,4)), max(((elevmax1-elevmax2)/coalesce(length,0.1)::numeric(12,4))) + + SELECT min(((elevmax1-elevmax2)/coalesce(length,0.1))::numeric(12,4)), max(((elevmax1-elevmax2)/coalesce(length,0.1)::numeric(12,4))) INTO v_min, v_max FROM temp_t_arc; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for conduit slope. Values from [',v_min,'] to [',v_max,'] have been found.')); END IF; - + SELECT min(length), max(length) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'CONDUIT'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for conduit length. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); @@ -245,27 +245,27 @@ BEGIN SELECT min(elevmax1), max(elevmax1) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'CONDUIT'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for conduit z1. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); - + SELECT min(elevmax2), max(elevmax2) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'CONDUIT'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for conduit z2. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); - + SELECT min(slope), max(slope) INTO v_min, v_max FROM temp_t_arc WHERE epa_type = 'CONDUIT'; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, concat('Data analysis for conduit slope. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); - + SELECT min(elev), max(elev) INTO v_min, v_max FROM temp_t_node; INSERT INTO temp_audit_check_data (fid, criticity, error_message) VALUES (v_fid, 0, - concat('Data analysis for node elevation. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); + concat('Data analysis for node elevation. Minimun and maximum values are: ( ',v_min,' - ',v_max,' ).')); - v_networkstats = gw_fct_json_object_set_key((select json_build_object('sector', array_agg(sector_id)) + v_networkstats = gw_fct_json_object_set_key((select json_build_object('sector', array_agg(sector_id)) FROM selector_sector where cur_user=current_user and sector_id > 0), 'Total Length (Km)', v_sumlength); END IF; - + -- set rpt_cat_result table with network stats INSERT INTO temp_t_rpt_cat_result (result_id, network_stats) VALUES (v_result_id, v_networkstats); - + -- Return RETURN '{"status":"ok"}';