Get schedule and capacity from thermal zones

This commit is contained in:
Ruben1729 2024-02-06 10:56:07 -05:00
parent fa18c0445a
commit c8ec8fae92
2 changed files with 2506 additions and 11 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,8 +36,6 @@ class MatSimEngine:
# TODO: this should come from the factories, please check idf generation # TODO: this should come from the factories, please check idf generation
for building in city.buildings: for building in city.buildings:
activity = hub_function_to_matsim.dictionary[building.function].split(',') activity = hub_function_to_matsim.dictionary[building.function].split(',')
schedule = matsim_schedule.dictionary[activity[0]]
start_time, end_time = schedule.split('-')
for surface in building.grounds: for surface in building.grounds:
for coord in surface.solid_polygon.coordinates: for coord in surface.solid_polygon.coordinates:
@ -54,25 +52,49 @@ class MatSimEngine:
if len(building.thermal_zones_from_internal_zones) > 1: if len(building.thermal_zones_from_internal_zones) > 1:
raise NotImplementedError("multi-zone buildings aren't yet supported") raise NotImplementedError("multi-zone buildings aren't yet supported")
building_schedules = []
capacity = 0
for thermal_zone in building.thermal_zones_from_internal_zones: for thermal_zone in building.thermal_zones_from_internal_zones:
capacity = thermal_zone.occupancy.occupancy_density * building.floor_area * building.storeys_above_ground capacity = thermal_zone.occupancy.occupancy_density * building.floor_area * building.storeys_above_ground
for schedule in thermal_zone.occupancy.occupancy_schedules: for schedule in thermal_zone.occupancy.occupancy_schedules:
print(schedule.values) # TODO: use this schedules values to generate more accurate opentimes. building_schedules.append(schedule)
# TODO: check http://www.matsim.org/files/dtd/facilities_v1.dtd seems to be missing values here # TODO: check http://www.matsim.org/files/dtd/facilities_v1.dtd seems to be missing values here
for new_activity in activity: for new_activity in activity:
facility['activity'].append({ activity_info = {
'@type': new_activity, '@type': new_activity,
'capacity': { 'capacity': {
'@value': math.ceil(capacity) '@value': math.ceil(capacity)
}, },
'opentime': { 'opentime': []
'@day': 'wkday', }
'@start_time': start_time,
'@end_time': end_time for schedule in building_schedules:
} opening_hour = 0
}) closing_hour = 0
# Find opening hour (first hour > 0)
for i, value in enumerate(schedule.values):
if value > 0:
opening_hour = i
break
for i, value in reversed(list(enumerate(schedule.values))):
if value > 0:
closing_hour = i
break
for day in schedule.day_types:
if day[0:3] != 'hol':
activity_info['opentime'].append({
'@day': day[0:3],
'@start_time': opening_hour,
'@end_time': closing_hour
})
facility['activity'].append(activity_info)
facilities_dict['facilities']['facility'].append(facility) facilities_dict['facilities']['facility'].append(facility)
@ -84,7 +106,7 @@ class MatSimEngine:
gdf.to_file("input_files/buildings_shapefile.shp") gdf.to_file("input_files/buildings_shapefile.shp")
# Convert the Python dictionary to an XML string # Convert the Python dictionary to an XML string
xml_content = xmltodict.unparse(facilities_dict, pretty=True) xml_content = xmltodict.unparse(facilities_dict, pretty=True, short_empty_elements=True)
# Write the XML to the file # Write the XML to the file
with open(f"{output_file_path}/{city.name}_facilities.xml", 'w') as file: with open(f"{output_file_path}/{city.name}_facilities.xml", 'w') as file: