Skip to content

Commit 2c89f29

Browse files
committed
Remove BAU columns from custom_table_rates
1 parent 9952837 commit 2c89f29

File tree

2 files changed

+64
-51
lines changed

2 files changed

+64
-51
lines changed

reoptjl/custom_table_config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,30 +1296,30 @@
12961296
# This formula calculates the percentage change of Placeholder2 using Placeholder1's BAU value as the reference.
12971297
},
12981298

1299-
# ANCCR Specific Calculations
1299+
# custom_table_rates Specific Calculations
13001300
{
13011301
"name": "Change in Year 1 Total Charges ($)",
1302-
"formula": lambda col, bau, headers: f'={col}{headers["Year 1 Total Bill Charges ($)"] + 2}-{"C"}{headers["Year 1 Total Bill Charges ($)"] + 2}'
1302+
"formula": lambda col, bau, headers: f'={col}{headers["Year 1 Total Bill Charges ($)"] + 2}-{"B"}{headers["Year 1 Total Bill Charges ($)"] + 2}'
13031303
# This formula calculates the percentage change of scenario 2 vs. scenario 1.
13041304
},
13051305
{
13061306
"name": "Year 1 Fixed Charges Percent Change (%)",
1307-
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Fixed Charges ($)"] + 2}-{"C"}{headers["Year 1 Annual Fixed Charges ($)"] + 2})/{"C"}{headers["Year 1 Annual Fixed Charges ($)"] + 2}'
1307+
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Fixed Charges ($)"] + 2}-{"B"}{headers["Year 1 Annual Fixed Charges ($)"] + 2})/{"B"}{headers["Year 1 Annual Fixed Charges ($)"] + 2}'
13081308
# This formula calculates the percentage change of scenario 2 vs. scenario 1.
13091309
},
13101310
{
13111311
"name": "Year 1 Energy Charges Percent Change (%)",
1312-
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Energy Charges ($)"] + 2}-{"C"}{headers["Year 1 Annual Energy Charges ($)"] + 2})/{"C"}{headers["Year 1 Annual Energy Charges ($)"] + 2}'
1312+
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Energy Charges ($)"] + 2}-{"B"}{headers["Year 1 Annual Energy Charges ($)"] + 2})/{"B"}{headers["Year 1 Annual Energy Charges ($)"] + 2}'
13131313
# This formula calculates the percentage change of scenario 2 vs. scenario 1.
13141314
},
13151315
{
13161316
"name": "Year 1 Demand Charges Percent Change (%)",
1317-
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Demand Charges ($)"] + 2}-{"C"}{headers["Year 1 Annual Demand Charges ($)"] + 2})/{"C"}{headers["Year 1 Annual Demand Charges ($)"] + 2}'
1317+
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Demand Charges ($)"] + 2}-{"B"}{headers["Year 1 Annual Demand Charges ($)"] + 2})/{"B"}{headers["Year 1 Annual Demand Charges ($)"] + 2}'
13181318
# This formula calculates the percentage change of scenario 2 vs. scenario 1.
13191319
},
13201320
{
13211321
"name": "Year 1 Total Bill Charges Percent Change (%)",
1322-
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Total Bill Charges ($)"] + 2}-{"C"}{headers["Year 1 Annual Total Bill Charges ($)"] + 2})/{"C"}{headers["Year 1 Annual Total Bill Charges ($)"] + 2}'
1322+
"formula": lambda col, bau, headers: f'=({col}{headers["Year 1 Annual Total Bill Charges ($)"] + 2}-{"B"}{headers["Year 1 Annual Total Bill Charges ($)"] + 2})/{"B"}{headers["Year 1 Annual Total Bill Charges ($)"] + 2}'
13231323
# This formula calculates the percentage change of scenario 2 vs. scenario 1.
13241324
},
13251325
{

reoptjl/views.py

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,20 +1877,33 @@ def get_bau_values(scenarios: List[Dict[str, Any]], config: List[Dict[str, Any]]
18771877

18781878
def process_scenarios(scenarios: List[Dict[str, Any]], reopt_data_config: List[Dict[str, Any]]) -> pd.DataFrame:
18791879
try:
1880-
bau_values_per_scenario = get_bau_values(scenarios, reopt_data_config)
1881-
all_dataframes = []
1880+
# Check if we're using custom_table_rates - if so, skip BAU data entirely
1881+
is_rates_table = (reopt_data_config == custom_table_rates)
1882+
1883+
if is_rates_table:
1884+
# For custom_table_rates, only generate scenario data (no BAU)
1885+
all_dataframes = []
1886+
for idx, scenario in enumerate(scenarios):
1887+
run_uuid = scenario['run_uuid']
1888+
df_result = generate_reopt_dataframe(scenario['full_data'], run_uuid, reopt_data_config)
1889+
df_result["Scenario"] = run_uuid
1890+
all_dataframes.append(df_result)
1891+
else:
1892+
# For all other tables, generate both BAU and scenario data
1893+
bau_values_per_scenario = get_bau_values(scenarios, reopt_data_config)
1894+
all_dataframes = []
18821895

1883-
for idx, scenario in enumerate(scenarios):
1884-
run_uuid = scenario['run_uuid']
1885-
df_result = generate_reopt_dataframe(scenario['full_data'], run_uuid, reopt_data_config)
1886-
df_result["Scenario"] = run_uuid
1896+
for idx, scenario in enumerate(scenarios):
1897+
run_uuid = scenario['run_uuid']
1898+
df_result = generate_reopt_dataframe(scenario['full_data'], run_uuid, reopt_data_config)
1899+
df_result["Scenario"] = run_uuid
18871900

1888-
bau_data = {key: [value] for key, value in bau_values_per_scenario[run_uuid].items()}
1889-
bau_data["Scenario"] = [f"BAU {idx + 1}"]
1890-
df_bau = pd.DataFrame(bau_data)
1901+
bau_data = {key: [value] for key, value in bau_values_per_scenario[run_uuid].items()}
1902+
bau_data["Scenario"] = [f"BAU {idx + 1}"]
1903+
df_bau = pd.DataFrame(bau_data)
18911904

1892-
# Add both BAU and result dataframes to list
1893-
all_dataframes.extend([df_bau, df_result])
1905+
# Add both BAU and result dataframes to list
1906+
all_dataframes.extend([df_bau, df_result])
18941907

18951908
# Concatenate all dataframes at once
18961909
combined_df = pd.concat(all_dataframes, axis=0, ignore_index=True)
@@ -2026,26 +2039,24 @@ def get_combined_format(label, row_color, is_formula=False):
20262039
column_width = 25
20272040
columns_to_hide = set()
20282041

2029-
# Check if using custom_table_rates - if so, hide ALL BAU columns
2030-
is_anccr_table = (custom_table == custom_table_rates)
2042+
# Check if using custom_table_rates
2043+
is_rates_table = (custom_table == custom_table_rates)
20312044

2032-
# Extract rate names for ANCCR table headers
2045+
# Extract rate names for rates table headers
20332046
rate_names = []
2034-
if is_anccr_table and scenarios:
2047+
if is_rates_table and scenarios:
20352048
for scenario in scenarios:
20362049
rate_name = scenario.get('full_data', {}).get('inputs', {}).get('ElectricTariff', {}).get('urdb_metadata', {}).get('rate_name', None)
20372050
if rate_name:
20382051
rate_names.append(rate_name)
20392052

2040-
# Loop through BAU columns and check if all numerical values are identical across all BAU columns
2041-
bau_columns = [i for i, header in enumerate(df.columns) if "BAU" in header]
2042-
2043-
# Only proceed if there are BAU columns
2044-
if bau_columns:
2045-
if is_anccr_table:
2046-
# For custom_table_rates, hide ALL BAU columns
2047-
columns_to_hide.update(bau_columns)
2048-
else:
2053+
# For non-rates tables, handle BAU column logic
2054+
if not is_rates_table:
2055+
# Loop through BAU columns and check if all numerical values are identical across all BAU columns
2056+
bau_columns = [i for i, header in enumerate(df.columns) if "BAU" in header]
2057+
2058+
# Only proceed if there are BAU columns
2059+
if bau_columns:
20492060
identical_bau_columns = True # Assume all BAU columns are identical unless proven otherwise
20502061

20512062
# Loop through each row and check the values across BAU columns
@@ -2067,13 +2078,13 @@ def get_combined_format(label, row_color, is_formula=False):
20672078
for col_num in bau_columns[1:]:
20682079
columns_to_hide.add(col_num)
20692080

2070-
# Now set the column properties for hiding BAU columns and leaving others unchanged
2081+
# Now set the column properties - no BAU columns to hide for rates table
20712082
for col_num, header in enumerate(df.columns):
2072-
if "BAU" in header and col_num in columns_to_hide:
2073-
# Hide the BAU columns that have been marked
2083+
if not is_rates_table and "BAU" in header and col_num in columns_to_hide:
2084+
# Hide the BAU columns that have been marked (only for non-rates tables)
20742085
worksheet.set_column(col_num + 1, col_num + 1, column_width, None, {'hidden': True})
20752086
else:
2076-
# Set the normal column width for non-hidden columns
2087+
# Set the normal column width for all columns (rates table has no BAU columns to hide)
20772088
worksheet.set_column(col_num + 1, col_num + 1, column_width)
20782089

20792090
# Write scenario headers
@@ -2083,18 +2094,14 @@ def get_combined_format(label, row_color, is_formula=False):
20832094
non_bau_index = 0
20842095

20852096
for col_num, header in enumerate(df.columns):
2086-
# For custom_table_rates, use rate names for non-BAU column headers
2087-
if is_anccr_table and rate_names:
2088-
if "BAU" not in header:
2089-
# This is a non-BAU column - use rate name as header
2090-
if non_bau_index < len(rate_names):
2091-
header_text = rate_names[non_bau_index]
2092-
else:
2093-
header_text = header
2094-
non_bau_index += 1
2097+
# For custom_table_rates, use rate names for column headers
2098+
if is_rates_table and rate_names:
2099+
# For rates table, all columns are scenario columns - use rate names
2100+
if non_bau_index < len(rate_names):
2101+
header_text = rate_names[non_bau_index]
20952102
else:
2096-
# This is a BAU column - keep original header (will be hidden)
20972103
header_text = header
2104+
non_bau_index += 1
20982105
else:
20992106
header_text = header
21002107

@@ -2168,15 +2175,21 @@ def get_bau_column(col):
21682175
missing_entries = []
21692176

21702177
for col in range(2, len(df.columns) + 2):
2171-
# Skip BAU columns (BAU columns should not have formulas)
2172-
if col % 2 == 0:
2173-
continue # Skip the BAU column
2178+
# For rates table, apply formulas to all columns since there are no BAU columns
2179+
# For other tables, skip BAU columns (every other column)
2180+
if not is_rates_table and col % 2 == 0:
2181+
continue # Skip the BAU column for non-rates tables
21742182

21752183
col_letter = colnum_string(col)
2176-
bau_col = get_bau_column(col) # Get the corresponding BAU column
2177-
bau_col_letter = colnum_string(bau_col) # Convert the column number to letter for Excel reference
2178-
2179-
bau_cells = {cell_name: f'{bau_col_letter}{headers[header] + 2}' for cell_name, header in bau_cells_config.items() if header in headers}
2184+
2185+
# For non-rates tables, get the corresponding BAU column
2186+
if not is_rates_table:
2187+
bau_col = get_bau_column(col) # Get the corresponding BAU column
2188+
bau_col_letter = colnum_string(bau_col) # Convert the column number to letter for Excel reference
2189+
bau_cells = {cell_name: f'{bau_col_letter}{headers[header] + 2}' for cell_name, header in bau_cells_config.items() if header in headers}
2190+
else:
2191+
# For rates table, no BAU cells since we don't have BAU columns
2192+
bau_cells = {}
21802193

21812194
for calc in relevant_calculations:
21822195
try:

0 commit comments

Comments
 (0)