diff --git a/model_data/app.py b/model_data/app.py index 8c1fddf5..bad4b303 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -114,15 +114,10 @@ def handler(): for p in input_properties: p.get_components(cleaner) + # TODO: Add property age band into this uvalue_estimates = UvalueEstimations(data=data) uvalue_estimates.get_estimates(cleaner=cleaner) - # Now, given the components, we want to idenfity upgrade options - import pandas as pd - floors_df = pd.DataFrame( - [{"address1": p.address1, **p.floor} for p in input_properties] - ) - input_properties[4].data["address1"] input_properties[4].data["postcode"] floors_df["address1"].values[4] @@ -136,8 +131,15 @@ def handler(): df["property-type"].unique() from model_data.recommendations.WallRecommendations import WallRecommendations + all_res = [] + for p in input_properties: + inst = WallRecommendations(property_instance=p, uvalue_estimates=uvalue_estimates) + inst.recommend() + n_recs = len(inst.recommendations) + all_res.append(n_recs) + self = WallRecommendations(property_instance=input_properties[2], uvalue_estimates=uvalue_estimates) - input_properties[2].walls + input_properties[6].walls self.recommend() df = pd.DataFrame(self.recommendations[0]["parts"]) recommendations = pd.DataFrame(self.recommendations) diff --git a/model_data/plotting/__init__.py b/model_data/plotting/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/model_data/plotting/plotting_functions.py b/model_data/plotting/plotting_functions.py new file mode 100644 index 00000000..049ba248 --- /dev/null +++ b/model_data/plotting/plotting_functions.py @@ -0,0 +1,40 @@ +import pandas as pd +import seaborn as sns +import matplotlib.pyplot as plt + + +def create_heatmap_plots(data, response_var, pivot_var1, pivot_var2, order1=None, order2=None): + """ + Create a heatmap plot based on a list of data and given variables. + + :param data: List of dictionaries, input data. + :param response_var: String, response variable to be plotted. + :param pivot_var1: String, first pivot variable to be used in the plot. + :param pivot_var2: String, second pivot variable to be used in the plot. + :param order1: List, the order of categories for pivot_var1. Optional. + :param order2: List, the order of categories for pivot_var2. Optional. + + Returns: + None. Displays the generated plot. + """ + + # Create a DataFrame from your list of dictionaries + df = pd.DataFrame(data) + + # Convert the response variable column to float type if it's not already + df[response_var] = df[response_var].astype(float) + + # Create a pivot table + pivot = df.pivot_table(index=pivot_var1, columns=pivot_var2, values=response_var) + + # If an order is provided, reorder the pivot table + if order1 is not None: + pivot = pivot.reindex(order1) + if order2 is not None: + pivot = pivot[order2] + + # Plot the heatmap + plt.figure(figsize=(10, 6)) + sns.heatmap(pivot, annot=True, fmt=".2f", cmap='coolwarm') + plt.title(f"Heatmap of {response_var} by {pivot_var1} and {pivot_var2}") + plt.show() diff --git a/model_data/recommendations/WallRecommendations.py b/model_data/recommendations/WallRecommendations.py index 61a1878a..aaeb777a 100644 --- a/model_data/recommendations/WallRecommendations.py +++ b/model_data/recommendations/WallRecommendations.py @@ -291,6 +291,9 @@ class WallRecommendations(BaseUtility): self.find_insulation(u_value) return + # If the u-value is within regulations, we don't do anything + return + raise NotImplementedError("Not implemented yet") def _find_insulation(self, parts, u_value): diff --git a/model_data/requirements.txt b/model_data/requirements.txt index a0efa457..c4fbd083 100644 --- a/model_data/requirements.txt +++ b/model_data/requirements.txt @@ -13,4 +13,5 @@ dbfread pyproj pint geopandas -mip \ No newline at end of file +mip +seaborn \ No newline at end of file