Skip to content

Commit 7ed236c

Browse files
author
weilixu
committed
redesign the architecture
separate model from simulation job.
1 parent 4123960 commit 7ed236c

12 files changed

Lines changed: 70 additions & 163 deletions
469 Bytes
Binary file not shown.

BuildSimHubAPI/buildsimhub.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from BuildSimHubAPI.helpers import bldgsim_info
22
from BuildSimHubAPI.helpers import simulationJob
33
from BuildSimHubAPI.helpers import simulationType
4+
from BuildSimHubAPI.helpers import energyModel
5+
from BuildSimHubAPI.helpers import htmlResults
46

57
class BuildSimHubAPIClient():
68
"""
@@ -33,3 +35,11 @@ def new_simulation_job(self, model_key):
3335
def get_simulation_type(self):
3436
st = simulationType.SimulationType()
3537
return st
38+
39+
def get_model(self, simulationJob):
40+
modelKey = vars(simulationJob)['_trackToken']
41+
model = energyModel.Model(self._userAPI,modelKey)
42+
return model
43+
44+
def get_html(self, simulationJob):
45+
html = htmlResults.HTMLResults(self._userAPI,simulaitonJob)
56 Bytes
Binary file not shown.
1.35 KB
Binary file not shown.
-92 Bytes
Binary file not shown.
-9 Bytes
Binary file not shown.

BuildSimHubAPI/helpers/energyModel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22
import json
3-
3+
from .simulationJob import SimulationJob
44
#This is a class that contains all the model information for user
55
#to read
66

@@ -13,8 +13,8 @@ class Model():
1313

1414
def __init__(self, userKey, modelKey):
1515
self._userKey = userKey
16-
self._modelKey = modelKey
1716
self._lastParameterUnit = ""
17+
self._modelKey = modelKey
1818

1919
@property
2020
def lastParameterUnit(self):
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import requests
2+
import json
3+
from .simulationJob import SimulationJob
4+
5+
#This is a class that contains all the model information for user
6+
#to read
7+
8+
9+
#potentially in the future, to write
10+
11+
class HTMLResults():
12+
#every call will connect to this base URL
13+
BASE_URL = 'https://develop.buildsimhub.net/'
14+
15+
def __init__(self, userKey, simulationJob):
16+
self._userKey = userKey
17+
self._modelKey = simulationJob.modelKey
18+
self._lastParameterUnit = ''
19+
20+
@property
21+
def lastParameterUnit(self):
22+
return self._lastParameterUnit
23+
24+
def request_numeric_value(self, report, table, column_name, row_name):
25+
url = HTMLResults.BASE_URL + 'GetNumericValueFromHTML_API'
26+
payload = {
27+
'user_api_key': self._userKey,
28+
'track_token': self._modelKey,
29+
'report': report,
30+
'table': table,
31+
'column_name': column_name,
32+
'row_name': row_name
33+
}
34+
35+
r = request.get(url, params = payload)
36+
resp_json = r.json()
37+
if(resp_json['status']=='success'):
38+
data = resp_json['data']
39+
value = data['value']
40+
if('unit' in data):
41+
self._lastParameterUnit = data['unit']
42+
else:
43+
self._lastParameterUnit = ''
44+
return value
45+
else:
46+
return -1

BuildSimHubAPI/helpers/model.py

Lines changed: 0 additions & 145 deletions
This file was deleted.

BuildSimHubAPI/helpers/simulationJob.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import requests
22
import json
3-
from .energyModel import Model
43

54
class SimulationJob():
65
#every call will connect to this base URL
76
BASE_URL = 'https://develop.buildsimhub.net/'
87

9-
def __init__(self, userKey, folderkey):
8+
def __init__(self, userKey, mk):
109
self._userKey = userKey
11-
self._folderKey = folderkey
10+
self._modelKey = mk
1211
self._trackToken = ""
1312
self._trackStatus = "No simulation is running or completed in this Job - please start simulation using createModel method."
14-
self._model = None
1513

1614
@property
1715
def trackStatus(self):
@@ -21,14 +19,14 @@ def trackStatus(self):
2119
def trackToken(self):
2220
return self._trackToken
2321

22+
@property
23+
def modelKey(self):
24+
return self._modelKey
25+
2426
@trackToken.setter
2527
def trackToken(self, value):
2628
self._trackToken = value
2729

28-
@property
29-
def model(self):
30-
return self._model
31-
3230
def get_simulation_results(self, resultType="html"):
3331
if(self._trackToken == ""):
3432
return self._trackStatus
@@ -96,7 +94,7 @@ def create_model(self, file_dir, comment = "Upload through Python API", simulati
9694
url = SimulationJob.BASE_URL + 'CreateModel_API'
9795
payload = {
9896
'user_api_key': self._userKey,
99-
'folder_api_key': self._folderKey,
97+
'folder_api_key': self._modelKey,
10098
'comment': comment,
10199
'simulation_type': simulationType,
102100
'agents' : agent
@@ -105,15 +103,13 @@ def create_model(self, file_dir, comment = "Upload through Python API", simulati
105103
files={
106104
'file': open(file_dir, 'rb')
107105
}
108-
106+
109107
r = requests.post(url, data=payload, files= files)
110-
108+
111109
resp_json = r.json()
112110

113111
if(resp_json['status'] == 'success'):
114112
self._trackToken = resp_json['tracking']
115-
self._model = Model(self._userKey, self._trackToken)
116-
117113
return resp_json['status']
118114
else:
119115
return resp_json['error_msg']

0 commit comments

Comments
 (0)