Skip to content

Commit d3a4f1b

Browse files
committed
Refactor of folder dev and clean code
1 parent fd256fe commit d3a4f1b

File tree

60 files changed

+36
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+36
-33
lines changed

dev/version3/admin/gw_fct_admin_multiplicate_network.sql dev/v3/admin/gw_fct_admin_multiplicate_network.sql

+16-15
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ This version of Giswater is provided by Giswater Association
66

77
--FUNCTION CODE:
88

9-
CREATE OR REPLACE FUNCTION ws1_2802.gw_fct_admin_multiplicate_network(p_x integer, p_y integer, p_dx integer, p_dy integer)
9+
CREATE OR REPLACE FUNCTION ws36010.gw_fct_admin_multiplicate_network(p_x integer, p_y integer, p_dx integer, p_dy integer)
1010
RETURNS json AS
1111
$BODY$
1212

1313
/* example
1414
1515
-- execute
16-
SELECT ws1_2802.gw_fct_admin_multiplicate_network(2,1,11000,15000);
16+
SELECT ws36010.gw_fct_admin_multiplicate_network(2,1,1700,2300);
1717
1818
*/
1919

@@ -26,10 +26,10 @@ BEGIN
2626

2727

2828
-- Set search path to local schema
29-
SET search_path = "ws1_2802", public;
29+
SET search_path = "ws36010", public;
3030

3131
-- set previous
32-
ALTER TABLE ext_plot ALTER COLUMN id SET DEFAULT nextval('ws1_2802.urn_id_seq'::regclass);
32+
ALTER TABLE ext_plot ALTER COLUMN id SET DEFAULT nextval('ws36010.urn_id_seq'::regclass);
3333

3434
ALTER TABLE node DISABLE TRIGGER gw_trg_edit_foreignkey;
3535
ALTER TABLE node DISABLE TRIGGER gw_trg_node_arc_divide;
@@ -40,7 +40,6 @@ BEGIN
4040
ALTER TABLE node DISABLE RULE insert_plan_psector_x_node;
4141

4242
ALTER TABLE arc DISABLE TRIGGER gw_trg_arc_noderotation_update;
43-
ALTER TABLE arc DISABLE TRIGGER gw_trg_arc_vnodelink_update;
4443
ALTER TABLE arc DISABLE TRIGGER gw_trg_edit_foreignkey;
4544
ALTER TABLE arc DISABLE TRIGGER gw_trg_topocontrol_arc;
4645
ALTER TABLE arc DISABLE TRIGGER gw_trg_typevalue_fk;
@@ -64,7 +63,7 @@ BEGIN
6463
FOR x IN 1..p_x
6564
LOOP
6665

67-
RAISE NOTICE 'X LOOP % , %',y,x;
66+
RAISE NOTICE 'X LOOP % , %', y,x;
6867

6968
RAISE NOTICE 'nodes';
7069
INSERT INTO node (code, elevation, depth, nodecat_id, epa_type, sector_id, arc_id, parent_id, state, state_type, annotation, observ,comment, dma_id, presszone_id,
@@ -85,6 +84,7 @@ BEGIN
8584
INSERT INTO inp_pump SELECT node_id FROM node WHERE state >0 and epa_type = 'PUMP' ON CONFLICT (node_id) DO NOTHING;
8685
INSERT INTO inp_shortpipe SELECT node_id FROM node WHERE state >0 and epa_type = 'SHORTPIPE' ON CONFLICT (node_id) DO NOTHING;
8786

87+
8888
-- TODO: insert man_junctio & others nodes.....
8989

9090
RAISE NOTICE 'arcs';
@@ -99,6 +99,7 @@ BEGIN
9999

100100
INSERT INTO inp_pipe SELECT arc_id FROM arc WHERE state >0 and epa_type = 'PIPE' ON CONFLICT (arc_id) DO NOTHING;
101101
INSERT INTO inp_virtualvalve SELECT arc_id FROM arc WHERE state >0 and epa_type = 'VIRTUALVALVE' ON CONFLICT (arc_id) DO NOTHING;
102+
INSERT INTO inp_virtualpump SELECT arc_id FROM arc WHERE state >0 and epa_type = 'VIRTUALPUMP' ON CONFLICT (arc_id) DO NOTHING;
102103

103104
-- TODO: insert man_pipe
104105

@@ -107,22 +108,23 @@ BEGIN
107108
function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, streetaxis2_id, postnumber, postnumber2,
108109
muni_id, streetaxis_id, postcode, district_id, postcomplement, postcomplement2, descript, link, verified, rotation, the_geom, undelete, label_x,label_y,label_rotation, expl_id,
109110
publish, inventory,num_value, connec_length, arc_id, minsector_id, dqa_id, staticpressure, pjoint_id, pjoint_type,
110-
adate, adescript, accessibility, lastupdate, lastupdate_user, asset_id, epa_type)
111+
adate, adescript, accessibility, lastupdate, lastupdate_user, asset_id, epa_type,
112+
om_state, conserv_state, priority, valve_location, valve_type, shutoff_valve, access_type, placement_type, crmzone_id, expl_id2, plot_code)
111113
SELECT code, elevation, depth,connecat_id, sector_id, customer_code, state, state_type, annotation, observ, comment,dma_id, presszone_id, soilcat_id,
112114
function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, streetaxis2_id, postnumber, postnumber2,
113115
muni_id, streetaxis_id, postcode, district_id, postcomplement, postcomplement2, descript, link, verified, rotation, st_translate(the_geom,x*p_dx,y*p_dy), undelete, label_x,label_y,label_rotation, expl_id,
114116
publish, inventory,num_value, connec_length, arc_id, minsector_id, dqa_id, staticpressure, pjoint_id, pjoint_type,
115-
adate, adescript, accessibility, lastupdate, lastupdate_user, asset_id, epa_type FROM connec;
117+
adate, adescript, accessibility, lastupdate, lastupdate_user, asset_id, epa_type, om_state, conserv_state, priority, valve_location, valve_type, shutoff_valve, access_type,
118+
placement_type, crmzone_id, expl_id2, plot_code FROM connec;
116119

117120
INSERT INTO inp_connec SELECT connec_id FROM connec WHERE epa_type = 'JUNCTION' ON CONFLICT (connec_id) DO NOTHING;
118121

119122
RAISE NOTICE 'links';
120-
INSERT INTO link (feature_type, feature_id, expl_id, exit_id, exit_type, userdefined_geom, state, the_geom, vnode_topelev)
121-
SELECT feature_type, feature_id, expl_id, exit_id, exit_type, userdefined_geom, state, st_translate(the_geom,x*p_dx,y*p_dy), vnode_topelev FROM link;
122-
123-
RAISE NOTICE 'Vnode';
124-
INSERT INTO vnode (state, the_geom)
125-
SELECT state, st_translate(the_geom,x*p_dx,y*p_dy) FROM vnode;
123+
INSERT INTO link (feature_type, feature_id, expl_id, exit_id, exit_type, userdefined_geom, state, the_geom, exit_topelev,
124+
exit_elev, sector_id, dma_id, fluid_type, presszone_id, dqa_id, minsector_id,expl_id2, epa_type, is_operative, insert_user, lastupdate, lastupdate_user, connecat_id, workcat_id, workcat_id_end, builtdate, enddate)
125+
SELECT feature_type, feature_id, expl_id, exit_id, exit_type, userdefined_geom, state, st_translate(the_geom,x*p_dx,y*p_dy), exit_topelev,
126+
exit_elev, sector_id, dma_id, fluid_type, presszone_id, dqa_id, minsector_id,expl_id2, epa_type, is_operative, insert_user, lastupdate, lastupdate_user, connecat_id, workcat_id, workcat_id_end, builtdate, enddate
127+
FROM link;
126128

127129
RAISE NOTICE 'Plot';
128130
INSERT INTO ext_plot (plot_code, muni_id, postcode, streetaxis_id, postnumber, complement, placement, square, observ, text, the_geom, expl_id)
@@ -142,7 +144,6 @@ BEGIN
142144
ALTER TABLE node ENABLE RULE insert_plan_psector_x_node;
143145

144146
ALTER TABLE arc ENABLE TRIGGER gw_trg_arc_noderotation_update;
145-
ALTER TABLE arc ENABLE TRIGGER gw_trg_arc_vnodelink_update;
146147
ALTER TABLE arc ENABLE TRIGGER gw_trg_edit_foreignkey;
147148
ALTER TABLE arc ENABLE TRIGGER gw_trg_topocontrol_arc;
148149
ALTER TABLE arc ENABLE TRIGGER gw_trg_typevalue_fk;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

utils/fct/gw_fct_linktonetwork.sql

+20-18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_fct_linktonetwork(p_data json)
1212
RETURNS json AS
1313
$BODY$
1414

15+
1516
/*
1617
GOAL
1718
----
@@ -32,7 +33,7 @@ EXAMPLES
3233
--------
3334
SELECT SCHEMA_NAME.gw_fct_setlinktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{"id":["3201","3200"]},"data":{"feature_type":"CONNEC", "forcedArcs":["2001","2002"]}}$$);
3435
35-
SELECT SCHEMA_NAME.gw_fct_setlinktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{"id":["3136"]},"data":{"feature_type":"CONNEC"}}$$);
36+
SELECT SCHEMA_NAME.gw_fct_setlinktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{"id":["3209"]},"data":{"feature_type":"CONNEC"}}$$);
3637
3738
3839
SELECT SCHEMA_NAME.gw_fct_setlinktonetwork($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{"id":["100013"]},"data":{"feature_type":"CONNEC", "forcedArcs":["221"]}}$$);
@@ -193,9 +194,9 @@ BEGIN
193194

194195
RAISE NOTICE '% - %', v_i, v_connect_id;
195196

196-
IF v_isforcedarcs IS FALSE THEN
197-
v_forcedarcs= '';
198-
END IF;
197+
IF v_isforcedarcs IS FALSE THEN
198+
v_forcedarcs= '';
199+
END IF;
199200

200201
INSERT INTO audit_check_data (fid, result_id, criticity, error_message)
201202
VALUES (217, null, 4, concat('Trying to connect ', lower(v_feature_type),' with id ',v_connect_id,'.'));
@@ -242,13 +243,14 @@ BEGIN
242243
-- Use connect.arc_id as forced arcs in case of exists
243244
IF v_connect.arc_id IS NOT NULL AND v_isforcedarcs is False THEN
244245
v_forcedarcs = concat (' AND arc_id::integer = ',v_connect.arc_id,' ');
246+
245247
-- check if forced arc diameter is smaller than configured
246-
IF v_projecttype ='WS' THEN
247-
IF (SELECT cat_dnom::integer FROM vu_arc WHERE arc_id=v_connect.arc_id) >= v_check_arcdnom AND v_check_arcdnom_status IS TRUE THEN
248-
EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{},
249-
"data":{"message":"3232", "function":"3188","debug_msg":'||v_check_arcdnom||', "is_process":true}}$$);';
250-
END IF;
251-
END IF;
248+
IF v_projecttype ='WS' THEN
249+
IF (SELECT cat_dnom::integer FROM vu_arc WHERE arc_id=v_connect.arc_id) >= v_check_arcdnom AND v_check_arcdnom_status IS TRUE THEN
250+
EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{},
251+
"data":{"message":"3232", "function":"3188","debug_msg":'||v_check_arcdnom||', "is_process":true}}$$);';
252+
END IF;
253+
END IF;
252254
END IF;
253255

254256
IF v_arc.arc_id IS NOT NULL THEN
@@ -258,7 +260,7 @@ BEGIN
258260

259261
-- Use check arc diameter variable
260262
IF v_projecttype = 'WS' AND v_check_arcdnom_status IS TRUE THEN
261-
v_checkeddiam = concat(' AND cat_dnom::integer<',v_check_arcdnom,' ');
263+
v_checkeddiam = concat(' AND cat_dnom::integer <',v_check_arcdnom,' ');
262264
ELSE v_checkeddiam = '';
263265
END IF;
264266

@@ -276,13 +278,13 @@ BEGIN
276278
SELECT arc_id FROM index_query ORDER BY distance limit 1'
277279
INTO v_connect.arc_id;
278280

279-
IF v_connect.arc_id IS NULL and v_forcedarcs is not null THEN -- looking for closest arc from connect
280-
EXECUTE 'WITH index_query AS(
281-
SELECT ST_Distance(the_geom, '||quote_literal(v_connect.the_geom::text)||') as distance, arc_id FROM arc WHERE state > 0 '||v_forcedarcs||')
282-
SELECT arc_id FROM index_query ORDER BY distance limit 1'
283-
INTO v_connect.arc_id;
284-
end if;
285-
281+
IF v_connect.arc_id IS NULL and v_forcedarcs is not null THEN -- looking for closest arc from connect
282+
EXECUTE 'WITH index_query AS(
283+
SELECT ST_Distance(the_geom, '||quote_literal(v_connect.the_geom::text)||') as distance, arc_id FROM arc WHERE state > 0 '||v_forcedarcs||')
284+
SELECT arc_id FROM index_query ORDER BY distance limit 1'
285+
INTO v_connect.arc_id;
286+
END IF;
287+
286288
END IF;
287289

288290
-- get v_edit_arc information

0 commit comments

Comments
 (0)