-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp4.py
More file actions
179 lines (161 loc) · 6.11 KB
/
app4.py
File metadata and controls
179 lines (161 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from readers import *
import plotly.graph_objs as go
from plotly.subplots import make_subplots
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app_options = {
"HomeA": ["FurnaceHRV [kW]", "Refrigerator [kW]", "KitchenDenLights [kW]", "DishwasherDisposalSinkLight [kW]",
"OfficeLights [kW]", "CellarOutlets [kW]", "Dryer [kW]", "BasementOutdoorOutlets [kW]"],
"HomeB": ["Grid [kW]", "AC [kW]", "Furnace [kW]", "Utility Rm + Basement Bath [kW]", "Home Office (R) [kW]",
"Home office [kW]", "Guest Bedroom / Media Room [kW]"],
"HomeC": ["LivingRoomOutlets [kW]", "House overall [kW]", "Furnace 1 [kW]", "Furnace 2 [kW]", "Home office [kW]",
"Fridge [kW]", "Wine cellar [kW]", "Living room [kW]"]
}
year_options = {
"HomeA": ["2014", "2015", "2016"],
"HomeB": ["2014", "2015", "2016"],
"HomeC": ["2014", "2015", "2016"]
}
color_list = [
'#1f77b4', # muted blue
'#ff7f0e', # safety orange
'#2ca02c', # cooked asparagus green
'#d62728', # brick red
'#9467bd', # muted purple
'#8c564b', # chestnut brown
'#e377c2', # raspberry yogurt pink
'#7f7f7f', # middle gray
'#bcbd22', # curry yellow-green
'#17becf' # blue-teal
]
app.layout = html.Div([
html.Div([
html.Label("Task4"),
dcc.Dropdown(
id="drop-down-year",
value="2016"
),
dcc.Dropdown(
id="drop-down-apps",
multi=True,
),
dcc.Dropdown(
id="drop-down-homes",
value='HomeA',
options=[
{'label': 'Home A', 'value': 'HomeA'},
{'label': 'Home B', 'value': 'HomeB'},
{'label': 'Home C', 'value': 'HomeC'}
]
),
dcc.RadioItems(
id="radio-weather",
options=[
{'label': 'Temperature', 'value': 'temperature'},
{'label': 'Pressure', 'value': 'pressure'},
{'label': 'WindSpeed', 'value': 'windSpeed'}
],
value="temperature"
),
html.Div([
dcc.Graph(
id='Vis-1',
),
dcc.Graph(
id='Vis-2',
)
])
])
])
@app.callback(
[Output("drop-down-year", "options"),
Output("drop-down-apps", "options")],
[Input("drop-down-homes", "value")])
def update_comps(home_name):
return [{'label': i, 'value': i} for i in year_options[home_name]], [{'label': i, 'value': i} for i in
app_options[home_name]]
@app.callback(
[Output('Vis-1', 'figure'),
Output("Vis-2", "figure")],
[Input("drop-down-homes", "value"),
Input("drop-down-year", "value"),
Input("drop-down-apps", "value"),
Input("radio-weather", "value")],
)
def update_graph(home_name, year, apps, weather):
df = merger(home_name, year)
df["Temperature range"] = df["temperature"].apply(roundup_v1)
df["Temperature range"] = [("(" + str(row - 10) + "," + str(row) + ")") for row in df["Temperature range"]]
df["Pressure range"] = df["pressure"].apply(roundup_v1)
df["Pressure range"] = [("(" + str(row - 10) + "," + str(row) + ")") for row in df["Pressure range"]]
df["windSpeed range"] = df["windSpeed"].apply(roundup_v2)
df["windSpeed range"] = [("(" + str(row - 1) + "," + str(row) + ")") for row in df["windSpeed range"]]
fig_1 = make_subplots(specs=[[{"secondary_y": True}]])
fig_2 = make_subplots(rows=1, cols=3, y_title="Power Consumption [kW]")
color_count = 0
fig_1.add_trace(
go.Scatter(x=df["Date"],
y=df[weather],
name=weather,
line=dict(color="black", width=0.5)),
secondary_y=True
)
if apps is None:
raise PreventUpdate
else:
for app in apps:
fig_1.add_trace(
go.Scatter(x=df["Date"],
y=df[app],
name=app,
line=dict(color=color_list[color_count], width=1)),
secondary_y=False
)
fig_2.add_trace(
go.Scatter(
x=df["Temperature range"].sort_values(ascending=True),
y=df[app],
name=app,
mode='markers',
marker_color=color_list[color_count],
opacity = 0.5
), row=1, col=1,
)
fig_2.add_trace(
go.Scatter(
x=df["Pressure range"].sort_values(ascending=True),
y=df[app],
name=app,
mode='markers',
marker_color=color_list[color_count],
opacity=0.5,
showlegend = False
), row=1, col=2
)
fig_2.add_trace(
go.Scatter(
x=df["windSpeed range"].sort_values(ascending=True),
y=df[app],
name=app,
mode='markers',
marker_color=color_list[color_count],
opacity=0.5,
showlegend=False
), row=1, col=3
)
color_count += 1
fig_1.update_layout(title='Appliance Power Consumption across Weather Conditions ' + home_name + ' ' + year)
fig_1.update_xaxes(title_text="Months", nticks=6)
fig_1.update_yaxes(title_text=weather, secondary_y=True)
fig_1.update_yaxes(title_text="Power Consumption", secondary_y=False)
fig_2.update_xaxes(title_text="Temperature (C)", row=1, col=1)
fig_2.update_xaxes(title_text="Pressure(mBar)", row=1, col=2)
fig_2.update_xaxes(title_text="WindSpeed(kmph)", row=1, col=3)
return fig_1, fig_2
if __name__ == "__main__":
app.run_server(debug=True)