(WIP) feat: add result factory for archetype mapping

This commit is contained in:
Majid Rezaei 2024-10-09 12:11:39 -04:00
parent 79edd8f6a2
commit 02d7ecdad4
5 changed files with 1335518 additions and 0 deletions

210241
data/energy_demand_data.csv Normal file

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,10 @@ class SimplifiedBuilding:
self._postal_code = postal_code
self._city = city
self._type = 'building'
self.heating_demand = []
self.cooling_demand = []
self.electricity_demand = []
self.appliance_demand = []
@property
def name(self):

View File

@ -0,0 +1,108 @@
import pandas as pd
class DemandEnricher:
"""
DemandEnricher class to enrich buildings with demand data
"""
def __init__(self, archetype_demand_file):
self.archetype_demand_file = archetype_demand_file
self.archetype_df = pd.read_csv(self.archetype_demand_file, encoding='latin1')
self.fix_type_of_building_encoding()
self.create_archetype_demands_dict()
self.create_function_mapping()
def fix_type_of_building_encoding(self):
def fix_encoding(text):
if isinstance(text, str):
try:
return text.encode('latin1').decode('utf-8')
except UnicodeEncodeError:
return text
return text
self.archetype_df['Type_of_building'] = self.archetype_df['Type_of_building'].apply(fix_encoding)
def create_archetype_demands_dict(self):
self.archetype_demands = {}
for archetype in self.archetype_df['Type_of_building'].unique():
df = self.archetype_df[self.archetype_df['Type_of_building'] == archetype]
self.archetype_demands[archetype] = df.reset_index(drop=True)
def create_function_mapping(self):
self.function_mapping = {
'residential': 'Maison Unifamiliale',
'single family house': 'Maison Unifamiliale',
'multifamily house': 'Apartements partie 3 du code',
'medium office': 'Bureaux',
'office and administration': 'Bureaux',
'commercial': 'Commercial attaché',
'warehouse': 'Commercial détaché',
'restaurant': 'Commercial attaché',
'hotel': 'Commercial attaché'
}
def get_vintage_range(self, year):
if year <= 1947:
return 'avant 1947'
elif 1947 < year <= 1983:
return '1947-1983'
elif 1983 < year <= 2010:
return '1984-2010'
elif year > 2010:
return 'après 2010'
else:
return None
def enrich_city(self, city):
for building in city.buildings:
if (building.year_of_construction is not None and
building.function is not None and
building.total_floor_area is not None):
building_function_lower = building.function.lower()
mapped_function = None
for key in self.function_mapping:
if key in building_function_lower:
mapped_function = self.function_mapping[key]
break
if mapped_function:
vintage_range = self.get_vintage_range(building.year_of_construction)
if vintage_range:
type_of_building = f"{mapped_function} {vintage_range}"
if type_of_building in self.archetype_demands:
demands_df = self.archetype_demands[type_of_building]
total_floor_area = building.total_floor_area
demands_df['Heating_total'] = demands_df['Heating'] * total_floor_area
demands_df['Cooling_total'] = demands_df['Cooling'] * total_floor_area
demands_df['Equipment_total'] = demands_df['Equipment'] * total_floor_area
demands_df['Lighting_total'] = demands_df['Lighting'] * total_floor_area
building.heating_demand = demands_df['Heating_total'].tolist()
building.cooling_demand = demands_df['Cooling_total'].tolist()
building.electricity_demand = demands_df['Lighting_total'].tolist()
building.appliance_demand = demands_df['Equipment_total'].tolist()
else:
building.heating_demand = []
building.cooling_demand = []
building.electricity_demand = []
building.appliance_demand = []
else:
building.heating_demand = []
building.cooling_demand = []
building.electricity_demand = []
building.appliance_demand = []
else:
building.heating_demand = []
building.cooling_demand = []
building.electricity_demand = []
building.appliance_demand = []
else:
building.heating_demand = []
building.cooling_demand = []
building.electricity_demand = []
building.appliance_demand = []

View File

@ -1,10 +1,12 @@
from hub.imports.geometry_factory import GeometryFactory
from hub.helpers.dictionaries import Dictionaries
from hub.imports.results.archetype_based_demand import DemandEnricher
import os
import psycopg2
import csv
input_file = "data/cmm_points_function_vintage_surface.csv"
output_file = "output_buildings.csv"
# Initialize city object from GeometryFactory
city = GeometryFactory(
@ -17,3 +19,10 @@ city = GeometryFactory(
function_to_hub=Dictionaries().montreal_function_to_hub_function,
total_floor_area_field="supfi_etag"
).city
demand_enricher = DemandEnricher('./data/energy_demand_data.csv')
# Enrich the city object
demand_enricher.enrich_city(city)
print("done")

1125156
output_buildings.csv Normal file

File diff suppressed because it is too large Load Diff