mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
preparing for hubspot upload
This commit is contained in:
parent
61eb2349ba
commit
8012fa4433
3 changed files with 95 additions and 26 deletions
|
|
@ -347,6 +347,8 @@ class AssetList:
|
|||
self.work_type_breakdowns = {}
|
||||
self.flat_data = None
|
||||
self.duplicated_addresses = None
|
||||
self.contact_details = None
|
||||
self.contact_detail_fields = None
|
||||
|
||||
# We detect the presence of the non-intrusive columns
|
||||
self.non_intrusives_present = True if "CIGA Check Required" in self.raw_asset_list.columns else False
|
||||
|
|
@ -1528,7 +1530,70 @@ class AssetList:
|
|||
|
||||
self.flat_data = flat_data
|
||||
|
||||
def prepare_for_crm(self, contact_details, company_domain, crm_pipeline_name, first_dealstage, assigned_surveyors):
|
||||
@staticmethod
|
||||
def split_full_name(x):
|
||||
if pd.isnull(x):
|
||||
return None, None, None
|
||||
x = x.lower()
|
||||
titles = ["mr", "mrs", "ms", "miss", "dr", "prof"]
|
||||
# Remove titles
|
||||
detected_title = [title for title in titles if x.startswith(title)]
|
||||
if detected_title:
|
||||
for title in detected_title:
|
||||
x = x.replace(title, "")
|
||||
x = x.strip()
|
||||
first_name, last_name = x.split(" ")[0], x.split(" ")[-1]
|
||||
title = detected_title[0].title() if detected_title else None
|
||||
return title, first_name.title(), last_name.title()
|
||||
|
||||
def load_contact_details(
|
||||
self,
|
||||
local_filepath,
|
||||
sheet_name,
|
||||
landlord_property_id,
|
||||
phone_number_column=None,
|
||||
email_column=None,
|
||||
fullname_column=None,
|
||||
firstname_column=None,
|
||||
lastname_column=None
|
||||
):
|
||||
|
||||
self.contact_detail_fields = {
|
||||
"landlord_property_id": landlord_property_id,
|
||||
"phone_number": phone_number_column,
|
||||
"email": email_column,
|
||||
"fullname": fullname_column,
|
||||
"firstname": firstname_column,
|
||||
"lastname": lastname_column
|
||||
}
|
||||
|
||||
details_colnames = [
|
||||
phone_number_column, email_column, fullname_column, firstname_column, lastname_column
|
||||
]
|
||||
# We'll fill them
|
||||
none_details = [x for x in details_colnames if x is None]
|
||||
details_colnames = [x for x in details_colnames if x is not None]
|
||||
|
||||
contact_details = pd.read_excel(
|
||||
local_filepath, sheet_name=sheet_name
|
||||
)[[self.contact_detail_fields["landlord_property_id"]] + details_colnames]
|
||||
contact_details = contact_details[
|
||||
~pd.isnull(contact_details[self.contact_detail_fields["landlord_property_id"]])
|
||||
]
|
||||
# Fill anything we don't have
|
||||
for detail in none_details:
|
||||
contact_details[detail] = None
|
||||
|
||||
if fullname_column and not (firstname_column and lastname_column):
|
||||
contact_details["title"], contact_details["first_name"], contact_details["last_name"] = zip(
|
||||
*contact_details[fullname_column].apply(self.split_full_name)
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError("Implement me")
|
||||
|
||||
self.contact_details = contact_details
|
||||
|
||||
def prepare_for_crm(self, company_domain, crm_pipeline_name, first_dealstage, assigned_surveyors):
|
||||
"""
|
||||
This function prepares the data for upload into Hubspot
|
||||
:return:
|
||||
|
|
@ -1589,7 +1654,7 @@ class AssetList:
|
|||
|
||||
# Merge on the contact details
|
||||
programme_data = programme_data.merge(
|
||||
contact_details,
|
||||
self.contact_details,
|
||||
how="left",
|
||||
left_on=self.STANDARD_LANDLORD_PROPERTY_ID,
|
||||
right_on=self.landlord_property_id,
|
||||
|
|
@ -1655,10 +1720,18 @@ class AssetList:
|
|||
schema_mappings = {
|
||||
'Name <LISTING hs_name>': self.DOMNA_PROPERTY_ID, # TODO: Maybe change this?
|
||||
'Company Domain Name <COMPANY domain>': 'Company Domain Name <COMPANY domain>',
|
||||
'Email <CONTACT email>': 'email', # TODO: Review
|
||||
'First Name <CONTACT firstname>': 'first name', # TODO: Review
|
||||
'Last Name <CONTACT lastname>': 'last name', # TODO: Review
|
||||
'Phone <CONTACT phone>': 'phone', # TODO: Review
|
||||
'Email <CONTACT email>': (
|
||||
self.contact_detail_fields["email"] if self.contact_detail_fields["email"] else None
|
||||
), # TODO: Review
|
||||
'First Name <CONTACT firstname>': (
|
||||
self.contact_detail_fields["firstname"] if self.contact_detail_fields["firstname"] else None
|
||||
), # TODO: Review
|
||||
'Last Name <CONTACT lastname>': (
|
||||
self.contact_detail_fields["lastname"] if self.contact_detail_fields["lastname"] else None
|
||||
), # TODO: Review
|
||||
'Phone <CONTACT phone>': (
|
||||
self.contact_detail_fields["phone_number"] if self.contact_detail_fields["phone_number"] else None
|
||||
), # TODO: Review
|
||||
'Full Address <LISTING full_address>': self.STANDARD_FULL_ADDRESS,
|
||||
'Address 1 <LISTING hs_address_1>': self.STANDARD_ADDRESS_1,
|
||||
'Address 2 <LISTING hs_address_2>': None, # TODO: Don't have this for the moment
|
||||
|
|
|
|||
|
|
@ -472,23 +472,23 @@ def app():
|
|||
|
||||
asset_list.flat_analysis()
|
||||
|
||||
# Convert to a format suitable for CRM
|
||||
contact_details = pd.DataFrame(
|
||||
[
|
||||
{
|
||||
asset_list.landlord_property_id: "EXETEMORH0100010",
|
||||
"first name": "Khalim",
|
||||
"last name": "Conn-Kowlessar",
|
||||
"email": "kconnkowlessar@gmail.com",
|
||||
"phone": "075399248"
|
||||
}
|
||||
]
|
||||
asset_list.load_contact_details(
|
||||
local_filepath=os.path.join(data_folder, "Full property list wth D&V report V look up 12.2.25.xlsx"),
|
||||
sheet_name="Report 1",
|
||||
landlord_property_id=asset_list.landlord_property_id,
|
||||
phone_number_column='Property Current Tel. Number',
|
||||
fullname_column='Proeprty Current Occupant',
|
||||
firstname_column=None,
|
||||
lastname_column=None,
|
||||
email_column=None, # TODO - we need this
|
||||
)
|
||||
|
||||
# Convert to a format suitable for CRM
|
||||
# TODO: TEMP
|
||||
assigned_surveyors = pd.DataFrame(
|
||||
[
|
||||
{
|
||||
asset_list.landlord_property_id: "EXETEMORH0100010",
|
||||
asset_list.landlord_property_id: "02610001",
|
||||
"surveyor_name": "Khalim Conn-Kowlessar",
|
||||
"surveyor_email": "khalim@domna.homes",
|
||||
}
|
||||
|
|
@ -501,17 +501,14 @@ def app():
|
|||
crm_pipeline_name = "Survey Management"
|
||||
first_dealstage = "READY TO BEGIN SCHEDULING"
|
||||
# TODO - temp, upload to either SharePoint or AWS
|
||||
hubspot_template = pd.read_csv("~/Downloads/Hubspot Upload Template - Demo V2(Template).csv")
|
||||
hubspot_schema = hubspot_template.columns.tolist()
|
||||
|
||||
asset_list.prepare_for_crm(
|
||||
contact_details=contact_details,
|
||||
assigned_surveyors=assigned_surveyors,
|
||||
company_domain=company_domain,
|
||||
crm_pipeline_name=crm_pipeline_name,
|
||||
first_dealstage=first_dealstage
|
||||
)
|
||||
hubspt_data = asset_list.hubspot_data
|
||||
hubspot_data = asset_list.hubspot_data
|
||||
|
||||
# Store as an excel
|
||||
filename = os.path.join(data_folder, ".".join(data_filename.split(".")[:-1])) + " - Standardised.xlsx"
|
||||
|
|
@ -520,3 +517,6 @@ def app():
|
|||
with pd.ExcelWriter(filename) as writer:
|
||||
asset_list.standardised_asset_list.to_excel(writer, sheet_name="Standardised Asset List", index=False)
|
||||
asset_list.flat_data.to_excel(writer, sheet_name="Flat Data", index=False)
|
||||
|
||||
# Store the Hubspot export as a csv
|
||||
hubspot_data.to_csv(os.path.join(data_folder, "Hubspot Export.csv"), index=False)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
import pandas as pd
|
||||
from backend.Property import Property
|
||||
from utils.s3 import read_from_s3
|
||||
|
||||
from recommendations.recommendation_utils import get_wall_u_value, get_floor_u_value, get_roof_u_value
|
||||
|
||||
from backend.app.config import get_settings
|
||||
import msgpack
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue