2024-10-03 18:28:35 -04:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
|
|
from hub.helpers.dictionaries import Dictionaries
|
2024-10-09 12:11:39 -04:00
|
|
|
from hub.imports.results.archetype_based_demand import DemandEnricher
|
|
|
|
import urllib.parse
|
2024-10-03 18:28:35 -04:00
|
|
|
|
2024-10-08 15:07:32 -04:00
|
|
|
input_file = "data/cmm_points_function_vintage_surface.csv"
|
2024-10-09 12:11:39 -04:00
|
|
|
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}'
|
2024-10-03 18:28:35 -04:00
|
|
|
|
2024-10-08 15:07:32 -04:00
|
|
|
# Initialize city object from GeometryFactory
|
2024-10-03 18:28:35 -04:00
|
|
|
city = GeometryFactory(
|
|
|
|
file_type="csv",
|
|
|
|
path=input_file,
|
2024-10-08 15:07:32 -04:00
|
|
|
centroid_x_field="centroid_x",
|
|
|
|
centroid_y_field="centroid_y",
|
2024-10-03 18:28:35 -04:00
|
|
|
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
|
2024-10-09 12:11:39 -04:00
|
|
|
|
|
|
|
# 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")
|