-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.py
191 lines (153 loc) · 5.82 KB
/
Home.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
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
180
181
182
183
184
185
186
187
188
189
190
191
import streamlit as st
import pandas as pd
import plotly.express as px
from streamlit_option_menu import option_menu
from numerize.numerize import numerize
#from query import *
import time
st.set_page_config(page_title="Dashboard",page_icon="🌍",layout="wide")
st.subheader("🔔 Analytics Dashboard")
st.markdown("##")
theme_plotly = None # None or streamlit
# Style
with open('style.css')as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html = True)
#fetch data
#result = view_all_data()
#df=pd.DataFrame(result,columns=["Policy","Expiry","Location","State","Region","Investment","Construction","BusinessType","Earthquake","Flood","Rating","id"])
#load excel file
df=pd.read_excel('data.xlsx', sheet_name='Sheet1')
#side bar
st.sidebar.image("data/logo1.png",caption="Developed and Maintaned by: samir: +255675839840")
#switcher
st.sidebar.header("Please filter")
region=st.sidebar.multiselect(
"Select Region",
options=df["Region"].unique(),
default=df["Region"].unique(),
)
location=st.sidebar.multiselect(
"Select Location",
options=df["Location"].unique(),
default=df["Location"].unique(),
)
construction=st.sidebar.multiselect(
"Select Construction",
options=df["Construction"].unique(),
default=df["Construction"].unique(),
)
df_selection=df.query(
"Region==@region & Location==@location & Construction ==@construction"
)
def Home():
with st.expander("⏰ My Excel WorkBook"):
showData=st.multiselect('Filter: ',df_selection.columns,default=["Policy","Expiry","Location","State","Region","Investment","Construction","BusinessType","Earthquake","Flood","Rating"])
st.dataframe(df_selection[showData],use_container_width=True)
#compute top analytics
total_investment = float(df_selection['Investment'].sum())
investment_mode = float(df_selection['Investment'].mode())
investment_mean = float(df_selection['Investment'].mean())
investment_median= float(df_selection['Investment'].median())
rating = float(df_selection['Rating'].sum())
total1,total2,total3,total4,total5=st.columns(5,gap='large')
with total1:
st.info('Total Investment',icon="📌")
st.metric(label="sum TZS",value=f"{total_investment:,.0f}")
with total2:
st.info('Most frequent',icon="📌")
st.metric(label="mode TZS",value=f"{investment_mode:,.0f}")
with total3:
st.info('Average',icon="📌")
st.metric(label="average TZS",value=f"{investment_mean:,.0f}")
with total4:
st.info('Central Earnings',icon="📌")
st.metric(label="median TZS",value=f"{investment_median:,.0f}")
with total5:
st.info('Ratings',icon="📌")
st.metric(label="Rating",value=numerize(rating),help=f""" Total Rating: {rating} """)
st.markdown("""---""")
#graphs
def graphs():
#total_investment=int(df_selection["Investment"]).sum()
#averageRating=int(round(df_selection["Rating"]).mean(),2)
#simple bar graph
investment_by_business_type=(
df_selection.groupby(by=["BusinessType"]).count()[["Investment"]].sort_values(by="Investment")
)
fig_investment=px.bar(
investment_by_business_type,
x="Investment",
y=investment_by_business_type.index,
orientation="h",
title="<b> Investment by Business Type </b>",
color_discrete_sequence=["#0083B8"]*len(investment_by_business_type),
template="plotly_white",
)
fig_investment.update_layout(
plot_bgcolor="rgba(0,0,0,0)",
xaxis=(dict(showgrid=False))
)
#simple line graph
investment_state=df_selection.groupby(by=["State"]).count()[["Investment"]]
fig_state=px.line(
investment_state,
x=investment_state.index,
y="Investment",
orientation="v",
title="<b> Investment by State </b>",
color_discrete_sequence=["#0083b8"]*len(investment_state),
template="plotly_white",
)
fig_state.update_layout(
xaxis=dict(tickmode="linear"),
plot_bgcolor="rgba(0,0,0,0)",
yaxis=(dict(showgrid=False))
)
left,right,center=st.columns(3)
left.plotly_chart(fig_state,use_container_width=True)
right.plotly_chart(fig_investment,use_container_width=True)
with center:
#pie chart
fig = px.pie(df_selection, values='Rating', names='State', title='Regions by Ratings')
fig.update_layout(legend_title="Regions", legend_y=0.9)
fig.update_traces(textinfo='percent+label', textposition='inside')
st.plotly_chart(fig, use_container_width=True, theme=theme_plotly)
def Progressbar():
st.markdown("""<style>.stProgress > div > div > div > div { background-image: linear-gradient(to right, #99ff99 , #FFFF00)}</style>""",unsafe_allow_html=True,)
target=3000000000
current=df_selection["Investment"].sum()
percent=round((current/target*100))
mybar=st.progress(0)
if percent>100:
st.subheader("Target done !")
else:
st.write("you have ",percent, "% " ,"of ", (format(target, 'd')), "TZS")
for percent_complete in range(percent):
time.sleep(0.1)
mybar.progress(percent_complete+1,text=" Target Percentage")
def sideBar():
with st.sidebar:
selected=option_menu(
menu_title="Main Menu",
options=["Home","Progress"],
icons=["house","eye"],
menu_icon="cast",
default_index=0
)
if selected=="Home":
#st.subheader(f"Page: {selected}")
Home()
graphs()
if selected=="Progress":
#st.subheader(f"Page: {selected}")
Progressbar()
graphs()
sideBar()
#theme
hide_st_style="""
<style>
#MainMenu {visibility:hidden;}
footer {visibility:hidden;}
header {visibility:hidden;}
</style>
"""