nouamanetazi HF staff commited on
Commit
7d0d991
1 Parent(s): 597fb2d
Files changed (2) hide show
  1. app.py +18 -43
  2. src/dataframes.py +52 -0
app.py CHANGED
@@ -4,7 +4,6 @@ from src.markers import display_interventions, display_solved, show_requests, sh
4
  from src.filters import show_requests_filters, show_interventions_filters
5
 
6
  import folium
7
- import pandas as pd
8
  import streamlit as st
9
  from huggingface_hub import HfApi
10
  from streamlit_folium import st_folium
@@ -14,19 +13,13 @@ from src.text_content import (
14
  LOGO,
15
  SLOGAN,
16
  )
17
- from src.utils import add_latlng_col, init_map, parse_gg_sheet, is_request_in_list, parse_json_file
18
  from src.map_utils import get_legend_macro
19
  from src.dataframes import display_dataframe
 
20
 
21
  TOKEN = os.environ.get("HF_TOKEN", None)
22
- VERIFIED_REQUESTS_URL = (
23
- "https://docs.google.com/spreadsheets/d/1PXcAtI5L95hHSXAiRl3Y4v5O4coG39S86OTfBEcvLTE/edit#gid=0"
24
- )
25
- REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
26
- INTERVENTIONS_URL = (
27
- "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
28
- )
29
- DOUARS_URL = "data/regions.json"
30
  api = HfApi(TOKEN)
31
 
32
 
@@ -49,49 +42,31 @@ if auto_refresh:
49
  number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time)
50
  st.session_state.sleep_time = number
51
 
52
-
53
- # Streamlit functions
54
-
55
  # Logo and Title
56
  st.markdown(LOGO, unsafe_allow_html=True)
57
  # st.title("Nt3awnou نتعاونو")
58
  st.markdown(SLOGAN, unsafe_allow_html=True)
59
 
 
60
  m, emergency_fgs, intervention_fgs = init_map()
61
  fg = folium.FeatureGroup(name="Markers")
62
 
63
  # Selection of requests
64
-
65
  selected_options, options, show_unverified, show_interventions = show_requests_filters()
66
- # Load data and initialize map with plugins
67
- df = parse_gg_sheet(REQUESTS_URL)
68
- if show_unverified:
69
- df = add_latlng_col(df, process_column=15)
70
- interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
71
- interventions_df = add_latlng_col(interventions_df, process_column="Automatic Extracted Coordinates")
72
- verified_df = parse_gg_sheet(VERIFIED_REQUESTS_URL)
73
- verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
74
- douar_df = parse_json_file(DOUARS_URL)
75
-
76
- # check if verified requests have been solved
77
- solved_verified_requests = verified_df[~pd.isnull(verified_df["Status"])]
78
- verified_df = verified_df[pd.isnull(verified_df["Status"])]
79
-
80
- len_requests = len(df)
81
- len_interventions = len(interventions_df)
82
- len_verified_requests = len(verified_df)
83
- len_solved_verified_requests = len(solved_verified_requests)
84
-
85
- df["id"] = df.index # Needed to display request id
86
- verified_df["id"] = verified_df.index # Needed to display request id
87
- # keep rows with at least one request in selected_options
88
- filtered_df = df[
89
- df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(lambda x: is_request_in_list(x, selected_options, options))
90
- ]
91
- filtered_verified_df = verified_df[
92
- verified_df["Help Details"].apply(lambda x: is_request_in_list(x, selected_options, options))
93
- ]
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  # Selection of interventions
97
  (
@@ -111,7 +86,7 @@ if show_unverified:
111
  show_requests(filtered_df, fg)
112
 
113
  # Add verified requests markers to map
114
- show_verified_requests(verified_df, emergency_fgs)
115
 
116
  # Add legend
117
  legend_macro = get_legend_macro(show_unverified)
 
4
  from src.filters import show_requests_filters, show_interventions_filters
5
 
6
  import folium
 
7
  import streamlit as st
8
  from huggingface_hub import HfApi
9
  from streamlit_folium import st_folium
 
13
  LOGO,
14
  SLOGAN,
15
  )
16
+ from src.utils import init_map
17
  from src.map_utils import get_legend_macro
18
  from src.dataframes import display_dataframe
19
+ from src.dataframes import load_data, VERIFIED_REQUESTS_URL, REQUESTS_URL, INTERVENTIONS_URL
20
 
21
  TOKEN = os.environ.get("HF_TOKEN", None)
22
+
 
 
 
 
 
 
 
23
  api = HfApi(TOKEN)
24
 
25
 
 
42
  number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time)
43
  st.session_state.sleep_time = number
44
 
 
 
 
45
  # Logo and Title
46
  st.markdown(LOGO, unsafe_allow_html=True)
47
  # st.title("Nt3awnou نتعاونو")
48
  st.markdown(SLOGAN, unsafe_allow_html=True)
49
 
50
+ # Initialize map
51
  m, emergency_fgs, intervention_fgs = init_map()
52
  fg = folium.FeatureGroup(name="Markers")
53
 
54
  # Selection of requests
 
55
  selected_options, options, show_unverified, show_interventions = show_requests_filters()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ # Load data
58
+ (
59
+ df,
60
+ filtered_df,
61
+ interventions_df,
62
+ verified_df,
63
+ filtered_verified_df,
64
+ solved_verified_requests,
65
+ douar_df,
66
+ len_requests,
67
+ len_interventions,
68
+ len_solved_verified_requests,
69
+ ) = load_data(show_unverified, selected_options, options)
70
 
71
  # Selection of interventions
72
  (
 
86
  show_requests(filtered_df, fg)
87
 
88
  # Add verified requests markers to map
89
+ show_verified_requests(filtered_verified_df, emergency_fgs)
90
 
91
  # Add legend
92
  legend_macro = get_legend_macro(show_unverified)
src/dataframes.py CHANGED
@@ -1,5 +1,57 @@
1
 
2
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
  def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for_help_requests=False, show_link=True):
 
1
 
2
  import streamlit as st
3
+ from src.utils import add_latlng_col, parse_gg_sheet, parse_json_file, is_request_in_list
4
+ import pandas as pd
5
+
6
+ VERIFIED_REQUESTS_URL = (
7
+ "https://docs.google.com/spreadsheets/d/1PXcAtI5L95hHSXAiRl3Y4v5O4coG39S86OTfBEcvLTE/edit#gid=0"
8
+ )
9
+ REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
10
+ INTERVENTIONS_URL = (
11
+ "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
12
+ )
13
+ DOUARS_URL = "data/regions.json"
14
+
15
+ def load_data(show_unverified, selected_options, options):
16
+ df = parse_gg_sheet(REQUESTS_URL)
17
+ if show_unverified:
18
+ df = add_latlng_col(df, process_column=15)
19
+ interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
20
+ interventions_df = add_latlng_col(interventions_df, process_column="Automatic Extracted Coordinates")
21
+ verified_df = parse_gg_sheet(VERIFIED_REQUESTS_URL)
22
+ verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
23
+ douar_df = parse_json_file(DOUARS_URL)
24
+
25
+ # check if verified requests have been solved
26
+ solved_verified_requests = verified_df[~pd.isnull(verified_df["Status"])]
27
+ verified_df = verified_df[pd.isnull(verified_df["Status"])]
28
+
29
+ len_requests = len(df)
30
+ len_interventions = len(interventions_df)
31
+ len_solved_verified_requests = len(solved_verified_requests)
32
+
33
+ df["id"] = df.index # Needed to display request id
34
+ verified_df["id"] = verified_df.index # Needed to display request id
35
+ # keep rows with at least one request in selected_options
36
+ filtered_df = df[
37
+ df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(lambda x: is_request_in_list(x, selected_options, options))
38
+ ]
39
+ filtered_verified_df = verified_df[
40
+ verified_df["Help Details"].apply(lambda x: is_request_in_list(x, selected_options, options))
41
+ ]
42
+ return (
43
+ df,
44
+ filtered_df,
45
+ interventions_df,
46
+ verified_df,
47
+ filtered_verified_df,
48
+ solved_verified_requests,
49
+ douar_df,
50
+ len_requests,
51
+ len_interventions,
52
+ len_solved_verified_requests,
53
+ )
54
+
55
 
56
 
57
  def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for_help_requests=False, show_link=True):