Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data validation for inputs in front end #2479

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cea/glossary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -798,16 +798,16 @@ data-helper,get_building_comfort,inputs/building-properties/indoor_comfort.dbf,T
data-helper,get_building_comfort,inputs/building-properties/indoor_comfort.dbf,Ve_lpspax,Indoor quality requirements of indoor ventilation per person,[l/s],{0.0...n},float,black
data-helper,get_building_comfort,inputs/building-properties/indoor_comfort.dbf,RH_max_pc,Upper bound of relative humidity,[%],{0.0...n},float,black
data-helper,get_building_comfort,inputs/building-properties/indoor_comfort.dbf,RH_min_pc,Lower_bound of relative humidity,[%],{0.0...n},float,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,Name,Unique building ID. It must start with a letter.,[-],alphanumeric,string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,type_cs,Type of cooling supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,type_ctrl,Type of heating and cooling control systems (relates to values in Default Database HVAC Properties),[code],{T1...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,type_dhw,Type of hot water supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,type_hs,Type of heating supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,type_vent,Type of ventilation strategy (relates to values in Default Database HVAC Properties),[code],{T1...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,heat_starts,Start of the heating season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,heat_ends,End of the heating season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,cool_starts,Start of the cooling season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/technical_systems.dbf,cool_ends,End of the cooling season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,Name,Unique building ID. It must start with a letter.,[-],alphanumeric,string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,type_cs,Type of cooling supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,type_ctrl,Type of heating and cooling control systems (relates to values in Default Database HVAC Properties),[code],{T1...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,type_dhw,Type of hot water supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,type_hs,Type of heating supply system,[code],{T0...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,type_vent,Type of ventilation strategy (relates to values in Default Database HVAC Properties),[code],{T1...Tn},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,heat_starts,Start of the heating season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,heat_ends,End of the heating season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,cool_starts,Start of the cooling season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_air_conditioning,inputs/building-properties/air_conditioning_systems.dbf,cool_ends,End of the cooling season - use 00|00 when there is none,[DD|MM],{00|00...31|12},string,black
data-helper,get_building_internal,inputs/building-properties/internal_loads.dbf,Ea_Wm2,Peak specific electrical load due to computers and devices,[W/m2],{0.0...n},float,black
data-helper,get_building_internal,inputs/building-properties/internal_loads.dbf,Ed_Wm2,Peak specific electrical load due to servers/data centres,[W/m2],{0.0...n},float,black
data-helper,get_building_internal,inputs/building-properties/internal_loads.dbf,El_Wm2,Peak specific electrical load due to artificial lighting,[W/m2],{0.0...n},float,black
Expand Down
35 changes: 22 additions & 13 deletions cea/interfaces/dashboard/api/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ def read_inputs_field_types():
"""Parse the inputs.yaml file and create the dictionary of column types"""
inputs = yaml.load(
open(os.path.join(os.path.dirname(__file__), '../inputs/inputs.yml')).read())
types = {
'int': int,
'float': float,
'str': str,
'year': int,
}

for db in inputs.keys():
inputs[db]['fieldtypes'] = {
field['name']: types[field['type']] for field in inputs[db]['fields']}
inputs[db]['fieldnames'] = [field['name']
for field in inputs[db]['fields']]
return inputs
Expand Down Expand Up @@ -77,8 +69,8 @@ def get(self, db):
abort(400, 'Input file not found: %s' % db, choices=INPUT_KEYS)
db_info = INPUTS[db]
columns = OrderedDict()
for column in db_info['fieldnames']:
columns[column] = db_info['fieldtypes'][column].__name__
for field in db_info['fields']:
columns[field['name']] = field['type']
return columns


Expand Down Expand Up @@ -196,7 +188,7 @@ def put(self):
def get_building_properties():
import cea.glossary
# FIXME: Find a better way to ensure order of tabs
tabs = ['zone', 'age', 'occupancy', 'architecture', 'internal-loads', 'indoor-comfort', 'technical-systems',
tabs = ['zone', 'age', 'occupancy', 'architecture', 'internal-loads', 'indoor-comfort', 'air-conditioning-systems',
'supply-systems', 'surroundings']

config = current_app.cea_config
Expand Down Expand Up @@ -228,11 +220,19 @@ def get_building_properties():
db_glossary = json.loads(glossary[filenames == '%s.%s' % (db.replace('-', '_'), db_info['type'])]
[['VARIABLE', 'UNIT', 'DESCRIPTION']].set_index('VARIABLE').to_json(orient='index'))

for column in db_info['fieldnames']:
for field in db_info['fields']:
column = field['name']
columns[column] = {}
if column == 'REFERENCE':
continue
columns[column]['type'] = db_info['fieldtypes'][column].__name__
columns[column]['type'] = field['type']
if field['type'] == 'choice':
path = getattr(locator, field['location']['path'])()
columns[column]['path'] = path
# TODO: Try to optimize this step to decrease the number of file reading
columns[column]['choices'] = get_choices(field['location'], path)
if 'constraints' in field:
columns[column]['constraints'] = field['constraints']
columns[column]['description'] = db_glossary[column]['DESCRIPTION']
columns[column]['unit'] = db_glossary[column]['UNIT']
store['columns'][db] = columns
Expand Down Expand Up @@ -319,6 +319,15 @@ def get(self, building):
abort(500, 'File not found')


def get_choices(location, path):
df = pandas.read_excel(path, location['sheet'])
if 'filter' in location:
choices = df[df.eval(location['filter'])][location['column']].tolist()
else:
choices = df[location['column']].tolist()
return [{'value': choice, 'label': df.loc[df[location['column']] == choice, 'Description'].values[0]} for choice in choices]


def schedule_to_dict(locator, building):
schedule_path = locator.get_building_weekly_schedules(building)
schedule_data, schedule_complementary_data = read_cea_schedule(schedule_path)
Expand Down
154 changes: 134 additions & 20 deletions cea/interfaces/dashboard/inputs/inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,72 @@ occupancy:
type: str
- name: SINGLE_RES
type: float
constraints:
max: 1
- name: MULTI_RES
type: float
constraints:
max: 1
- name: OFFICE
type: float
constraints:
max: 1
- name: RETAIL
type: float
constraints:
max: 1
- name: SCHOOL
type: float
constraints:
max: 1
- name: RESTAURANT
type: float
constraints:
max: 1
- name: FOODSTORE
type: float
constraints:
max: 1
- name: GYM
type: float
constraints:
max: 1
- name: HOSPITAL
type: float
constraints:
max: 1
- name: HOTEL
type: float
constraints:
max: 1
- name: INDUSTRIAL
type: float
constraints:
max: 1
- name: LIBRARY
type: float
constraints:
max: 1
- name: SWIMMING
type: float
constraints:
max: 1
- name: COOLROOM
type: float
constraints:
max: 1
- name: SERVERROOM
type: float
constraints:
max: 1
- name: PARKING
type: float
constraints:
max: 1
- name: REFERENCE
type: str
constraints:
max: 1
internal-loads:
parent: zone
pk: Name
Expand Down Expand Up @@ -138,13 +172,33 @@ supply-systems:
- name: Name
type: str
- name: type_cs
type: str
type: choice
location:
path: get_database_supply_systems
sheet: ALL_IN_ONE_SYSTEMS
column: code
filter: system=='COOLING' or system=='NONE'
- name: type_dhw
type: str
type: choice
location:
path: get_database_supply_systems
sheet: ALL_IN_ONE_SYSTEMS
column: code
filter: system=='HEATING' or system=='NONE'
- name: type_el
type: str
type: choice
location:
path: get_database_supply_systems
sheet: ALL_IN_ONE_SYSTEMS
column: code
filter: system=='ELECTRICITY' or system=='NONE'
- name: type_hs
type: str
type: choice
location:
path: get_database_supply_systems
sheet: ALL_IN_ONE_SYSTEMS
column: code
filter: system=='HEATING' or system=='NONE'
architecture:
parent: zone
pk: Name
Expand All @@ -157,32 +211,72 @@ architecture:
type: int
- name: Es
type: float
constraints:
max: 1
- name: Hs_ag
type: float
constraints:
max: 1
- name: Hs_bg
type: float
constraints:
max: 1
- name: Ns
type: float
constraints:
max: 1
- name: wwr_north
type: float
constraints:
max: 1
- name: wwr_east
type: float
constraints:
max: 1
- name: wwr_south
type: float
constraints:
max: 1
- name: wwr_west
type: float
constraints:
max: 1
- name: type_cons
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: CONSTRUCTION
column: code
- name: type_leak
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: LEAKAGE
column: code
- name: type_roof
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: ROOF
column: code
- name: type_shade
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: SHADING
column: code
- name: type_wall
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: WALL
column: code
- name: type_win
type: str
type: choice
location:
path: get_database_envelope_systems
sheet: WINDOW
column: code
indoor-comfort:
parent: zone
pk: Name
Expand All @@ -205,7 +299,7 @@ indoor-comfort:
type: float
- name: Ve_lpspax
type: float
technical-systems:
air-conditioning-systems:
parent: zone
pk: Name
type: dbf
Expand All @@ -214,23 +308,43 @@ technical-systems:
- name: Name
type: str
- name: type_cs
type: str
type: choice
location:
path: get_database_air_conditioning_systems
sheet: cooling
column: code
- name: type_hs
type: str
type: choice
location:
path: get_database_air_conditioning_systems
sheet: heating
column: code
- name: type_dhw
type: str
type: choice
location:
path: get_database_air_conditioning_systems
sheet: dhw
column: code
- name: type_ctrl
type: str
type: choice
location:
path: get_database_air_conditioning_systems
sheet: controller
column: code
- name: type_vent
type: str
type: choice
location:
path: get_database_air_conditioning_systems
sheet: ventilation
column: code
- name: heat_starts
type: str
type: date
- name: heat_ends
type: str
type: date
- name: cool_starts
type: str
type: date
- name: cool_ends
type: str
type: date



2 changes: 2 additions & 0 deletions cea/interfaces/dashboard/inputs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def read_inputs_field_types():
'float': float,
'str': str,
'year': int,
'choice': str,
'date': str
}

for db in inputs.keys():
Expand Down