-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
102 lines (89 loc) · 2.57 KB
/
streamlit_app.py
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
import pandas as pd
import plotly.express as px
import requests
import streamlit as st
st.set_page_config(page_title="yyc-building-energy-benchmarking", page_icon="house")
_, center, _ = st.columns([2, 1, 2])
with center:
st.image(
"https://cdn1.iconfinder.com/data/icons/provincial-electricity-authority-2/64/building_construction_urban_power_energy-512.png",
use_column_width=True,
)
st.title("yyc-building-energy-benchmarking")
st.caption(
"A visualization on building energy and greenhouse gas emission performance information of selected properties"
)
@st.cache_data
def load_df():
yyc_data_url = "https://data.calgary.ca/resource/8twd-upbv.json"
response = requests.get(yyc_data_url)
df = pd.DataFrame(response.json())
df["energy_star_score"] = pd.to_numeric(df["energy_star_score"])
df["site_eui_gj_m"] = pd.to_numeric(df["site_eui_gj_m"])
df = df.sort_values(["year_ending", "property_name"])
return df
df = load_df()
df
st.subheader("Energy Star Score")
fig = px.histogram(
df,
x="energy_star_score",
labels={
"energy_star_score": "Energy Star Score",
},
)
fig
fig = px.scatter(
df,
x="energy_star_score",
y="site_eui_gj_m",
labels={
"energy_star_score": "Energy Star Score",
"site_eui_gj_m": "Site EUI (GJ/m²)",
},
)
fig
st.subheader("Number of Properties")
fig = px.bar(
df.groupby("year_ending").count().reset_index(),
x="year_ending",
y="property_id",
color="year_ending",
labels={
"property_id": "# of properties",
"year_ending": "Year",
},
)
fig.update_layout(
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
)
)
fig.update_xaxes(type="category")
fig
num_of_records_per_property = (
df.groupby("property_id").apply(lambda group: group["year_ending"].count()).tolist()
)
if len(set(num_of_records_per_property)) == 1:
y = set(num_of_records_per_property).pop()
p = len(num_of_records_per_property)
st.caption(f"All {p} properties have {y} years of records.")
st.subheader("Total GHG Emissions Intensity")
property_ids = st.multiselect("property", df["property_id"].unique())
if property_ids:
fig = px.line(
df[df["property_id"].isin(property_ids)],
x="year_ending",
y="total_ghg_emissions_intensity",
color="property_id",
labels={
"total_ghg_emissions_intensity": "Total GHG Emissions Intensity",
"year_ending": "Year",
},
)
fig.update_xaxes(type="category")
fig