From af13467c2c4c9b7fc98e5be1e343399f57c062fb Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 6 Mar 2024 20:04:37 +0000 Subject: [PATCH] Added gbis variance checks --- .../ha_15_32/ha_analysis_batch_3.py | 83 ++++++++----------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/etl/eligibility/ha_15_32/ha_analysis_batch_3.py b/etl/eligibility/ha_15_32/ha_analysis_batch_3.py index 7859d6d2..553f6271 100644 --- a/etl/eligibility/ha_15_32/ha_analysis_batch_3.py +++ b/etl/eligibility/ha_15_32/ha_analysis_batch_3.py @@ -3237,6 +3237,7 @@ def forecast_remaining_sales(loader): results = [] for ha_name, input_data in loader.data.items(): + # Original warmfront figures - ECO4 original_warmfront_estimates = december_figures[december_figures["HA Name"] == ha_name] @@ -3280,50 +3281,6 @@ def forecast_remaining_sales(loader): asset_list_remaining = asset_list_remaining[pd.isnull(asset_list_remaining["installation_status"])] asset_list_remaining = asset_list_remaining.drop(columns=["installation_status"]) - # TODO: TEMP - # n_pre_ciga = asset_list[ - # asset_list["ECO Eligibility"].isin( - # [ - # "eco4 - passed ciga", - # "eco4 (subject to ciga)", - # "failed ciga", - # "eco4" - # ] - # ) - # ].shape[0] - # - # n_pre_ciga_remaining = asset_list_remaining[ - # asset_list_remaining["ECO Eligibility"].isin( - # [ - # "eco4 - passed ciga", - # "eco4 (subject to ciga)", - # "failed ciga", - # "eco4" - # ] - # ) - # ].shape[0] - # - # compare_to_ids = asset_list_remaining["asset_list_row_id"].values - # assets_diff_ids = [x for x in asset_list["asset_list_row_id"].values if x not in compare_to_ids] - # diff = asset_list[asset_list["asset_list_row_id"].isin(assets_diff_ids)] - # - # n_sold = survey_list[survey_list["installation_status"].str.contains("ECO4")].shape[0] - # # cancellations = survey_list[] - # asset_list["ECO Eligibility"].value_counts() - # - # # Revenenue - # pre_ciga_revenue = n_pre_ciga * eco4_rate - # pre_ciga_remaining_revenue = n_pre_ciga_remaining * eco4_rate - # sold_revenue = n_sold * eco4_rate - # - # pre_ciga_revenue - (pre_ciga_remaining_revenue + sold_revenue) - # # MISSING 1 SALE from sold - # cancelled = survey_list[survey_list["installation_status"].str.contains("ECO4")].shape[0] - # dupes = survey_list[survey_list["asset_list_row_id"].duplicated()]["asset_list_row_id"].values - # z = survey_list[survey_list["asset_list_row_id"].isin(dupes)] - # z[['NO.', 'Street / Block Name', 'Post Code', 'INSTALLED OR CANCELLED', 'SUBMISSION DATE']] - # # TODO: END TEMP - eligiblity_counts = pd.DataFrame(asset_list["ECO Eligibility"].value_counts()).reset_index() eligiblity_counts_remaining = pd.DataFrame(asset_list_remaining["ECO Eligibility"].value_counts()).reset_index() @@ -3525,6 +3482,35 @@ def forecast_remaining_sales(loader): if variance_remaining != 0: raise ValueError("Something went wrong in variance remaining") + # We also check variances to make sure that the pre-CIGA ECO4 total equals + # 1) Pre CIGA remaining + + # 2) ECO4 sold + + # 3) ECO4 confirmed cancellations + + # 4) ECO4 unconfirmed cancellations + + pre_ciga_eco4_variance = ( + eco4_pre_ciga_revenue - + eco4_pre_ciga_remaining_revenue - + eco4_actually_sold - + eco4_confirmed_cancellations * eco4_rate - + eco4_expected_cancellations * eco4_rate + ) + + if pre_ciga_eco4_variance != 0: + raise ValueError("Something went wrong in pre_ciga_eco4_variance") + + # Check GBIS total variance + gbis_variance = ( + gbis_total_revenue - + gbis_actually_sold - + gbis_confirmed_cancellations * gbis_rate - + gbis_expected_cancellations * gbis_rate - + gbis_remaining_revenue + ) + + if gbis_variance != 0: + raise ValueError("Something went wrong in gbis_variance") + to_append = { ("", "", "", "HA Name"): ha_name, # ECO4 - original warmfront figures @@ -3544,8 +3530,10 @@ def forecast_remaining_sales(loader): ("ECO4 pre-ciga", "", "Remaining - #", ""): eco4_pre_ciga_remaining, ("ECO4 pre-ciga", "", "Total - £", ""): eco4_pre_ciga_revenue, ("ECO4 pre-ciga", "", "Remaining - £", ""): eco4_pre_ciga_remaining_revenue, - ("ECO4 pre-ciga", "", "VARIANCE - TOTAL", ""): variance_total, - ("ECO4 pre-ciga", "", "VARIANCE - REMAINING", ""): variance_remaining, + ("ECO4 pre-ciga", "", "VARIANCE - PRE-CIGA ECO4 TOTAL", ""): pre_ciga_eco4_variance, + ("ECO4 pre-ciga", "", "VARIANCE - PRE-CIGA ECO4 TOTAL VS ELIGIBLE & INELIGIBLE", ""): variance_total, + ("ECO4 pre-ciga", "", "VARIANCE - PRE-CIGA ECO4 REMAINING VS ELIGIBLE & INELIGIBLE", ""): + variance_remaining, ("ECO4 pre-ciga", "", "Sold - £", ""): eco4_actually_sold, ("ECO4 pre-ciga", "", "Confirmed cancellations - £", ""): eco4_confirmed_cancellations * eco4_rate, # This is for jobs that are in-progress and could still cancel @@ -3600,6 +3588,7 @@ def forecast_remaining_sales(loader): # GBIS postcode list ("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", "Warmfront post code list", "GBIS VARIANCE", "GBIS total"): gbis_variance, ("GBIS Postcode list", "Warmfront post code list", "Sold - £", "GBIS total"): gbis_actually_sold, ("GBIS Postcode list", "", "Confirmed cancellations - £", ""): gbis_confirmed_cancellations * gbis_rate, # This is for jobs that are in-progress and could still cancel @@ -3611,7 +3600,7 @@ def forecast_remaining_sales(loader): } # Make sure nothing is forgotten due to duplicate multi-index keys - if len(to_append) != 45: + if len(to_append) != 47: raise ValueError("Something went wrong") results.append(to_append)