diff --git a/etl/hubspot_to_invoice.py b/etl/hubspot_to_invoice.py index cea0653..bc3d466 100644 --- a/etl/hubspot_to_invoice.py +++ b/etl/hubspot_to_invoice.py @@ -11,4 +11,4 @@ from etl.surveyPrice.surveyPrice import SurveyPrice sp = SurveyPrice() -sp.get_price_card() \ No newline at end of file +sp.get_cavity_pricing_table("JJC_EMPTIES") \ No newline at end of file diff --git a/etl/surveyPrice/surveyPrice.py b/etl/surveyPrice/surveyPrice.py index a23088e..81dbcdf 100644 --- a/etl/surveyPrice/surveyPrice.py +++ b/etl/surveyPrice/surveyPrice.py @@ -10,7 +10,7 @@ class SurveyPrice(): self.sharepoint_client = SharePointScraper(SharePointInstaller.WARMFRONT) self.master_rate_card_path = None self.download_price_card() - self.sheet_names = [ + self.required_sheets = [ 'JJC - EMPTIES', 'JJC - GENERAL EXTRACTIONS', 'JJC - FORMALDEHYDE EXTRACTION', @@ -36,14 +36,49 @@ class SurveyPrice(): return self.master_rate_card_path - def get_price_card(self): + def get_cavity_pricing_table(self, sheet_name): excel_file = pd.ExcelFile(self.master_rate_card_path) - return excel_file.sheet_names + available_sheets = excel_file.sheet_names + missing_sheets = [sheet for sheet in self.required_sheets if sheet not in available_sheets] + + if missing_sheets: + raise ValueError(f"Missing sheets: {missing_sheets}") + + pricing_table = self.get_price_matrix(sheet_name) + + return pricing_table def get_master_rate_card_path(self): - return self.master_rate_card_path() + return self.master_rate_card_path + def get_price_matrix(self, sheet_name): + df = pd.read_excel(self.master_rate_card_path, sheet_name) + + columns_to_check = { + "no extractors or ventilation required": {"Trickle Vent": 0, "wetrooms": 0}, + "Trickle Vents ONLY": {"Trickle Vent": 1, "wetrooms": 0}, + "1 wet room extractor required": {"Trickle Vent": 0, "wetrooms": 1}, + "2 wet room extractor required": {"Trickle Vent": 0, "wetrooms": 2}, + "3 wet room extractor required": {"Trickle Vent": 0, "wetrooms": 3}, + 'Trickle Vents + 1 wet room extractor': {"Trickle Vent": 1, "wetrooms": 1}, + 'Trickle Vents + 2 wet room extractor': {"Trickle Vent": 1, "wetrooms": 2}, + 'Trickle Vents + 3 wet room extractor': {"Trickle Vent": 1, "wetrooms": 3}, + } + + pricing_table = [] + for _, row in df.iterrows(): + for key, variables in columns_to_check.items(): + pricing_table.append( + { + "funding": row["Funding"], + "floor_area_group": row["Total Floor Area"][:-1], + **variables, + "price": row[key][1:] if row[key] != "Not viable" else None, + } + ) + pricing_table = pd.DataFrame(pricing_table) + return pricing_table diff --git a/etl/tests/test_survey_price.py b/etl/tests/test_survey_price.py new file mode 100644 index 0000000..e6773d5 --- /dev/null +++ b/etl/tests/test_survey_price.py @@ -0,0 +1,13 @@ +import os +# WarmFront Sharepoint KEYS +os.environ["SHAREPOINT_CLIENT_ID"] = "895e3b77-b1d7-43ec-b18f-dcfe07cdfeaf" +os.environ["SHAREPOINT_CLIENT_SECRET"] = "SOf8Q~-is4wdQiqvEEm9FlJQRAY9ELGaj5Qz-a6E" +os.environ["SHAREPOINT_TENANT_ID"] = "c3f7519c-2719-4547-af04-6da6cbfd8f8f" + +from etl.surveyPrice.surveyPrice import SurveyPrice + +def test_get_price_matrix_jjc_empties(): + sp = SurveyPrice + jjc_empties_price_table = sp.get_cavity_pricing_table("JJC - EMPTIES") + +