Added totals percentages aggregations

This commit is contained in:
Khalim Conn-Kowlessar 2024-03-01 21:33:45 +00:00
parent 028c2edce7
commit 721bfb19fc

View file

@ -2965,6 +2965,14 @@ def forecast_remaining_sales(loader):
gbis_remaining = int(np.round(gbis_remaining * ha_gbis_sale_conversion))
gbis_remaining_revenue = int(gbis_remaining * gbis_rate)
# GBIS delta
if original_warmfront_gbis == 0:
gbis_delta_vs_original_estimate = 100 * gbis_total
else:
gbis_delta_vs_original_estimate = 100 * (
gbis_total - original_warmfront_gbis
) / original_warmfront_gbis
to_append = {
("", "", "", "HA Name"): ha_name,
# ECO4 - original warmfront figures
@ -2987,7 +2995,7 @@ def forecast_remaining_sales(loader):
"ECO4 - post CIGA - #"],
("ECO4 post-ciga", "", "Estimated total eligible - £", ""): eco4_post_ciga_total_results[
"ECO4 - post CIGA - £"],
("ECO4 post-ciga", "", "Delta vs original estimate", ""): eco4_delta_vs_original_estimate,
("ECO4 post-ciga", "", "Delta vs original estimate - %", ""): eco4_delta_vs_original_estimate,
# ECO4 - asset list, post ciga, remaining
("ECO4 post-ciga", "", "Estimated remaining eligible - #", ""): eco4_post_ciga_remaining_results[
"ECO4 - post CIGA - #"],
@ -3021,14 +3029,15 @@ def forecast_remaining_sales(loader):
"Estimated CIGA failures - £"
],
# GBIS postcode list
("", "Warmfront post code list", "Total - #", "GBIS total"): gbis_total,
("", "Warmfront post code list", "Remaining - #", "GBIS total"): gbis_remaining,
("", "Warmfront post code list", "Total - £", "GBIS total"): gbis_total_revenue,
("", "Warmfront post code list", "Remaining - £", "GBIS total"): gbis_remaining_revenue,
("GBIS Postcode list", "Warmfront post code list", "Total - #", "GBIS total"): gbis_total,
("GBIS Postcode list", "Warmfront post code list", "Total - £", "GBIS total"): gbis_total_revenue,
("GBIS Postcode list", "", "Delta vs original estimate - %", ""): gbis_delta_vs_original_estimate,
("GBIS Postcode list", "Warmfront post code list", "Remaining - #", "GBIS total"): gbis_remaining,
("GBIS Postcode list", "Warmfront post code list", "Remaining - £", "GBIS total"): gbis_remaining_revenue,
}
# Make sure nothing is forgotten due to duplicate multi-index keys
if len(to_append) != 32:
if len(to_append) != 33:
raise ValueError("Something went wrong")
results.append(to_append)
@ -3039,11 +3048,31 @@ def forecast_remaining_sales(loader):
for col in results.columns:
if col == ('', '', '', 'HA Name'):
totals_row[col] = "Total"
elif col == ("ECO4 post-ciga", "", "Delta vs original estimate", ""):
totals_row[col] = results[col].mean()
elif col in [
("ECO4 post-ciga", "", "Delta vs original estimate - %", ""),
("GBIS Postcode list", "", "Delta vs original estimate - %", "")
]:
totals_row[col] = None
else:
totals_row[col] = results[col].sum()
# For the delta columns, we calculate the delta on the totals
totals_row[("ECO4 post-ciga", "", "Delta vs original estimate - %", "")] = round(
100 * (
totals_row[("ECO4 post-ciga", "", "Estimated total eligible - #", "")] -
totals_row[("", "Original Warmfront estimate", "Total - #", "ECO4 - November")]
) / totals_row[("", "Original Warmfront estimate", "Total - #", "ECO4 - November")],
1
)
totals_row[("GBIS Postcode list", "", "Delta vs original estimate - %", "")] = round(
100 * (
totals_row[("GBIS Postcode list", "Warmfront post code list", "Total - #", "GBIS total")] -
totals_row[("", "Original Warmfront estimate", "Total - #", "GBIS - November")]
) / totals_row[("", "Original Warmfront estimate", "Total - #", "GBIS - November")],
1
)
blank_row = pd.DataFrame([{col: "" for col in results.columns}])
# Put together a Warmfront original remaining ECO4 vs asset list remaining ECO4 and same for GBIS, as well as totals
@ -3204,10 +3233,35 @@ def forecast_remaining_sales(loader):
]
results = pd.concat(
[results, pd.DataFrame([headlines]), pd.DataFrame([totals_row]), blank_row, blank_row,
pd.DataFrame(assumptions)]
[
results,
pd.DataFrame([totals_row]),
pd.DataFrame(headlines),
blank_row,
blank_row,
pd.DataFrame(assumptions)
]
)
# header_rows = [
# [name[0] for name in results.columns.values],
# [name[1] for name in results.columns.values],
# [name[2] for name in results.columns.values],
# [name[3] for name in results.columns.values]
# ]
# Step 2: Write the transformed header and DataFrame data to CSV.
# Open the file in write mode.
import csv
with open("HA Remaining Analysis.csv", "w", newline="") as file:
# writer = csv.writer(file)
# Write the header rows.
# writer.writerows(header_rows)
# Write the DataFrame data without the index (adjust if you want the index).
results.to_csv(file, header=True, index=False)
def app():
"""