add error handling

This commit is contained in:
Guille Gutierrez 2022-05-11 07:34:24 -04:00
parent 2030cf5b96
commit 8d3cf3a341
3 changed files with 69 additions and 54 deletions

View File

@ -75,6 +75,11 @@ label {
font-width: bold; font-width: bold;
} }
.error {
color: red;
font-width: bold;
}
#links a { #links a {
color: #0CFF0C; color: #0CFF0C;
} }

View File

@ -89,6 +89,10 @@ function run_script(script, parameters='') {
document.getElementById('spinner').style.visibility = "hidden" document.getElementById('spinner').style.visibility = "hidden"
plot_results() plot_results()
} }
else if (message == '[simulation abort]')
{
document.getElementById('spinner').style.visibility = "hidden"
}
else if (message.substring(0, 4) == 'row:') else if (message.substring(0, 4) == 'row:')
{ {
message = message.replace('row: ', '') message = message.replace('row: ', '')
@ -97,6 +101,12 @@ function run_script(script, parameters='') {
heating.push(row[1]) heating.push(row[1])
cooling.push(row[2]) cooling.push(row[2])
} }
else if (message.substring(0, 6) == 'error:')
{
message = message.replace('error: ', '')
message = '<label class="error">' + message + '</label>'
document.getElementById('debug').innerHTML = message
}
else if (message.substring(0, 5) == 'info:') else if (message.substring(0, 5) == 'info:')
{ {
message = message.replace('info: ', '') message = message.replace('info: ', '')

View File

@ -1,65 +1,65 @@
import sys import sys
from pathlib import Path from pathlib import Path
import csv 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 for argument_tuple in sys.argv[1:]:
from imports.construction_factory import ConstructionFactory argument = argument_tuple.split(' ')
from imports.usage_factory import UsageFactory option = argument[0]
from exports.exports_factory import ExportsFactory value = argument[1]
from imports.customized_imports_factory import CustomizedImportsFactory if option == '-g':
from imports.customized_imports.stochastic_schedules_importer import StochasticSchedulesImporter as ssi gml = value
for argument_tuple in sys.argv[1:]: print('[simulation start]')
argument = argument_tuple.split(' ') city = GeometryFactory('citygml', gml).city
option = argument[0] print(f'city created from {gml}')
value = argument[1] for building in city.buildings:
if option == '-g': building.year_of_construction = 2006
gml = value 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]') area = 0
city = GeometryFactory('citygml', gml).city volume = 0
print(f'city created from {gml}') for building in city.buildings:
for building in city.buildings: volume = building.volume
building.year_of_construction = 2006 for ground in building.grounds:
ConstructionFactory('nrel', city).enrich() area += ground.perimeter_polygon.area
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 print('exporting:')
volume = 0 out_path = (Path(__file__).parent.parent / 'out_files')
for building in city.buildings: ExportsFactory('obj', city, out_path).export()
volume = building.volume print(' geometry exported...')
for ground in building.grounds: # todo: _idf exporter does not catch errors in exporting
area += ground.perimeter_polygon.area _idf = ExportsFactory('idf', city, out_path).export_debug()
print(' idf exported...')
_idf.run()
print('exporting:') csv_file = str((out_path / f'{city.name}_out.csv').resolve())
out_path = (Path(__file__).parent.parent / 'out_files') eso_file = str((out_path / f'{city.name}_out.eso').resolve())
ExportsFactory('obj', city, out_path).export() idf_file = str((out_path / f'{city.name}.idf').resolve())
print(' geometry exported...') obj_file = str((out_path / f'{city.name}.obj').resolve())
# 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()) with open((out_path / f'{city.name}_out.csv').resolve()) as f:
eso_file = str((out_path / f'{city.name}_out.eso').resolve()) reader = csv.reader(f, delimiter=',')
idf_file = str((out_path / f'{city.name}.idf').resolve()) for row in reader:
obj_file = str((out_path / f'{city.name}.obj').resolve()) if ':00:00' in row[0]:
print(f'row: {row[0]}, {row[8]}, {row[9]}')
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]')
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() sys.stdout.flush()