Skip to content

Commit

Permalink
fix(views): bug fix when dropping views
Browse files Browse the repository at this point in the history
  • Loading branch information
mguzman14 committed Jan 20, 2025
1 parent 56cdd7f commit 9d33878
Showing 1 changed file with 326 additions and 2 deletions.
328 changes: 326 additions & 2 deletions updates/36/36017/ws/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,15 @@ AS SELECT d.dqa_id,
WHERE d.expl_id = selector_expl.expl_id AND d.active AND selector_expl.cur_user = "current_user"()::text OR d.expl_id IS NULL
ORDER BY d.dqa_id;


DROP VIEW IF EXISTS ve_epa_pump;
DROP VIEW IF EXISTS ve_epa_pump_additional;
DROP VIEW IF EXISTS ve_epa_valve;
DROP VIEW IF EXISTS ve_epa_shortpipe;
DROP VIEW IF EXISTS ve_epa_pipe;
DROP VIEW IF EXISTS ve_epa_virtualvalve;
DROP VIEW IF EXISTS ve_epa_virtualpump;

-- 18/01/2025
drop view v_rpt_arc;
CREATE OR REPLACE VIEW v_rpt_arc as
Expand Down Expand Up @@ -1117,7 +1126,7 @@ select arc.arc_id,
rpt_inp_arc arc
JOIN rpt_arc ON rpt_arc.arc_id::text = arc.arc_id::text
WHERE rpt_arc.result_id::text = selector_rpt_main.result_id::text AND selector_rpt_main.cur_user = "current_user"()::text AND arc.result_id::text = selector_rpt_main.result_id::text
GROUP BY arc.arc_id, arc.arc_type, arc.sector_id, arc.arccat_id, selector_rpt_main.result_id, arc.the_geom, rpt_arc.length
GROUP BY arc.arc_id, arc.arc_type, arc.sector_id, arc.arccat_id, selector_rpt_main.result_id, arc.the_geom, rpt_arc.length;

drop VIEW v_rpt_arc_all;
CREATE OR REPLACE VIEW v_rpt_arc_all as
Expand All @@ -1140,4 +1149,319 @@ SELECT rpt_arc.id,
rpt_inp_arc arc
JOIN rpt_arc ON rpt_arc.arc_id::text = arc.arc_id::text
WHERE rpt_arc.result_id::text = selector_rpt_main.result_id::text AND selector_rpt_main.cur_user = "current_user"()::text AND arc.result_id::text = selector_rpt_main.result_id::text
ORDER BY rpt_arc.setting, arc.arc_id;
ORDER BY rpt_arc.setting, arc.arc_id;


CREATE OR REPLACE VIEW v_rpt_arc_stats
AS SELECT r.arc_id,
r.result_id,
r.arc_type,
r.sector_id,
r.arccat_id,
r.flow_max,
r.flow_min,
r.flow_avg,
r.vel_max,
r.vel_min,
r.vel_avg,
r.headloss_max,
r.headloss_min,
r.setting_max,
r.setting_min,
r.reaction_max,
r.reaction_min,
r.ffactor_max,
r.ffactor_min,
r.the_geom
FROM rpt_arc_stats r,
selector_rpt_main s
WHERE r.result_id::text = s.result_id::text AND s.cur_user = "current_user"()::text;



CREATE OR REPLACE VIEW ve_epa_virtualvalve AS
SELECT inp_virtualvalve.arc_id,
inp_virtualvalve.valv_type,
inp_virtualvalve.pressure,
inp_virtualvalve.diameter,
inp_virtualvalve.flow,
inp_virtualvalve.coef_loss,
inp_virtualvalve.curve_id,
inp_virtualvalve.minorloss,
inp_virtualvalve.status,
inp_virtualvalve.init_quality,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM inp_virtualvalve
LEFT JOIN v_rpt_arc_stats USING (arc_id);

CREATE OR REPLACE VIEW ve_epa_virtualpump
AS SELECT p.arc_id,
p.power,
p.curve_id,
p.speed,
p.pattern_id,
p.status,
p.pump_type,
p.effic_curve_id,
p.energy_price,
p.energy_pattern_id,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM inp_virtualpump p
LEFT JOIN v_rpt_arc_stats USING (arc_id);

CREATE OR REPLACE VIEW ve_epa_pump
AS SELECT inp_pump.node_id,
inp_pump.power,
inp_pump.curve_id,
inp_pump.speed,
inp_pump.pattern_id,
inp_pump.status,
p.to_arc,
inp_pump.energyparam,
inp_pump.energyvalue,
inp_pump.pump_type,
inp_pump.effic_curve_id,
inp_pump.energy_price,
inp_pump.energy_pattern_id,
concat(inp_pump.node_id, '_n2a') AS nodarc_id,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM inp_pump
LEFT JOIN v_rpt_arc_stats ON concat(inp_pump.node_id, '_n2a') = v_rpt_arc_stats.arc_id::text
LEFT JOIN man_pump p ON p.node_id::text = inp_pump.node_id::text;

CREATE OR REPLACE VIEW ve_epa_pump_additional
AS SELECT inp_pump_additional.id,
inp_pump_additional.node_id,
inp_pump_additional.order_id,
inp_pump_additional.power,
inp_pump_additional.curve_id,
inp_pump_additional.speed,
inp_pump_additional.pattern_id,
inp_pump_additional.status,
inp_pump_additional.energyparam,
inp_pump_additional.energyvalue,
inp_pump_additional.effic_curve_id,
inp_pump_additional.energy_price,
inp_pump_additional.energy_pattern_id,
concat(inp_pump_additional.node_id, '_n2a') AS nodarc_id,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM inp_pump_additional
LEFT JOIN v_rpt_arc_stats ON concat(inp_pump_additional.node_id, '_n2a', inp_pump_additional.order_id) = v_rpt_arc_stats.arc_id::text;

CREATE OR REPLACE VIEW ve_epa_valve
AS SELECT inp_valve.node_id,
inp_valve.valv_type,
inp_valve.pressure,
vu_node.cat_dint,
inp_valve.custom_dint,
inp_valve.flow,
inp_valve.coef_loss,
inp_valve.curve_id,
inp_valve.minorloss,
v.to_arc,
CASE
WHEN v.closed IS TRUE THEN 'CLOSED'::character varying(12)
WHEN v.closed IS FALSE AND v.active IS TRUE THEN 'ACTIVE'::character varying(12)
WHEN v.closed IS FALSE AND v.active IS FALSE THEN 'OPEN'::character varying(12)
ELSE NULL::character varying(12)
END AS status,
inp_valve.add_settings,
inp_valve.init_quality,
concat(inp_valve.node_id, '_n2a') AS nodarc_id,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM vu_node
JOIN inp_valve USING (node_id)
LEFT JOIN v_rpt_arc_stats ON concat(inp_valve.node_id, '_n2a') = v_rpt_arc_stats.arc_id::text
LEFT JOIN man_valve v ON v.node_id::text = inp_valve.node_id::text;

CREATE OR REPLACE VIEW ve_epa_shortpipe
AS SELECT inp_shortpipe.node_id,
inp_shortpipe.minorloss,
vu_node.cat_dint,
inp_shortpipe.custom_dint,
v.to_arc,
CASE
WHEN v.active IS TRUE AND v.to_arc IS NOT NULL THEN 'CV'::character varying(12)
WHEN v.closed IS TRUE THEN 'CLOSED'::character varying(12)
WHEN v.closed IS FALSE THEN 'OPEN'::character varying(12)
ELSE NULL::character varying(12)
END AS status,
inp_shortpipe.bulk_coeff,
inp_shortpipe.wall_coeff,
concat(inp_shortpipe.node_id, '_n2a') AS nodarc_id,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max AS flowmax,
v_rpt_arc_stats.flow_min AS flowmin,
v_rpt_arc_stats.flow_avg AS flowavg,
v_rpt_arc_stats.vel_max AS velmax,
v_rpt_arc_stats.vel_min AS velmin,
v_rpt_arc_stats.vel_avg AS velavg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM vu_node
JOIN inp_shortpipe USING (node_id)
LEFT JOIN v_rpt_arc_stats ON concat(inp_shortpipe.node_id, '_n2a') = v_rpt_arc_stats.arc_id::text
LEFT JOIN man_valve v ON v.node_id::text = inp_shortpipe.node_id::text;

CREATE OR REPLACE VIEW ve_epa_pipe AS
SELECT inp_pipe.arc_id,
inp_pipe.minorloss,
inp_pipe.status,
a.cat_matcat_id,
a.builtdate,
r.roughness AS cat_roughness,
inp_pipe.custom_roughness,
a.cat_dint,
inp_pipe.custom_dint,
inp_pipe.reactionparam,
inp_pipe.reactionvalue,
inp_pipe.bulk_coeff,
inp_pipe.wall_coeff,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max,
v_rpt_arc_stats.flow_min,
v_rpt_arc_stats.flow_avg,
v_rpt_arc_stats.vel_max,
v_rpt_arc_stats.vel_min,
v_rpt_arc_stats.vel_avg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM vu_arc a
JOIN inp_pipe USING (arc_id)
LEFT JOIN v_rpt_arc_stats ON split_part(v_rpt_arc_stats.arc_id::text, 'P'::text, 1) = inp_pipe.arc_id::text
LEFT JOIN cat_mat_roughness r ON a.cat_matcat_id::text = r.matcat_id::text
WHERE ((now()::date -
CASE
WHEN a.builtdate IS NULL THEN '1900-01-01'::date
ELSE a.builtdate
END) / 365) >= r.init_age AND ((now()::date -
CASE
WHEN a.builtdate IS NULL THEN '1900-01-01'::date
ELSE a.builtdate
END) / 365) < r.end_age AND r.active IS TRUE;


CREATE OR REPLACE VIEW ve_epa_pipe AS
SELECT inp_pipe.arc_id,
inp_pipe.minorloss,
inp_pipe.status,
a.cat_matcat_id,
a.builtdate,
r.roughness AS cat_roughness,
inp_pipe.custom_roughness,
a.cat_dint,
inp_pipe.custom_dint,
inp_pipe.reactionparam,
inp_pipe.reactionvalue,
inp_pipe.bulk_coeff,
inp_pipe.wall_coeff,
v_rpt_arc_stats.result_id,
v_rpt_arc_stats.flow_max,
v_rpt_arc_stats.flow_min,
v_rpt_arc_stats.flow_avg,
v_rpt_arc_stats.vel_max,
v_rpt_arc_stats.vel_min,
v_rpt_arc_stats.vel_avg,
v_rpt_arc_stats.headloss_max,
v_rpt_arc_stats.headloss_min,
v_rpt_arc_stats.setting_max,
v_rpt_arc_stats.setting_min,
v_rpt_arc_stats.reaction_max,
v_rpt_arc_stats.reaction_min,
v_rpt_arc_stats.ffactor_max,
v_rpt_arc_stats.ffactor_min
FROM vu_arc a
JOIN inp_pipe USING (arc_id)
LEFT JOIN v_rpt_arc_stats ON split_part(v_rpt_arc_stats.arc_id::text, 'P'::text, 1) = inp_pipe.arc_id::text
LEFT JOIN cat_mat_roughness r ON a.cat_matcat_id::text = r.matcat_id::text
WHERE ((now()::date -
CASE
WHEN a.builtdate IS NULL THEN '1900-01-01'::date
ELSE a.builtdate
END) / 365) >= r.init_age AND ((now()::date -
CASE
WHEN a.builtdate IS NULL THEN '1900-01-01'::date
ELSE a.builtdate
END) / 365) < r.end_age AND r.active IS TRUE;

0 comments on commit 9d33878

Please sign in to comment.