-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (49 loc) · 2.12 KB
/
main.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
from request_process import RequestProcess as rp
from data_process import DataProcess as dp
from map_visualization_process import MapVisualizationProcess
from streamlit_tools import StreamlitTools, st
import warnings
warnings.filterwarnings('ignore')
st.set_page_config(layout="wide")
def display_title():
"""Display the main title of the application."""
st.markdown("<center><h2>Turkey Earthquake</h2></center>", unsafe_allow_html=True)
def setup_sidebar(slt):
"""Set up the sidebar tools using StreamlitTools."""
st.sidebar.title("Select Range for Data Filter")
slt.sidebar_tools()
def run_filter_button():
"""Display and handle the Run Filter button action."""
return st.sidebar.button("Run Filter")
def display_data(dataframe):
"""Display the filtered data and the visualization map."""
st.dataframe(dataframe[["day", "time", "magnitude", "depth", "location"]], use_container_width=True)
st.components.v1.html(open('map.html', 'r').read(), width=None, height=st.session_state.get('map_height', 700))
def display_no_data():
"""Display a message if no data is found."""
st.markdown("<center><h2>Data Not Found :(</h2></center>", unsafe_allow_html=True)
def fetch_and_filter_data(slt, rp_instance, dp_instance):
"""Fetch and filter data based on user inputs."""
data = rp_instance.get_request(*slt.date_range)
if data:
dataframe = dp_instance.data_filter(data, *slt.date_range, slt.option_filter)
return dataframe, True
return None, None
def main():
"""Main function to run the Streamlit app."""
display_title()
slt = StreamlitTools()
setup_sidebar(slt)
if run_filter_button():
dataframe, control = fetch_and_filter_data(slt, rp(), dp())
if control:
mvp = MapVisualizationProcess()
mvp.map_visualization(dataframe, slt.type)
display_data(dataframe)
else:
# Display message if no data
display_no_data()
else:
st.markdown("<center><h5>Please Press Run Button to See The Result</h5></center>", unsafe_allow_html=True)
if __name__ == "__main__":
main()