from hub.imports.geometry_factory import GeometryFactory from hub.helpers.dictionaries import Dictionaries from hub.imports.results.archetype_based_demand import DemandEnricher import urllib.parse input_file = "data/cmm_points_function_vintage_surface.csv" output_file = "output_buildings.csv" # Database credentials db_username = 'postgres' db_password = '' db_host = 'localhost' db_port = '5432' db_name = 'energydemanddb' # URL-encode username and password db_username_encoded = urllib.parse.quote_plus(db_username) db_password_encoded = urllib.parse.quote_plus(db_password) # Construct the database connection URL database_url = f'postgresql://{db_username_encoded}:{db_password_encoded}@{db_host}:{db_port}/{db_name}' # Initialize city object from GeometryFactory city = GeometryFactory( file_type="csv", path=input_file, centroid_x_field="centroid_x", centroid_y_field="centroid_y", year_of_construction_field="anne_cnstr", function_field="code_util", function_to_hub=Dictionaries().montreal_function_to_hub_function, total_floor_area_field="supfi_etag" ).city # Create an instance of DemandEnricher using the database URL demand_enricher = DemandEnricher(database_url) demand_enricher.enrich_city(city) # Close the database connection when done demand_enricher.close_connection() print("done")