From 8d3cf3a3418318051dd035a725a5a363d616e3ee Mon Sep 17 00:00:00 2001 From: guille Date: Wed, 11 May 2022 07:34:24 -0400 Subject: [PATCH] add error handling --- css/base.css | 5 ++ js/renderer.js | 10 ++++ scripts/ep_workflow.py | 108 ++++++++++++++++++++--------------------- 3 files changed, 69 insertions(+), 54 deletions(-) diff --git a/css/base.css b/css/base.css index a08bc653..4b3e07bf 100644 --- a/css/base.css +++ b/css/base.css @@ -75,6 +75,11 @@ label { font-width: bold; } +.error { + color: red; + font-width: bold; +} + #links a { color: #0CFF0C; } diff --git a/js/renderer.js b/js/renderer.js index 701f7aeb..7588091b 100644 --- a/js/renderer.js +++ b/js/renderer.js @@ -89,6 +89,10 @@ function run_script(script, parameters='') { document.getElementById('spinner').style.visibility = "hidden" plot_results() } + else if (message == '[simulation abort]') + { + document.getElementById('spinner').style.visibility = "hidden" + } else if (message.substring(0, 4) == 'row:') { message = message.replace('row: ', '') @@ -97,6 +101,12 @@ function run_script(script, parameters='') { heating.push(row[1]) cooling.push(row[2]) } + else if (message.substring(0, 6) == 'error:') + { + message = message.replace('error: ', '') + message = '' + document.getElementById('debug').innerHTML = message + } else if (message.substring(0, 5) == 'info:') { message = message.replace('info: ', '') diff --git a/scripts/ep_workflow.py b/scripts/ep_workflow.py index 07705646..94b9ec22 100644 --- a/scripts/ep_workflow.py +++ b/scripts/ep_workflow.py @@ -1,65 +1,65 @@ import sys from pathlib import Path import csv -sys.path.append('../libs') +sys.path.append('../hub') +try: + from imports.geometry_factory import GeometryFactory + from imports.construction_factory import ConstructionFactory + from imports.usage_factory import UsageFactory + from exports.exports_factory import ExportsFactory + from imports.customized_imports_factory import CustomizedImportsFactory + from imports.customized_imports.stochastic_schedules_importer import StochasticSchedulesImporter as ssi -from imports.geometry_factory import GeometryFactory -from imports.construction_factory import ConstructionFactory -from imports.usage_factory import UsageFactory -from exports.exports_factory import ExportsFactory -from imports.customized_imports_factory import CustomizedImportsFactory -from imports.customized_imports.stochastic_schedules_importer import StochasticSchedulesImporter as ssi + for argument_tuple in sys.argv[1:]: + argument = argument_tuple.split(' ') + option = argument[0] + value = argument[1] + if option == '-g': + gml = value -for argument_tuple in sys.argv[1:]: - argument = argument_tuple.split(' ') - option = argument[0] - value = argument[1] - if option == '-g': - gml = value + print('[simulation start]') + city = GeometryFactory('citygml', gml).city + print(f'city created from {gml}') + for building in city.buildings: + building.year_of_construction = 2006 + ConstructionFactory('nrel', city).enrich() + print('enrich constructions... done') + UsageFactory('comnet', city).enrich() + print('enrich usage... done') + in_path = (Path(__file__).parent.parent / 'data' / 'occupancyschedules_2019_point4.xlsx') + CustomizedImportsFactory(ssi, city, in_path).enrich() + print('enrich stochastic schedules for occupancy... done') -print('[simulation start]') -city = GeometryFactory('citygml', gml).city -print(f'city created from {gml}') -for building in city.buildings: - building.year_of_construction = 2006 -ConstructionFactory('nrel', city).enrich() -print('enrich constructions... done') -UsageFactory('comnet', city).enrich() -print('enrich usage... done') -in_path = (Path(__file__).parent.parent / 'data' / 'occupancyschedules_2019_point4.xlsx') -CustomizedImportsFactory(ssi, city, in_path).enrich() -print('enrich stochastic schedules for occupancy... done') + area = 0 + volume = 0 + for building in city.buildings: + volume = building.volume + for ground in building.grounds: + area += ground.perimeter_polygon.area -area = 0 -volume = 0 -for building in city.buildings: - volume = building.volume - for ground in building.grounds: - area += ground.perimeter_polygon.area + print('exporting:') + out_path = (Path(__file__).parent.parent / 'out_files') + ExportsFactory('obj', city, out_path).export() + print(' geometry exported...') + # todo: _idf exporter does not catch errors in exporting + _idf = ExportsFactory('idf', city, out_path).export_debug() + print(' idf exported...') + _idf.run() -print('exporting:') -out_path = (Path(__file__).parent.parent / 'out_files') -ExportsFactory('obj', city, out_path).export() -print(' geometry exported...') -# todo: _idf exporter does not catch errors in exporting -_idf = ExportsFactory('idf', city, out_path).export_debug() -print(' idf exported...') -_idf.run() + csv_file = str((out_path / f'{city.name}_out.csv').resolve()) + eso_file = str((out_path / f'{city.name}_out.eso').resolve()) + idf_file = str((out_path / f'{city.name}.idf').resolve()) + obj_file = str((out_path / f'{city.name}.obj').resolve()) -csv_file = str((out_path / f'{city.name}_out.csv').resolve()) -eso_file = str((out_path / f'{city.name}_out.eso').resolve()) -idf_file = str((out_path / f'{city.name}.idf').resolve()) -obj_file = str((out_path / f'{city.name}.obj').resolve()) - -with open((out_path/ f'{city.name}_out.csv').resolve()) as f: - reader = csv.reader(f, delimiter=',') - for row in reader: - if ':00:00' in row[0]: - print(f'row: {row[0]}, {row[8]}, {row[9]}') - - -print(f'info: {idf_file}, {csv_file}, {eso_file}, {area}, {volume}, {obj_file}') - -print('[simulation end]') + with open((out_path / f'{city.name}_out.csv').resolve()) as f: + reader = csv.reader(f, delimiter=',') + for row in reader: + if ':00:00' in row[0]: + print(f'row: {row[0]}, {row[8]}, {row[9]}') + print(f'info: {idf_file}, {csv_file}, {eso_file}, {area}, {volume}, {obj_file}') + print('[simulation end]') +except Exception as ex: + print('error: ', ex) + print('[simulation abort]') sys.stdout.flush()