From cc07706fc124899d06d66bb220a829bfcc22597e Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Mon, 14 Apr 2025 15:47:35 +0000 Subject: [PATCH] merge pdf works now --- etl/hubspot_to_invoice.py | 6 ++++-- etl/surveyPrice/surveyPrice.py | 37 ++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/etl/hubspot_to_invoice.py b/etl/hubspot_to_invoice.py index 9bee806..3c3e2fe 100644 --- a/etl/hubspot_to_invoice.py +++ b/etl/hubspot_to_invoice.py @@ -13,5 +13,7 @@ from etl.surveyPrice.surveyPrice import SurveyPrice sp = SurveyPrice() sp.get_cavity_pricing_table("JJC - EMPTIES") -df = sp.get_all_surveys_from_hubspot() -df = sp.get_all_surveyed_data_from_sharepoint() \ No newline at end of file +hubspot_df = sp.get_all_surveys_from_hubspot() +sharepoint_df = sp.get_all_surveyed_data_from_sharepoint() + +df = sp.merge_hub_spot_and_survey_information() \ No newline at end of file diff --git a/etl/surveyPrice/surveyPrice.py b/etl/surveyPrice/surveyPrice.py index 7e437f0..dd8c45e 100644 --- a/etl/surveyPrice/surveyPrice.py +++ b/etl/surveyPrice/surveyPrice.py @@ -12,6 +12,7 @@ class SurveyPrice(): self.warmfront_sharepoint_client = SharePointScraper(SharePointInstaller.WARMFRONT) self.master_rate_card_path = None self.all_hubspot_submissions = None + self.all_survey_info_from_sharepoint = None self.download_price_card() self.required_sheets = [ 'JJC - EMPTIES', @@ -103,7 +104,8 @@ class SurveyPrice(): return self.all_hubspot_submissions def get_all_surveyed_data_from_sharepoint(self): - self.sharepoint_data_for_jjc() + self.all_survey_info_from_sharepoint = self.sharepoint_data_for_jjc() + return self.all_survey_info_from_sharepoint def sharepoint_data_for_jjc(self): jjc_sp = SharePointScraper(SharePointInstaller.JJC, development=True) @@ -117,13 +119,14 @@ class SurveyPrice(): all_survey_info = [] for surveyInfo in jjc_surveys: info = { - "SHAREPOINT INSTALLER": "J & J Crumps", + "SHAREPOINT INSTALLER": "J & J CRUMP", "SHAREPOINT PRE_SITE_NOTES FOUND": True if surveyInfo.pre_site_note else False, "SHAREPOINT CSR FOUND": True if surveyInfo.csr else False, "SHAREPOINT TOTAL_FLOOR_AREA": "NO PRE SITE NOTES FOUND", "SHAREPOINT FLOOR_AREA_BANDING": "NO PRE SITE NOTES FOUND", "SHAREPOINT PRE_INSTALL_SAP_SCORE": "NO PRE SITE NOTES FOUND", "SHAREPOINT INSULATION MATERIAL": None, + "SHAREPOINT ADDRESS": address } if surveyInfo.pre_site_note: @@ -139,10 +142,36 @@ class SurveyPrice(): "SHAREPOINT INSULATION MATERIAL": surveyInfo.get_insulation_info(), }) + all_survey_info.append(info) - return jjc_surveys + return pd.DataFrame(all_survey_info) + + def merge_hub_spot_and_survey_information(self): + if self.all_survey_info_from_sharepoint is None: + raise RuntimeError("No survey information found from Sharepoint") + if self.all_hubspot_submissions is None: + raise RuntimeError("No information found from Hubspot") + + self.all_survey_info_from_sharepoint['clean_address'] = self.all_survey_info_from_sharepoint['SHAREPOINT ADDRESS'].apply( + lambda x: x.lower().replace(',', '').strip() + ) + + self.all_hubspot_submissions['clean_address'] = self.all_hubspot_submissions['HUBSPOT_DEAL_ADDRESS'].apply( + lambda x: x.lower().replace(',', '').strip() + ) + + merged_df = pd.merge( + self.all_survey_info_from_sharepoint, + self.all_hubspot_submissions, + left_on=['clean_address', 'SHAREPOINT INSTALLER'], + right_on=['clean_address', 'HUBSPOT_INSTALLER'], + how='inner' + ) + + merged_df.drop(columns=['clean_address'], inplace=True) + + return merged_df -