diff --git a/backend/src/dashboard/scripts/quick_one.py b/backend/src/dashboard/scripts/quick_one.py index 0c8a18c..d6d1342 100644 --- a/backend/src/dashboard/scripts/quick_one.py +++ b/backend/src/dashboard/scripts/quick_one.py @@ -5,9 +5,6 @@ s3 = FileManager() key, path, data = s3.download_and_read_latest() hubspot_data = jsonReader(data) - -counter, deals = hubspot_data.generate_solar_numbers_df() - -counter -deals +df = hubspot_data.generate_df_via_product_type("Empty Cavity - ECO4") +df diff --git a/backend/src/dashboard/services/hubspot_client_async.py b/backend/src/dashboard/services/hubspot_client_async.py index 19bf826..f8b8f45 100644 --- a/backend/src/dashboard/services/hubspot_client_async.py +++ b/backend/src/dashboard/services/hubspot_client_async.py @@ -273,6 +273,7 @@ class HubSpotClientAsync: "outcome_surveyor", "submission_date", "expected_commencement_date", + "attempt_type", ] ) diff --git a/backend/src/dashboard/services/json_reader.py b/backend/src/dashboard/services/json_reader.py index fa75404..6935cb4 100644 --- a/backend/src/dashboard/services/json_reader.py +++ b/backend/src/dashboard/services/json_reader.py @@ -1,5 +1,7 @@ from pprint import pprint from collections import defaultdict +import pandas as pd + @@ -29,18 +31,32 @@ class jsonReader: self.deals_by_line_item[name].append(deal) self.line_item_names = list(self.deals_by_line_item.keys()) - def generate_empty_cavity_numbers_df(self): - count=0 - for deals in self.deals_by_line_item["Empty Cavity - ECO4"]: - count +=1 + def generate_df_via_product_type(self, product_type): + rows = [] + for deals in self.deals_by_line_item[product_type]: if deals['attempts'] != []: - return count, deals - return count, deals + row = self._return_df_from_deal_info(deals, product_type) + rows.append(row) + + if rows: + return pd.concat(rows, ignore_index=True) + else: + return + + + def _return_df_from_deal_info(self, deal, product_type): + print(deal) + data = { + "submission_date": deal.get("submission_date", None), + "expected_commencement_date": deal.get("expected_commencement_date", None), + "work_type": product_type, + "price": next( + (item["price"] for item in deal["line_items"] if product_type in item["name"]), + None + ) + } + return pd.DataFrame([data]) - def _return_df_from_deal_info(self, deal): - - pass - def find_all_job_with_line_item(self): for i, deal in enumerate(self.raw_data): if len(deal["line_items"])>0: