-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
127 lines (98 loc) · 3.85 KB
/
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import streamlit as st
from streamlit_autorefresh import st_autorefresh
from collect_data import *
import plotly.express as px
from pre import pre_process_inflow_data
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
import plotly.express as px
def update_data():
# Perform some request to get a dataframe
get_river_flow_data()
get_sindh_barage_data()
print('refreshed data')
def save_data(df1,df2):
df1.to_excel('flow_Data.xlsx')
df2.to_excel('barage_data.xlsx')
print('made backup data')
# st_autorefresh(interval= 86400 * 1000, key="dataframerefresh")
#
# st.dataframe(update_data())
#
# st_autorefresh(interval= 15*86400 * 1000, key="savedfrefresh")
#
# st.savedf(save_data())
st.set_page_config(layout="wide")
st.header('Live Indus Dashboard')
st.sidebar.title('Select Ploting Options')
# select data
rivers = ['Indus','Jhelum', 'Chenab', 'Kabul']
river_dict = {'Tarbela':'Indus','Mangla':'Jhelum'}
river_ops = st.sidebar.radio("River Inflow plot", rivers)
#lev_rivers = ['Indus','Jhelum']
river_lev = st.sidebar.radio("Reservoir level plot", river_dict.keys())
reservoir_level = river_dict[river_lev]
barages = ['Guddu','Sukkur','Kotri']
selected_barage = st.sidebar.radio("Barage", barages)
st.sidebar.image(["logo.png","AGU_logo.png"], width=100)
#st.sidebar.image("logo.png", width=100)
#st.sidebar.image("AGU_logo.png", width=100)
#retrieve inflow data
flow_river = river_ops + '_Inflow'
df = pre_process_inflow_data()
level_reservoir = reservoir_level + '_levels'
file = 'Sindh_barage.xlsx'
dfb = pd.read_excel(file)
barage_df = dfb.loc[dfb['Station'] == selected_barage]
cutoff = 1380
if reservoir_level=='Jhelum':
cutoff = 1000
reservior_data = df[df[level_reservoir]>cutoff]
if river_ops == 'Kabul':
Inflow_Data = df[df[flow_river]<250.0]
else :
Inflow_Data = df
#ploting data
fig = make_subplots(
rows=2, cols=2,
specs=[[{"colspan": 2}, None],[{}, {}]],
subplot_titles=('Streamflow of '+ river_ops,
"Reservoir Levels Time Series",
"Barage Flow Time Series"))
# fig.update_yaxes(title_text="1000 X cusecs", row=1, col=1)
# fig.update_yaxes(title_text="ft", range=[10, 50], row=2, col=1)
# fig.update_yaxes(title_text="1000 cusecs", row=2, col=2)
fig.update_yaxes(title_text="1000 X cusecs", row=1, col=1)
fig.update_yaxes(title_text="feet", row=2, col=1)
fig.update_yaxes(title_text="1000 cusecs", showgrid=False, row=2, col=2)
date_list, data = zip(*sorted(zip(Inflow_Data['Time'], Inflow_Data[flow_river])))
date_list1, data1 = zip(*sorted(zip(reservior_data['Time'], reservior_data[level_reservoir])))
#plt.plot(date_list, data)
fig.add_trace(go.Scatter(x=date_list, y=data),row=1, col=1)
fig.add_trace(go.Scatter(x=date_list1, y=data1,showlegend = False),row=2, col=1)
fig.add_trace(go.Scatter(name ='Today',x=barage_df['Time'], y=barage_df['Today']), row=2, col=2)
fig.add_trace(go.Scatter(name ='Last Year',x=barage_df['Time'], y=barage_df['Last Year']),row=2, col=2)
fig.update_layout(height=800, width=1000, showlegend=True, title_text="Indus River System Analytics", legend = dict(yanchor="top",y=0.45))
st.write(fig)
st.text("")
# Provide references
st.subheader("Data Sources")
st.markdown(
"""
1. River inflows and reservoir levels are obtained from http://www.wapda.gov.pk/index.php/river-flow-data.
2. Barrage levels are obtained from http://www.wapda.gov.pk/index.php/hydroreservior-in-pakistan?tmpl=component&id=43
"""
)
st.text("")
# download = st.button('Download Shape File')
# shape_file_dict = {'chenab':'newchenab.shp',
# 'Kabul':'krbshape.shp',
# 'Indus':'Indus_complete.shp',
# 'tarbela':'newtarbela.shp',
# 'mangla': 'newmangla.shp'}
# if download:
# print('Download Started!')