Skip to content

Commit cc34f0f

Browse files
author
weilixu
committed
add ML system
1 parent e3c3f31 commit cc34f0f

File tree

10 files changed

+354
-131
lines changed

10 files changed

+354
-131
lines changed

.idea/workspace.xml

+178-120
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

BuildSimHubAPI/info.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
user_api_key= buildsimhub
2-
base_url=https://develop.buildsimhub.net/
2+
base_url=https://my.buildsim.io/
33
vendor_id=buildsimhub
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
BuildingLoad class - post-process bldg level load data
3+
and form it into a pandas dataframe
4+
"""
5+
6+
try:
7+
import pandas as pd
8+
except ImportError:
9+
pd = None
10+
print('pandas is not installed')
11+
12+
13+
class BuildingLoad(object):
14+
15+
def __init__(self, bldg_load_profile):
16+
"""
17+
18+
:param bldg_load_profile: bldg_load_profile: jsonarray returned
19+
from BSH server by calling the building load api
20+
"""
21+
22+
# reform the dict
23+
index_list = list()
24+
self._cooling_unit = ''
25+
self._heating_unit = ''
26+
self._cooling_density_unit = ''
27+
self._heating_density_unit = ''
28+
data = list()
29+
for d_dict in bldg_load_profile:
30+
data_dict = dict()
31+
if len(d_dict.keys()) == 1:
32+
continue
33+
index_list.append(d_dict['model'].upper())
34+
if self._cooling_unit == '':
35+
self._cooling_unit = d_dict['cooling_unit']
36+
if self._heating_unit == '':
37+
self._heating_unit = d_dict['heating_unit']
38+
if self._heating_density_unit == '':
39+
self._heating_density_unit = d_dict['heating_load_density_unit']
40+
if self._cooling_density_unit == '':
41+
self._cooling_density_unit = d_dict['cooling_load_density_unit']
42+
# remove name and units from the dict
43+
data_dict['heating_load'] = d_dict['heating_load']
44+
data_dict['cooling_load'] = d_dict['cooling_load']
45+
data_dict['heating_load_density'] = d_dict['heating_load_density']
46+
data_dict['cooling_load_density'] = d_dict['cooling_load_density']
47+
data.append(data_dict)
48+
self._df = pd.DataFrame(data, index=index_list)
49+
50+
@property
51+
def cooling_load_unit(self):
52+
return self._cooling_unit
53+
54+
@property
55+
def heating_load_unit(self):
56+
return self._heating_unit
57+
58+
@property
59+
def cooling_load_density_unit(self):
60+
return self._cooling_density_unit
61+
62+
@property
63+
def heating_load_density_unit(self):
64+
return self._heating_density_unit
65+
66+
def get_df(self):
67+
"""get the dataframe"""
68+
return self._df
69+
70+
def plot(self):
71+
"""Plotly scatter plot"""
72+
try:
73+
from plotly.offline import plot
74+
from plotly import tools
75+
import plotly.graph_objs as go
76+
except ImportError:
77+
print('plotly is not installed')
78+
79+
data = list()
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
try:
3+
import numpy as np
4+
except ImportError:
5+
np = None
6+
print('numpy is not installed')
7+
8+
try:
9+
import pandas as pd
10+
except ImportError:
11+
pd = None
12+
print('pandas is not installed')
13+
14+
15+
class Regression(object):
16+
def __init__(self, data, unit=""):
17+
"""
18+
Construct parametric plot
19+
20+
:param data: returned from the parametric result call
21+
:param unit:
22+
"""
23+
self._value = data['value']
24+
self._unit = unit
25+
26+
self._model_plot = data['model_plot']
27+
self._model_des = data['model']
28+
29+
data_list = list()
30+
31+
# create data dictionary
32+
for j in range(len(self._model_des)):
33+
col_list = self._model_des[j]
34+
parameters = col_list.split(",")
35+
data_dict = dict()
36+
for k in range(len(parameters)):
37+
title, val = parameters[k].split(":")
38+
# for cases like on off options
39+
if val.strip() == 'Off':
40+
val = '0'
41+
if val.strip() == 'On':
42+
val = '1'
43+
44+
data_dict[title.strip()] = float(val.strip())
45+
# data_dict['Value'] = self._value[j]
46+
47+
data_list.append(data_dict)
48+
49+
self._df = pd.DataFrame(data_list, index=self._model_plot)
50+
self._df['Value'] = self._value
51+
52+
def pandas_df(self):
53+
"""get the data in pandas dataframe"""
54+
return self._df
55+
56+
def add_column(self, head, col):
57+
"""
58+
59+
:param head:
60+
:param col:
61+
:type head: str
62+
:type col: list
63+
:return:
64+
"""
65+
if head == 'Value':
66+
return False
67+
self._df.assign(head=col)
68+
69+
def x_validate(self):
70+
y = self._df[['Value']]
71+
try:
72+
from sklearn.model_selection import cross_val_score
73+
except ImportError:
74+
print("Sci-kit learn package is required for model training. Please install the package at: "
75+
"http://scikit-learn.org/stable/index.html")
76+
return
77+
78+
79+
80+
81+
82+

Plot.html

+1-1
Large diffs are not rendered by default.

line.html

+1-1
Large diffs are not rendered by default.

test/parametrictest.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import BuildSimHubAPI.postprocess as pp
88

99
# 1. set your folder key
10-
project_key = '87e86a33-964e-4809-9e72-802791a8e968'
11-
model_key = '82f244cf-adb6-4f69-9d5d-183ca5e89106'
10+
project_key = '7e140eec-b37f-4213-8640-88b5f96c0065'
11+
model_key = '48003d7a-143f-45c1-b175-4ab4d1968bbd'
1212

1313
file_dir = "/Users/weilixu/Desktop/data/jsontest/5ZoneAirCooled_UniformLoading.epJSON"
1414

@@ -17,11 +17,11 @@
1717

1818
# Define EEMs
1919
wwr = bsh_api.measures.WindowWallRatio()
20-
wwr_ratio = [0.6, 0.4, 0.3]
20+
wwr_ratio = [0.6, 0.4]
2121
wwr.set_datalist(wwr_ratio)
2222

2323
lpd = bsh_api.measures.LightLPD('ip')
24-
lpdValue = [1.2, 0.9, 0.7]
24+
lpdValue = [1.2, 0.9]
2525
lpd.set_datalist(lpdValue)
2626

2727
heatEff = bsh_api.measures.HeatingEfficiency()
@@ -44,6 +44,7 @@
4444

4545
# Plot
4646
plot = pp.ParametricPlot(result_dict, result_unit)
47+
print(plot.pandas_df())
4748

4849
plot.scatter_chart_plotly("Scatter plot demo")
4950
plot.parallel_coordinate_plotly('LPD')

test/test.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
8.9 test
33
"""
44
import BuildSimHubAPI as bshapi
5+
import BuildSimHubAPI.postprocess as pp
56
import time
67

78
bsh = bshapi.BuildSimHubAPIClient()
8-
project_key = "d43f2d17-7da6-4fd1-800c-62651001d453"
9+
project_key = "7e140eec-b37f-4213-8640-88b5f96c0065"
910
# model_key = "39ed84d0-062b-470d-96e6-b03abff9c31c"
1011

1112
# 1. define the absolute directory of your energy model
1213
file_dir = ["/Users/weilixu/Desktop/data/jsontest/5ZoneAirCooled_UniformLoading.epJSON",
1314
"/Users/weilixu/Desktop/data/jsontest/5ZoneAirCooled.idf"]
1415

15-
file_dir = "/Users/weilixu/Desktop/data/jsontest/5ZoneAirCooled.idf"
16+
# file_dir = "/Users/weilixu/Desktop/data/jsontest/5ZoneAirCooled.idf"
1617

1718
wea_dir = "/Users/weilixu/Desktop/data/jsontest/in.epw"
1819

@@ -21,8 +22,10 @@
2122

2223
if results:
2324
load_data = results.zone_load()
24-
# print(load_data)
25-
results.bldg_geo()
25+
print(load_data)
26+
zl = pp.ZoneLoad(load_data)
27+
print(zl.get_df())
28+
# results.bldg_geo()
2629
# if results:
2730
# print(str(results.not_met_hour_cooling()) + " " + results.last_parameter_unit)
2831
# load_data = results.zone_load()

0 commit comments

Comments
 (0)