Skip to content

Commit b486620

Browse files
author
weilix88
committed
debug and new functions
1 parent f083b35 commit b486620

24 files changed

+689
-323
lines changed

.idea/workspace.xml

+326-288
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BuildSimHubAPI/buildsimhub.py

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def new_parametric_job(self, project_key, model_key=""):
9999
:param model_key: required param.
100100
:return: a parametric job object
101101
:rtype: ParametricJob or None
102-
103102
"""
104103
pj = helpers.parametric_job.ParametricJob(project_key, model_key, self._base_url, self._logger)
105104
return pj

BuildSimHubAPI/helpers/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
from .simulation_job import SimulationJob
66
from .simulation_type import SimulationType
77
from .class_template import ClassTemplate
8+
from .design_template import DesignTemplate
9+
from .eplus_object import EnergyPlusObject
810

Binary file not shown.

BuildSimHubAPI/helpers/energy_model.py

+73-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .httpurllib import request_post
66
from .httpurllib import make_url
77
from .class_template import ClassTemplate
8+
from .eplus_object import EnergyPlusObject
89

910

1011
class Model(object):
@@ -454,7 +455,7 @@ def bldg_orientation(self):
454455
else:
455456
return -1
456457

457-
def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
458+
def hvac_swap(self, temp_dir=None, hvac_type=1, autosize=True, select_sys=None, zone_group=None):
458459
"""
459460
Test function - do not use it
460461
"""
@@ -464,13 +465,10 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
464465
if len(test) is 3:
465466
track = "track_token"
466467

467-
files = dict()
468-
if temp_dir is not None:
469-
files['model'] = open(temp_dir, 'rb')
470-
471468
payload = {
472469
'project_api_key': self._project_api_key,
473-
track: self._track_token
470+
track: self._track_token,
471+
'hvac_type': hvac_type
474472
}
475473

476474
if autosize is True:
@@ -481,7 +479,15 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
481479
if select_sys is not None:
482480
payload['select_system'] = select_sys
483481

484-
r = request_post(url, params=payload, files=files)
482+
if zone_group is not None:
483+
payload['zone_group'] = zone_group
484+
485+
if temp_dir is not None:
486+
files = dict()
487+
files['model'] = open(temp_dir, 'rb')
488+
r = request_post(url, params=payload, files=files)
489+
else:
490+
r = request_post(url, params=payload)
485491
resp_json = r.json()
486492
if r.status_code > 200:
487493
# log action
@@ -504,13 +510,15 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
504510
print('Name: ' + sys['hvac'] + ', Type: ' + sys['object'])
505511
print('Description: ' + sys['description'])
506512
print('Supply: ')
507-
supply = sys['supply']
508-
for supply_comp in supply:
509-
print(supply_comp)
513+
if 'supply' in sys:
514+
supply = sys['supply']
515+
for supply_comp in supply:
516+
print(supply_comp)
510517
print('Demand: ')
511-
demand = sys['demand']
512-
for demand_comp in demand:
513-
print(demand_comp)
518+
if 'demand' in sys:
519+
demand = sys['demand']
520+
for demand_comp in demand:
521+
print(demand_comp)
514522
print('BuildSim choose the first listed system for merge.')
515523
print(data['message'])
516524

@@ -859,6 +867,58 @@ def zone_load(self, zone_name=None):
859867
else:
860868
return -1
861869

870+
def add_object(self, object_array):
871+
"""
872+
add objects to the energy model
873+
874+
:param object_array: the array of EnergyPlusObject class
875+
:return:
876+
"""
877+
# validation
878+
idf_data = list()
879+
for template in object_array:
880+
if not isinstance(template, EnergyPlusObject):
881+
print("The add object must be type of EnergyPlusObject")
882+
raise Exception("Type error")
883+
else:
884+
temp_obj = template.get_object()
885+
idf_data.append(temp_obj)
886+
887+
url = self._base_url + 'AddNewObjects_API'
888+
track = "folder_api_key"
889+
test = self._track_token.split("-")
890+
if len(test) is 3:
891+
track = "track_token"
892+
payload = {
893+
'project_api_key': self._project_api_key,
894+
track: self._track_token,
895+
'object_list': idf_data
896+
}
897+
898+
print(payload)
899+
r = request_post(url, params=payload)
900+
if r.status_code == 200:
901+
data = r.json()
902+
print(data['message'])
903+
904+
# log action
905+
if self._logger is not None:
906+
self._logger.write_in_message('Model', 'AddNewObjects_API', self._project_api_key,
907+
self._track_token, r.status_code, data['tracking'])
908+
909+
return data['tracking']
910+
else:
911+
r_json = r.json()
912+
# log action
913+
if self._logger is not None:
914+
self._logger.write_in_message('Model', 'AddModifyZone', self._project_api_key,
915+
self._track_token, r.status_code, 'error')
916+
try:
917+
print('Code: ' + str(r.status_code) + ' message: ' + r_json['error_msg'])
918+
except TypeError:
919+
print(r_json)
920+
return False
921+
862922
def add_modify_zone(self, zone_list, template_array):
863923
"""
864924
add and modify object according to zone
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
class EnergyPlusObject(object):
3+
4+
def __init__(self, class_label):
5+
self._object = dict()
6+
self._object['class_label'] = class_label
7+
self._values = list()
8+
self._comment = list()
9+
10+
def add_field(self, field, comment=None):
11+
self._values.append(str(field))
12+
if comment is None:
13+
self._comment.append("")
14+
else:
15+
self._comment.append(comment)
16+
17+
def get_object(self):
18+
self._object['value_array'] = self._values
19+
self._object['comment_array'] = self._comment
20+
return self._object
21+

BuildSimHubAPI/helpers/simulation_job.py

-2
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ def run(self, file_dir, epw_dir=None, add_files=None, unit='ip', design_conditio
279279
time.sleep(5)
280280
print("Submitting the model number: " + str(i + 1))
281281
temp_files = self._decode_model_and_epw(file_dir[i], None)
282-
if 'schedule_csv' in files:
283-
temp_files['schedule_csv'] = files['schedule_csv']
284282
r = request_post(url, params=payload, files=temp_files)
285283
if self._http_code_check(r):
286284
resp_json = r.json()

BuildSimHubAPI/measures/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
from .heat_recovery import HeatRecovery
2929
from .hvac_template import HVACTemplate
3030
from .displacement_ventilation import DisplacementVentilation
31-
from .design_template import DesignTemplate
3231
from .customized_measure import CustomizedMeasure
3332
from .discrete_measure_option_template import DiscreteMeasureOptionTemplate

BuildSimHubAPI/measures/discrete_measure_option_template.py

+21
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ def add_class_template_modify(self, class_label, template, class_name=None):
4242
self._template_group.append(template)
4343
return True
4444

45+
def add_class_template_add(self, class_label, template):
46+
"""
47+
Add the template for an EnergyPlus class and do add operation
48+
49+
delete operation means this template removes existing classes that matches
50+
class_label (e.g. Lights) or matches class_label (e.g. Lights) and class_name (SPACE1-1 Lights)
51+
52+
measure_template.add_class_template_delete('ElectricEquipment', 'PLENUM1 Electric')
53+
This will deletes the EnergyPlus class: ElectricEquipment with the name of PLENUM1 Electric
54+
55+
:param class_label: EnergyPlus class label, e.g. ElectricEquipment
56+
:param template: dictionary - the full data
57+
:return: True if added, False otherwise
58+
"""
59+
add_temp = dict()
60+
add_temp['operation'] = 'add'
61+
add_temp['class_label'] = class_label
62+
add_temp['add_data'] = template
63+
self._template_group.append(add_temp)
64+
return True
65+
4566
def add_class_template_delete(self, class_label, class_name=None):
4667
"""
4768
Add the template for an EnergyPlus class and do delete operation

BuildSimHubAPI/measures/model_action.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from BuildSimHubAPI.measures.design_template import DesignTemplate
1+
from BuildSimHubAPI.helpers.design_template import DesignTemplate
22

33

44
class ModelAction(object):

BuildSimHubAPI/postprocess/html_table_plot.py

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ def __init__(self, data):
6262
def pandas_df(self):
6363
return self._df
6464

65+
def get_cell_unit(self, col_name=None, row_name=None):
66+
if col_name is None and row_name is None:
67+
raise Exception("No cell or col or row is specified.")
68+
69+
if col_name is None and row_name is not None:
70+
unit_row_dict = self._unit_dict[row_name]
71+
for k, v in unit_row_dict.items():
72+
return v
73+
74+
if row_name is None and col_name is not None:
75+
for k, v in self._unit_dict.items():
76+
return self._unit_dict[k][col_name]
77+
78+
return self._unit_dict[row_name][col_name]
79+
6580
def table_bar_chart_plot(self, orientation='column', title='Table bar plot', image_name='bar_table', skip_rows=None,
6681
skip_cols=None):
6782
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ScheduleTypeLimits,
2+
Fraction, !- Name
3+
0, !- Lower Limit Value
4+
1, !- Upper Limit Value
5+
Continuous, !- Numeric Type
6+
Dimensionless; !- Unit Type
7+

buildsimdata/calculate.log

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Function entered

buildsimdata/convert_hourly_to_weekly.py

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def main(model_selector):
8080
for j in range(len(data_store[i])):
8181
for z in range(len(data_store[i][j])):
8282
clf = model[model_selector]
83+
print(data_store[i][j][z])
8384
X_train = np.asarray(data_store[i][j][z]).reshape(-1, 1)
8485
clf.fit(X_train)
8586
y_train_pred = clf.labels_

buildsimdata/data_resolution.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def process_data_given_unit(input_file_name, output_file_name, quantity, calcula
6060
export_df.to_csv(output_file_name)
6161

6262
else:
63-
print("here")
6463
minRange = list()
6564
for i in range(int(60/quantity)):
6665
minRange.insert(0, quantity*i)
@@ -127,7 +126,9 @@ def process_data_given_unit(input_file_name, output_file_name, quantity, calcula
127126
logger.info('Current Resolution %d', 1)
128127
logger.info('Converted Resolution %d', quantity)
129128

129+
130130
def main():
131131
process_data_given_unit('pow_lighting_raw.csv', 'result.csv', 12, 'sum')
132132

133+
133134
main()

buildsimdata/missing_data_imputation.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# https://github.com/WillKoehrsen/feature-selector/blob/master/Feature%20Selector%20Usage.ipynb
22
import pandas as pd
33
from datetime import datetime
4-
from sklearn.neighbors import KNeighborsClassifier
5-
from .feature_selector import FeatureSelector
6-
from sklearn.feature_selection import VarianceThreshold
7-
from sklearn.neighbors import KNeighborsClassifier
4+
from feature_selector import FeatureSelector
85
import math
96
from sklearn.neighbors import KNeighborsRegressor
107
import numpy as np
118

129

13-
df = pd.read_csv('../../Bldg101_2014_10m_NA10%.csv')
10+
df = pd.read_csv('/Users/weilixu/Desktop/Bldg101_2014_10m_NA10.csv')
1411
# test_missing = pd.read_excel('../missingdata/PI_Bldg101_Webctrl_Points.xlsx')
1512

1613
# Feature Selection - remove single value and high correlation variable

test/html_table_test.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
import BuildSimHubAPI.postprocess as pp
44

55
# project_key can be found in every project (click the information icon next to project name)
6-
project_api_key = 'f98aadb3-254f-428d-a321-82a6e4b9424c'
6+
project_api_key = '48d36077-89fe-4958-9f51-27a025c530ca'
77
# model_key can be found in each model information bar
8-
model_api_key = '60952acf-bde2-44fa-9883-a0a78bf9eb56'
8+
model_api_key = '17a01cbf-f764-44c8-8d80-4fa7959b420f'
99

1010
# initialize the client
1111
bsh = bshapi.BuildSimHubAPIClient()
1212
results = bsh.model_results(project_api_key, model_api_key)
1313

14-
table_data = results.html_table('Annual Building Utility Performance Summary', 'End Uses')
14+
table_data = results.html_table('Component Sizing Summary', 'Fan:OnOff')
1515
data = pp.HTMLTable(table_data)
1616
df = data.pandas_df()
1717

18-
data.table_bar_chart_plot(orientation='row', skip_rows=['Total End Uses'], title='End Uses', image_name='bar_table')
18+
print(data.get_cell_unit('Design Size Maximum Flow Rate', '28:MECHANICAL PTAC SUPPLY FAN'))
19+
print(df.to_string())

test/hvac_swap_test.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import BuildSimHubAPI as bshapi
2+
3+
# project_key can be found in every project (click the information icon next to project name)
4+
project_api_key = 'c39dceed-242b-4ea3-9fd4-e2076f89c29b'
5+
# model_key can be found in each model information bar
6+
model_api_key = '9e699206-3ee4-48e4-b80a-d9d103ce23ef'
7+
8+
# initialize the client
9+
bsh = bshapi.BuildSimHubAPIClient()
10+
results = bsh.model_results(project_api_key, model_api_key)
11+
id = results.hvac_swap('/Users/weilixu/Desktop/doasvrf.idf')
12+
13+
sim_update = bsh.new_simulation_job(project_api_key)
14+
update_model = sim_update.run_model_simulation(id, track=True)
15+
print(update_model.net_site_eui())

test/hvac_swap_zone_group_test.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
import BuildSimHubAPI as bshapi
3+
import pandas as pd
4+
5+
# project_key can be found in every project (click the information icon next to project name)
6+
project_api_key = 'c39dceed-242b-4ea3-9fd4-e2076f89c29b'
7+
# model_key can be found in each model information bar
8+
model_api_key = 'dca5f246-e6b5-44de-8a31-b9e27e28a633'
9+
10+
# initialize the client
11+
bsh = bshapi.BuildSimHubAPIClient()
12+
results = bsh.model_results(project_api_key, model_api_key)
13+
zone_list = results.zone_list()
14+
15+
zone_group = dict()
16+
for zone in zone_list:
17+
zone_group[zone['zone_name']] = dict()
18+
zone_group[zone['zone_name']]['ventilation'] = 'testzone'
19+
floor = zone['floor']
20+
if floor == 2:
21+
zone_group[zone['zone_name']]['heating'] = 'test2zone'
22+
zone_group[zone['zone_name']]['cooling'] = 'test2zone'
23+
else:
24+
zone_group[zone['zone_name']]['heating'] = 'test3zone'
25+
zone_group[zone['zone_name']]['cooling'] = 'test3zone'
26+
27+
print(zone_group)
28+
29+
id = results.hvac_swap('/Users/weilixu/Desktop/doasfancoil.idf', zone_group=zone_group)
30+
31+
sim_update = bsh.new_simulation_job(project_api_key)
32+
update_model = sim_update.run_model_simulation(id, track=True)
33+
print(update_model.net_site_eui())
34+
35+
36+

0 commit comments

Comments
 (0)