mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
be the same as main
This commit is contained in:
parent
ef366f1cd5
commit
9c1181475e
1 changed files with 22 additions and 28 deletions
|
|
@ -26,14 +26,15 @@ def has_solar_with_battery(materials_list: Optional[List[Dict[str, Any]]]) -> bo
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for m in materials_list or []:
|
for m in materials_list or []:
|
||||||
if m.get("type") == "solar_pv" and m.get("includes_battery") is True:
|
if (
|
||||||
|
m.get("type") == "solar_pv"
|
||||||
|
and m.get("includes_battery") is True
|
||||||
|
):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def process_export(
|
def process_export(payload: ExportRequest, session: Session) -> Dict[Union[str, int], pd.DataFrame]:
|
||||||
payload: ExportRequest, session: Session
|
|
||||||
) -> Dict[Union[str, int], pd.DataFrame]:
|
|
||||||
export_files: Dict[Union[str, int], pd.DataFrame] = {}
|
export_files: Dict[Union[str, int], pd.DataFrame] = {}
|
||||||
|
|
||||||
db_methods = DbMethods(session)
|
db_methods = DbMethods(session)
|
||||||
|
|
@ -51,9 +52,7 @@ def process_export(
|
||||||
logger.info("Retrieved %s plans for export", len(plans_df))
|
logger.info("Retrieved %s plans for export", len(plans_df))
|
||||||
|
|
||||||
if plans_df.empty:
|
if plans_df.empty:
|
||||||
logger.info(
|
logger.info("Empty plans dataframe - no plans to export. Returning empty export.")
|
||||||
"Empty plans dataframe - no plans to export. Returning empty export."
|
|
||||||
)
|
|
||||||
return export_files
|
return export_files
|
||||||
plan_ids: List[int] = plans_df["id"].tolist()
|
plan_ids: List[int] = plans_df["id"].tolist()
|
||||||
recommendations_df: pd.DataFrame = db_methods.get_recommendations(plan_ids)
|
recommendations_df: pd.DataFrame = db_methods.get_recommendations(plan_ids)
|
||||||
|
|
@ -62,12 +61,13 @@ def process_export(
|
||||||
|
|
||||||
recommendations_df = db_methods.attach_materials(recommendations_df)
|
recommendations_df = db_methods.attach_materials(recommendations_df)
|
||||||
|
|
||||||
recommendations_df["has_solar_with_battery"] = recommendations_df[
|
recommendations_df["has_solar_with_battery"] = (
|
||||||
"materials"
|
recommendations_df["materials"].apply(has_solar_with_battery)
|
||||||
].apply(has_solar_with_battery)
|
)
|
||||||
|
|
||||||
_filter = (recommendations_df["measure_type"] == "solar_pv") & (
|
_filter = (
|
||||||
recommendations_df["has_solar_with_battery"]
|
(recommendations_df["measure_type"] == "solar_pv")
|
||||||
|
& (recommendations_df["has_solar_with_battery"])
|
||||||
)
|
)
|
||||||
|
|
||||||
recommendations_df.loc[_filter, "measure_type"] = (
|
recommendations_df.loc[_filter, "measure_type"] = (
|
||||||
|
|
@ -83,13 +83,10 @@ def process_export(
|
||||||
else:
|
else:
|
||||||
scenario_recs = recommendations_df[
|
scenario_recs = recommendations_df[
|
||||||
recommendations_df["scenario_id"] == group_key
|
recommendations_df["scenario_id"] == group_key
|
||||||
]
|
]
|
||||||
|
|
||||||
if scenario_recs.empty:
|
if scenario_recs.empty:
|
||||||
logger.info(
|
logger.info("No recommendations found for group_key %s - skipping export for this group", group_key)
|
||||||
"No recommendations found for group_key %s - skipping export for this group",
|
|
||||||
group_key,
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
measures_df: pd.DataFrame = scenario_recs[
|
measures_df: pd.DataFrame = scenario_recs[
|
||||||
|
|
@ -102,12 +99,14 @@ def process_export(
|
||||||
values="estimated_cost",
|
values="estimated_cost",
|
||||||
).reset_index()
|
).reset_index()
|
||||||
|
|
||||||
pivot["total_retrofit_cost"] = pivot.drop(
|
pivot["total_retrofit_cost"] = (
|
||||||
columns=["property_id", "plan_name"]
|
pivot.drop(columns=["property_id", "plan_name"]).sum(axis=1)
|
||||||
).sum(axis=1)
|
)
|
||||||
|
|
||||||
post_sap: pd.DataFrame = (
|
post_sap: pd.DataFrame = (
|
||||||
scenario_recs.groupby("property_id")[["sap_points"]].sum().reset_index()
|
scenario_recs.groupby("property_id")[["sap_points"]]
|
||||||
|
.sum()
|
||||||
|
.reset_index()
|
||||||
)
|
)
|
||||||
|
|
||||||
df: pd.DataFrame = (
|
df: pd.DataFrame = (
|
||||||
|
|
@ -118,9 +117,7 @@ def process_export(
|
||||||
|
|
||||||
df["sap_points"] = df["sap_points"].fillna(0)
|
df["sap_points"] = df["sap_points"].fillna(0)
|
||||||
df["predicted_post_works_sap"] = df["current_sap_points"] + df["sap_points"]
|
df["predicted_post_works_sap"] = df["current_sap_points"] + df["sap_points"]
|
||||||
df["predicted_post_works_epc"] = df["predicted_post_works_sap"].apply(
|
df["predicted_post_works_epc"] = df["predicted_post_works_sap"].apply(sap_to_epc)
|
||||||
sap_to_epc
|
|
||||||
)
|
|
||||||
|
|
||||||
export_files[group_key] = df
|
export_files[group_key] = df
|
||||||
|
|
||||||
|
|
@ -131,10 +128,7 @@ def process_export(
|
||||||
# Lambda Handler
|
# Lambda Handler
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
def handler(event: Mapping[str, Any], context: Optional[Any]) -> Mapping[str, Union[int, str]]:
|
||||||
def handler(
|
|
||||||
event: Mapping[str, Any], context: Optional[Any]
|
|
||||||
) -> Mapping[str, Union[int, str]]:
|
|
||||||
"""
|
"""
|
||||||
Example event:
|
Example event:
|
||||||
body_dict = {
|
body_dict = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue