Get schedule and capacity from thermal zones
This commit is contained in:
parent
fa18c0445a
commit
c8ec8fae92
2473
input_files/summerschool_all_buildings.geojson
Normal file
2473
input_files/summerschool_all_buildings.geojson
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -36,8 +36,6 @@ class MatSimEngine:
|
|||
# TODO: this should come from the factories, please check idf generation
|
||||
for building in city.buildings:
|
||||
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 coord in surface.solid_polygon.coordinates:
|
||||
|
@ -54,25 +52,49 @@ class MatSimEngine:
|
|||
if len(building.thermal_zones_from_internal_zones) > 1:
|
||||
raise NotImplementedError("multi-zone buildings aren't yet supported")
|
||||
|
||||
building_schedules = []
|
||||
|
||||
capacity = 0
|
||||
for thermal_zone in building.thermal_zones_from_internal_zones:
|
||||
capacity = thermal_zone.occupancy.occupancy_density * building.floor_area * building.storeys_above_ground
|
||||
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
|
||||
|
||||
for new_activity in activity:
|
||||
facility['activity'].append({
|
||||
activity_info = {
|
||||
'@type': new_activity,
|
||||
'capacity': {
|
||||
'@value': math.ceil(capacity)
|
||||
},
|
||||
'opentime': {
|
||||
'@day': 'wkday',
|
||||
'@start_time': start_time,
|
||||
'@end_time': end_time
|
||||
}
|
||||
})
|
||||
'opentime': []
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
@ -84,7 +106,7 @@ class MatSimEngine:
|
|||
gdf.to_file("input_files/buildings_shapefile.shp")
|
||||
|
||||
# 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
|
||||
with open(f"{output_file_path}/{city.name}_facilities.xml", 'w') as file:
|
||||
|
|
Loading…
Reference in New Issue
Block a user