Skip to content

Commit

Permalink
fix(fct): correct pg2epa related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
danimarinBG committed Jan 24, 2025
1 parent dafa08b commit 771c835
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 116 deletions.
182 changes: 91 additions & 91 deletions ud/fct/ud_gw_fct_pg2epa_check_result.sql

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions ud/fct/ud_gw_fct_pg2epa_export_inp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ BEGIN
NULL::character varying AS other2,
NULL::character varying AS other3
FROM selector_inp_result s,
temp_rpt_inp_raingage r
t_rpt_inp_raingage r
LEFT JOIN inp_typevalue ON inp_typevalue.id::text = r.rgage_type::text
WHERE inp_typevalue.typevalue::text = 'inp_typevalue_raingage'::text AND r.rgage_type::text = 'TIMESERIES'::text AND s.result_id::text = r.result_id::text AND s.cur_user = CURRENT_USER
UNION
Expand All @@ -793,7 +793,7 @@ BEGIN
r.sta AS other2,
r.units AS other3
FROM selector_inp_result s,
temp_rpt_inp_raingage r
t_rpt_inp_raingage r
LEFT JOIN inp_typevalue ON inp_typevalue.id::text = r.rgage_type::text
WHERE inp_typevalue.typevalue::text = 'inp_typevalue_raingage'::text AND r.rgage_type::text = 'FILE'::text AND s.result_id::text = r.result_id::text AND s.cur_user = CURRENT_USER;

Expand Down Expand Up @@ -1224,7 +1224,7 @@ BEGIN
WHERE t.expl_id is NULL) b
ORDER BY b.id) c
JOIN inp_timeseries ON id = timser_id
WHERE (timser_type = 'Rainfall' and timser_id IN (SELECT timser_id FROM temp_rpt_inp_raingage)) or timser_type != 'Rainfall'::text
WHERE (timser_type = 'Rainfall' and timser_id IN (SELECT timser_id FROM t_rpt_inp_raingage)) or timser_type != 'Rainfall'::text
ORDER BY timser_id, other2;


Expand Down
8 changes: 4 additions & 4 deletions ud/fct/ud_gw_fct_pg2epa_fill_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ BEGIN
TRUNCATE temp_t_arc;
TRUNCATE temp_t_arc_flowregulator;
TRUNCATE temp_t_gully;
TRUNCATE temp_rpt_inp_raingage;
TRUNCATE t_rpt_inp_raingage;
DELETE FROM rpt_inp_raingage WHERE result_id = result_id_var;
TRUNCATE temp_t_lid_usage;

Expand Down Expand Up @@ -229,7 +229,7 @@ BEGIN
LEFT JOIN arc a USING (arc_id)
LEFT JOIN value_state_type ON id=g.state_type
WHERE arc_id IS NOT NULL AND g.sector_id > 0 '||v_statetype||' AND s.cur_user = current_user and s.sector_id = g.sector_id;';

END IF;

-- orifice
Expand Down Expand Up @@ -283,12 +283,12 @@ BEGIN
UPDATE temp_t_arc SET q0=0 where q0 IS NULL;

-- rpt_inp_raingage
INSERT INTO temp_rpt_inp_raingage
INSERT INTO t_rpt_inp_raingage
SELECT result_id_var, * FROM v_edit_raingage;

-- setting same rainfall for all raingage
IF v_rainfall IS NOT NULL THEN
UPDATE temp_rpt_inp_raingage SET timser_id=v_rainfall, rgage_type='TIMESERIES';
UPDATE t_rpt_inp_raingage SET timser_id=v_rainfall, rgage_type='TIMESERIES';
END IF;

-- setting for date-time parameters if rainfall has addparam values)
Expand Down
26 changes: 13 additions & 13 deletions ud/fct/ud_gw_fct_pg2epa_main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BEGIN
v_result = (p_data->>'data')::json->>'resultId';
v_dumpsubcatch = (p_data->>'data')::json->>'dumpSubcatch';
v_step = (p_data->>'data')::json->>'step';
v_input = concat('{"data":{"parameters":{"resultId":"',v_result,'", "dumpSubcatch":"',v_dumpsubcatch,'", "fid":227}}}')::json;
v_input = concat('{"data":{"parameters":{"isEmbebed":true, "resultId":"',v_result,'", "dumpSubcatch":"',v_dumpsubcatch,'", "fid":227}}}')::json;


-- get user parameters
Expand Down Expand Up @@ -156,8 +156,8 @@ BEGIN
END IF;

RAISE NOTICE '4.8 - Update values for temp table';
UPDATE t_arc SET result_id = v_result;
UPDATE t_node SET result_id = v_result;
UPDATE temp_t_arc SET result_id = v_result;
UPDATE temp_t_node SET result_id = v_result;

v_return = '{"status": "Accepted", "message":{"level":1, "text":"Export INP file 4/7 - Structure data...... done succesfully"}}'::json;
RETURN v_return;
Expand All @@ -176,17 +176,17 @@ BEGIN
PERFORM gw_fct_pg2epa_check_result(v_input);

-- deleting arcs without nodes
UPDATE t_arc t SET epa_type = 'TODELETE' FROM (SELECT a.id FROM t_arc a LEFT JOIN t_node ON node_1=node_id WHERE t_node.node_id is null) a WHERE t.id = a.id;
UPDATE t_arc t SET epa_type = 'TODELETE' FROM (SELECT a.id FROM t_arc a LEFT JOIN t_node ON node_2=node_id WHERE t_node.node_id is null) a WHERE t.id = a.id;
DELETE FROM t_arc WHERE epa_type = 'TODELETE';
UPDATE t_arc SET result_id = v_result WHERE result_id IS NULL;
UPDATE t_node SET result_id = v_result WHERE result_id IS NULL;
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;
DELETE FROM temp_t_arc WHERE epa_type = 'TODELETE';
UPDATE temp_t_arc SET result_id = v_result WHERE result_id IS NULL;
UPDATE temp_t_node SET result_id = v_result WHERE result_id IS NULL;

-- deleting nodes without arcs
UPDATE t_node t SET epa_type = 'TODELETE' FROM
(SELECT id FROM t_node LEFT JOIN (SELECT node_1 as node_id FROM t_arc UNION SELECT node_2 FROM t_arc) a USING (node_id) WHERE a.node_id IS NULL) a
UPDATE temp_t_node t SET epa_type = 'TODELETE' FROM
(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 t_node WHERE epa_type = 'TODELETE';
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;
Expand All @@ -207,14 +207,14 @@ BEGIN
SELECT
result_id, arc_id, node_1, node_2, elevmax1, elevmax2, arc_type, arccat_id, epa_type, sector_id, state, state_type, annotation,
length, n, the_geom, expl_id, addparam, arcparent, q0, qmax, barrels, slope, culvert, kentry, kexit, kavg, flap, seepage
FROM t_arc;
FROM temp_t_arc;

-- move nodes data
INSERT INTO rpt_inp_node (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)
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 t_node;
FROM temp_t_node;

-- move result data
UPDATE rpt_cat_result r set network_stats = t.network_stats FROM t_rpt_cat_result t WHERE r.result_id = t.result_id;
Expand Down
8 changes: 4 additions & 4 deletions updates/40/40000/utils/dml_issue_30.sql
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ function_name = '[gw_fct_pg2epa_check_result]',
active = true
WHERE fid = 377;


-- TODO: Activate this process once 'top_elev' is added to 'ws.node'.
UPDATE sys_fprocess SET
fprocess_name = 'Connec/node with outlayer value on elevation',
except_level = 3,
Expand All @@ -945,12 +945,12 @@ 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
active = false
WHERE fid = 407;


Expand Down
3 changes: 2 additions & 1 deletion utils/fct/gw_fct_manage_temp_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ BEGIN
CREATE TEMP TABLE temp_t_pgr_go2epa_node (LIKE temp_node INCLUDING ALL);

CREATE TEMP TABLE t_rpt_inp_pattern_value (LIKE rpt_inp_pattern_value INCLUDING ALL);
CREATE TEMP TABLE t_rpt_cat_result (LIKE rpt_cat_result INCLUDING ALL);

ELSIF v_project_type = 'UD' THEN
CREATE TEMP TABLE temp_t_arc_flowregulator (LIKE temp_arc_flowregulator INCLUDING ALL);
Expand All @@ -244,6 +243,8 @@ BEGIN
CREATE TEMP TABLE t_rpt_inp_arc (LIKE rpt_inp_arc INCLUDING ALL);
END IF;

CREATE TEMP TABLE t_rpt_cat_result (LIKE rpt_cat_result INCLUDING ALL);

CREATE TEMP TABLE temp_t_csv (LIKE temp_csv INCLUDING ALL);
CREATE TEMP TABLE temp_t_table (LIKE temp_table INCLUDING ALL);
CREATE TEMP TABLE temp_t_node (LIKE temp_node INCLUDING ALL);
Expand Down

0 comments on commit 771c835

Please sign in to comment.