From 413c302ed3e5b980facaf8e33971462badbcc57b Mon Sep 17 00:00:00 2001 From: guille Date: Wed, 17 Mar 2021 09:23:48 -0400 Subject: [PATCH] Export energy ade as a file --- exports/formats/energy_ade.py | 16 +++++++++------- tests/test_exports.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/exports/formats/energy_ade.py b/exports/formats/energy_ade.py index 01bf539a..f3cac58a 100644 --- a/exports/formats/energy_ade.py +++ b/exports/formats/energy_ade.py @@ -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]]) } } } diff --git a/tests/test_exports.py b/tests/test_exports.py index 1ae941c0..cc828b90 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -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):