Export energy ade as a file

This commit is contained in:
Guille Gutierrez 2021-03-17 09:23:48 -04:00
parent f0e7f55535
commit 413c302ed3
2 changed files with 10 additions and 8 deletions

View File

@ -5,6 +5,7 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
"""
import xmltodict
import uuid
from pathlib import Path
class EnergyAde:
@ -14,7 +15,6 @@ class EnergyAde:
self._export()
def _export(self):
print('start')
energy_ade = {
'core:CityModel': {
'@xmlns:brid':'http://www.opengis.net/citygml/bridge/2.0',
@ -49,7 +49,6 @@ class EnergyAde:
}
}
}
print(xmltodict.unparse(energy_ade,pretty=True))
buildings = []
for building in self._city.buildings:
building_dic = {
@ -60,8 +59,11 @@ class EnergyAde:
building_dic = EnergyAde._get_measures(building, building_dic)
buildings.append(building_dic)
energy_ade['core:CityModel'] = {'core:cityObjectMember': buildings}
print(xmltodict.unparse(energy_ade,pretty=True))
energy_ade['core:CityModel']['core:cityObjectMember'] = buildings
file_name = self._city.name + '_ade.gml'
file_path = Path(self._path / file_name).resolve()
with open(file_path, 'w' ) as file:
file.write(xmltodict.unparse(energy_ade,pretty=True))
@staticmethod
def _get_measures(building, building_dic):
@ -83,11 +85,11 @@ class EnergyAde:
for key in building.cooling:
if key != 'year':
period = EnergyAde._get_period(building.cooling, key, 'Heating energy', 'INSEL')
period = EnergyAde._get_period(building.cooling, key, 'Cooling energy', 'INSEL')
periods.append(period)
if len(periods) != 0:
building_dic['energy:demands']['energy:EnergyDemand'] = periods
building_dic['energy:demands'] = {'energy:EnergyDemand': periods}
return building_dic
@ -122,7 +124,7 @@ class EnergyAde:
},
'energy:values': {
'@uom': 'kWh',
'#text': ' '.join([str(e / 1000) for e in measure_dict[key_value][source]])
'#text': ' '.join([str(float(e) / 1000) for e in measure_dict[key_value][source]])
}
}
}

View File

@ -26,7 +26,7 @@ class TestExports(TestCase):
def _get_city(self):
if self._city_gml is None:
file_path = (self._example_path / 'one_building_in_kelowna_populated_weather_demand.pickle').resolve()
city = City.load(file_path)
self._city_gml = City.load(file_path)
return self._city_gml
def _export(self, export_type):