├── Main.py ├── README.md ├── UI.py ├── __pycache__ └── UI.cpython-311.pyc ├── data.xlsx ├── pages └── 🌎 Add Record.py ├── requirements.txt └── style.css /Main.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import streamlit.components.v1 as stc 4 | import plotly.express as px 5 | import time 6 | from streamlit_option_menu import option_menu 7 | from numerize.numerize import numerize 8 | import plotly.express as px 9 | import plotly.subplots as sp 10 | import plotly.graph_objects as go 11 | 12 | #page behaviour 13 | st.set_page_config(page_title="Descriptive Analytics ", page_icon="🌎", layout="wide") 14 | 15 | #remove default theme 16 | theme_plotly = None # None or streamlit 17 | 18 | 19 | # CSS Style 20 | with open('style.css')as f: 21 | st.markdown(f"", unsafe_allow_html = True) 22 | 23 | #load excel file 24 | df=pd.read_excel('data.xlsx', sheet_name='Sheet1') 25 | 26 | 27 | #2. switcher 28 | st.sidebar.header("Please Filter Here:") 29 | region= st.sidebar.multiselect( 30 | "Select the Region:", 31 | options=df["Region"].unique(), 32 | default=df["Region"].unique() 33 | ) 34 | location = st.sidebar.multiselect( 35 | "Select the Location:", 36 | options=df["Location"].unique(), 37 | default=df["Location"].unique(), 38 | ) 39 | construction = st.sidebar.multiselect( 40 | "Select the Construction:", 41 | options=df["Construction"].unique(), 42 | default=df["Construction"].unique() 43 | 44 | 45 | ) 46 | df_selection = df.query( 47 | "Region == @region & Location ==@location & Construction == @construction" 48 | ) 49 | 50 | #method/function 51 | 52 | def HomePage(): 53 | #1. print dataframe 54 | with st.expander("🧭 My database"): 55 | #st.dataframe(df_selection,use_container_width=True) 56 | shwdata = st.multiselect('Filter :', df_selection.columns, default=[]) 57 | st.dataframe(df_selection[shwdata],use_container_width=True) 58 | 59 | #2. compute top Analytics 60 | 61 | total_investment = float(df_selection['Investment'].sum()) 62 | investment_mode = float(df_selection['Investment'].mode()) 63 | investment_mean = float(df_selection['Investment'].mean()) 64 | investment_median= float(df_selection['Investment'].median()) 65 | rating = float(df_selection['Rating'].sum()) 66 | 67 | #3. columns 68 | total1,total2,total3,total4,total5 = st.columns(5,gap='large') 69 | with total1: 70 | 71 | st.info('Total Investment', icon="🔍") 72 | st.metric(label = 'sum TZS', value= f"{total_investment:,.0f}") 73 | 74 | with total2: 75 | st.info('Most frequently', icon="🔍") 76 | st.metric(label='Mode TZS', value=f"{investment_mode:,.0f}") 77 | 78 | with total3: 79 | st.info('Investment Average', icon="🔍") 80 | st.metric(label= 'Mean TZS',value=f"{investment_mean:,.0f}") 81 | 82 | with total4: 83 | st.info('Investment Marging', icon="🔍") 84 | st.metric(label='Median TZS',value=f"{investment_median:,.0f}") 85 | 86 | with total5: 87 | st.info('Ratings', icon="🔍") 88 | st.metric(label='Rating',value=numerize(rating),help=f"""Total rating: {rating}""") 89 | 90 | st.markdown("""---""") 91 | 92 | #graphs 93 | 94 | def Graphs(): 95 | total_investments = int(df_selection["Investment"].sum()) 96 | average_rating = round(df_selection["Rating"].mean(), 1) 97 | star_rating = ":star:" * int(round(average_rating, 0)) 98 | average_investment = round(df_selection["Investment"].mean(), 2) 99 | 100 | #1. simple bar graph 101 | investment_by_businessType = ( 102 | df_selection.groupby(by=["BusinessType"]).count()[["Investment"]].sort_values(by="Investment") 103 | ) 104 | fig_investment = px.bar( 105 | investment_by_businessType, 106 | x="Investment", 107 | y=investment_by_businessType.index, 108 | orientation="h", 109 | title="Investment by Business Type", 110 | color_discrete_sequence=["#0083B8"] * len(investment_by_businessType), 111 | template="plotly_white", 112 | ) 113 | 114 | fig_investment.update_layout( 115 | plot_bgcolor="rgba(0,0,0,0)", 116 | xaxis=(dict(showgrid=False)) 117 | ) 118 | 119 | #2. simple line graph------------------ 120 | investment_by_state = df_selection.groupby(by=["State"]).count()[["Investment"]] 121 | fig_state = px.line( 122 | investment_by_state, 123 | x=investment_by_state.index, 124 | orientation="v", 125 | y="Investment", 126 | title="Investment by Region ", 127 | color_discrete_sequence=["#0083B8"] * len(investment_by_state), 128 | template="plotly_white", 129 | ) 130 | fig_state.update_layout( 131 | xaxis=dict(tickmode="linear"), 132 | plot_bgcolor="rgba(0,0,0,0)", 133 | yaxis=(dict(showgrid=False)), 134 | ) 135 | 136 | left_column, right_column,center = st.columns(3) 137 | left_column.plotly_chart(fig_state, use_container_width=True) 138 | right_column.plotly_chart(fig_investment, use_container_width=True) 139 | 140 | #pie chart 141 | with center: 142 | fig = px.pie(df_selection, values='Rating', names='State', title='Regions by Ratings') 143 | fig.update_layout(legend_title="Regions", legend_y=0.9) 144 | fig.update_traces(textinfo='percent+label', textposition='inside') 145 | st.plotly_chart(fig, use_container_width=True, theme=theme_plotly) 146 | 147 | #-----PROGRESS BAR----- 148 | 149 | def ProgressBar(): 150 | st.markdown("""""",unsafe_allow_html=True,) 151 | target=3000000000 152 | current=df_selection['Investment'].sum() 153 | percent=round((current/target*100)) 154 | my_bar = st.progress(0) 155 | 156 | if percent>100: 157 | st.subheader("Target 100 complited") 158 | else: 159 | st.write("you have ", percent, " % " ," of ", (format(target, ',d')), " TZS") 160 | for percent_complete in range(percent): 161 | time.sleep(0.1) 162 | my_bar.progress(percent_complete + 1,text="Target percentage") 163 | 164 | #-----SIDE BAR----- 165 | 166 | def sideBar(): 167 | with st.sidebar: 168 | selected=option_menu( 169 | menu_title="Menu", 170 | #menu_title=None, 171 | options=["Home","Progress"], 172 | icons=["house","eye"], 173 | menu_icon="cast", #option 174 | default_index=0, #option 175 | ) 176 | if selected=="Home": 177 | try: 178 | HomePage() 179 | Graphs() 180 | except: 181 | st.warning("one or more options are mandatory ! ") 182 | 183 | 184 | if selected=="Progress": 185 | try: 186 | ProgressBar() 187 | Graphs() 188 | except: 189 | st.warning("one or more options are mandatory ! ") 190 | 191 | #print side bar 192 | sideBar() 193 | 194 | footer=""" 214 |
217 | """ 218 | st.markdown(footer,unsafe_allow_html=True) 219 | 220 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 |  10 |  11 |  12 |  13 |  14 | 15 | -------------------------------------------------------------------------------- /UI.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | def heading(): 3 | st.markdown(""" 4 | 5 | 6 |