From 8a54c2f1cfd69de6dbf1ae9b68f58d1469c6a00b Mon Sep 17 00:00:00 2001 From: Daniel Thom Date: Thu, 14 Apr 2022 16:36:54 -0600 Subject: [PATCH] Properly handle secondary voltages in HC scripts --- disco/postprocess/hosting_capacity.py | 12 ++-- disco/postprocess/query.mustache | 79 ++++++++++++++++++--------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/disco/postprocess/hosting_capacity.py b/disco/postprocess/hosting_capacity.py index 09e94664..8024baae 100644 --- a/disco/postprocess/hosting_capacity.py +++ b/disco/postprocess/hosting_capacity.py @@ -63,7 +63,7 @@ def synthesize_voltage(results_df): "sample", "penetration_level", "scenario", - "node_type"] + ] df = results_df.groupby(filter_cols)[["min_voltage"]].min().reset_index() df2 = results_df.groupby(filter_cols)[["max_voltage"]].max().reset_index() @@ -72,8 +72,8 @@ def synthesize_voltage(results_df): results_df.groupby(filter_cols)[ [ "num_nodes_any_outside_ansi_b", - "num_time_points_with_ansi_b_violations" - ] + "num_time_points_with_ansi_b_violations", + ] ] .max() .reset_index() @@ -161,10 +161,10 @@ def compute_hc_per_metric_class( ) meta_df = meta_df.dropna(axis="index", subset=["sample", "penetration_level"]) - metric_df, meta_df = synthesize(metric_df, meta_df, metric_class) - if metric_class == "voltage" and len(node_types) == 1: - metric_df = metric_df[metric_df.node_types == node_types[0]] + metric_df = metric_df[metric_df.node_type == node_types[0]] + + metric_df, meta_df = synthesize(metric_df, meta_df, metric_class) queries = build_queries(metric_df.columns, thresholds, metric_class, on=on) query_phrase = " & ".join(queries) diff --git a/disco/postprocess/query.mustache b/disco/postprocess/query.mustache index 94278fd1..d9990243 100644 --- a/disco/postprocess/query.mustache +++ b/disco/postprocess/query.mustache @@ -214,6 +214,33 @@ CREATE TEMP VIEW hc_max AS GROUP BY feeder ; +-- Create a table with worst-case values. +DROP VIEW IF EXISTS worst_case; +CREATE TEMP VIEW worst_case AS + SELECT + feeder + ,sample + ,penetration_level + ,transformer_instantaneous_threshold + {{#thermal}} + ,MAX(line_max_instantaneous_loading_pct) as line_max_instantaneous_loading_pct_overall + ,MAX(line_max_moving_average_loading_pct) as line_max_moving_average_loading_pct_overall + ,MAX(line_num_time_points_with_instantaneous_violations) as line_num_time_points_with_instantaneous_violations_overall + ,MAX(line_num_time_points_with_moving_average_violations) as line_num_time_points_with_moving_average_violations_overall + ,MAX(transformer_max_instantaneous_loading_pct) as transformer_max_instantaneous_loading_pct_overall + ,MAX(transformer_max_moving_average_loading_pct) as transformer_max_moving_average_loading_pct_overall + ,MAX(transformer_num_time_points_with_instantaneous_violations) as transformer_num_time_points_with_instantaneous_violations_overall + ,MAX(transformer_num_time_points_with_moving_average_violations) as transformer_num_time_points_with_moving_average_violations_overall + {{/thermal}} + {{#voltage}} + ,MIN(min_voltage) AS min_voltage_overall + ,MAX(max_voltage) AS max_voltage_overall + ,MAX(num_nodes_any_outside_ansi_b) as num_nodes_any_outside_ansi_b_overall + ,MAX(num_time_points_with_ansi_b_violations) as num_time_points_with_ansi_b_violations_overall + {{/voltage}} + FROM jt + GROUP BY feeder, sample, penetration_level, transformer_instantaneous_threshold; + -- Create a table showing hosting capacity by feeder and sample. DROP VIEW IF EXISTS hc_by_sample; CREATE TEMP VIEW hc_by_sample AS @@ -222,25 +249,25 @@ CREATE TEMP VIEW hc_by_sample AS ,sample --,pv_distance ,MAX(penetration_level) AS max_passing_penetration_level - FROM jt + FROM worst_case WHERE true {{#thermal}} AND ( - line_max_instantaneous_loading_pct <= {{thermal.line_max_instantaneous_loading_pct}} - AND line_max_moving_average_loading_pct <= {{thermal.line_max_moving_average_loading_pct}} - AND line_num_time_points_with_instantaneous_violations <= {{thermal.line_num_time_points_with_instantaneous_violations}} - AND line_num_time_points_with_moving_average_violations <= {{thermal.line_num_time_points_with_moving_average_violations}} + line_max_instantaneous_loading_pct_overall <= {{thermal.line_max_instantaneous_loading_pct}} + AND line_max_moving_average_loading_pct_overall <= {{thermal.line_max_moving_average_loading_pct}} + AND line_num_time_points_with_instantaneous_violations_overall <= {{thermal.line_num_time_points_with_instantaneous_violations}} + AND line_num_time_points_with_moving_average_violations_overall <= {{thermal.line_num_time_points_with_moving_average_violations}} AND ( transformer_instantaneous_threshold IS NULL OR ( - transformer_max_instantaneous_loading_pct <= {{thermal.transformer_max_instantaneous_loading_pct}} - AND transformer_max_moving_average_loading_pct <= {{thermal.transformer_max_moving_average_loading_pct}} - AND transformer_num_time_points_with_instantaneous_violations <= {{thermal.transformer_num_time_points_with_instantaneous_violations}} - AND transformer_num_time_points_with_moving_average_violations <= {{thermal.transformer_num_time_points_with_moving_average_violations}} + transformer_max_instantaneous_loading_pct_overall <= {{thermal.transformer_max_instantaneous_loading_pct}} + AND transformer_max_moving_average_loading_pct_overall <= {{thermal.transformer_max_moving_average_loading_pct}} + AND transformer_num_time_points_with_instantaneous_violations_overall <= {{thermal.transformer_num_time_points_with_instantaneous_violations}} + AND transformer_num_time_points_with_moving_average_violations_overall <= {{thermal.transformer_num_time_points_with_moving_average_violations}} ) ) ) @@ -248,10 +275,10 @@ CREATE TEMP VIEW hc_by_sample AS {{#voltage}} AND ( - min_voltage >= {{voltage.min_voltage}} - AND max_voltage <= {{voltage.max_voltage}} - AND num_nodes_any_outside_ansi_b <= {{voltage.num_nodes_any_outside_ansi_b}} - AND num_time_points_with_ansi_b_violations <= {{voltage.num_time_points_with_ansi_b_violations}} + min_voltage_overall >= {{voltage.min_voltage}} + AND max_voltage_overall <= {{voltage.max_voltage}} + AND num_nodes_any_outside_ansi_b_overall <= {{voltage.num_nodes_any_outside_ansi_b}} + AND num_time_points_with_ansi_b_violations_overall <= {{voltage.num_time_points_with_ansi_b_violations}} ) {{/voltage}} GROUP BY feeder, sample; @@ -282,25 +309,25 @@ CREATE TEMP VIEW hc_per_level1 AS feeder ,sample ,penetration_level - FROM jt + FROM worst_case WHERE true {{#thermal}} AND ( - line_max_instantaneous_loading_pct <= {{thermal.line_max_instantaneous_loading_pct}} - AND line_max_moving_average_loading_pct <= {{thermal.line_max_moving_average_loading_pct}} - AND line_num_time_points_with_instantaneous_violations <= {{thermal.line_num_time_points_with_instantaneous_violations}} - AND line_num_time_points_with_moving_average_violations <= {{thermal.line_num_time_points_with_moving_average_violations}} + line_max_instantaneous_loading_pct_overall <= {{thermal.line_max_instantaneous_loading_pct}} + AND line_max_moving_average_loading_pct_overall <= {{thermal.line_max_moving_average_loading_pct}} + AND line_num_time_points_with_instantaneous_violations_overall <= {{thermal.line_num_time_points_with_instantaneous_violations}} + AND line_num_time_points_with_moving_average_violations_overall <= {{thermal.line_num_time_points_with_moving_average_violations}} AND ( transformer_instantaneous_threshold IS NULL OR ( - transformer_max_instantaneous_loading_pct <= {{thermal.transformer_max_instantaneous_loading_pct}} - AND transformer_max_moving_average_loading_pct <= {{thermal.transformer_max_moving_average_loading_pct}} - AND transformer_num_time_points_with_instantaneous_violations <= {{thermal.transformer_num_time_points_with_instantaneous_violations}} - AND transformer_num_time_points_with_moving_average_violations <= {{thermal.transformer_num_time_points_with_moving_average_violations}} + transformer_max_instantaneous_loading_pct_overall <= {{thermal.transformer_max_instantaneous_loading_pct}} + AND transformer_max_moving_average_loading_pct_overall <= {{thermal.transformer_max_moving_average_loading_pct}} + AND transformer_num_time_points_with_instantaneous_violations_overall <= {{thermal.transformer_num_time_points_with_instantaneous_violations}} + AND transformer_num_time_points_with_moving_average_violations_overall <= {{thermal.transformer_num_time_points_with_moving_average_violations}} ) ) ) @@ -308,10 +335,10 @@ CREATE TEMP VIEW hc_per_level1 AS {{#voltage}} AND ( - min_voltage >= {{voltage.min_voltage}} - AND max_voltage <= {{voltage.max_voltage}} - AND num_nodes_any_outside_ansi_b <= {{voltage.num_nodes_any_outside_ansi_b}} - AND num_time_points_with_ansi_b_violations <= {{voltage.num_time_points_with_ansi_b_violations}} + min_voltage_overall >= {{voltage.min_voltage}} + AND max_voltage_overall <= {{voltage.max_voltage}} + AND num_nodes_any_outside_ansi_b_overall <= {{voltage.num_nodes_any_outside_ansi_b}} + AND num_time_points_with_ansi_b_violations_overall <= {{voltage.num_time_points_with_ansi_b_violations}} ) {{/voltage}} ;