Jan Mühlnikel
commited on
Commit
•
e3302f1
1
Parent(s):
55a6bd8
added country and orga filter
Browse files
__pycache__/similarity_page.cpython-310.pyc
CHANGED
Binary files a/__pycache__/similarity_page.cpython-310.pyc and b/__pycache__/similarity_page.cpython-310.pyc differ
|
|
functions/__pycache__/filter_projects.cpython-310.pyc
CHANGED
Binary files a/functions/__pycache__/filter_projects.cpython-310.pyc and b/functions/__pycache__/filter_projects.cpython-310.pyc differ
|
|
functions/filter_projects.py
CHANGED
@@ -4,8 +4,11 @@ def contains_code(crs_codes, code_list):
|
|
4 |
codes = str(crs_codes).split(';')
|
5 |
return any(code in code_list for code in codes)
|
6 |
|
7 |
-
def filter_projects(df, crs3_list, crs5_list, sdg_str):
|
|
|
8 |
if crs3_list != [] or crs5_list != [] or sdg_str != "":
|
|
|
|
|
9 |
if crs3_list and not crs5_list:
|
10 |
df = df[df['crs_3_code'].apply(lambda x: contains_code(x, crs3_list))]
|
11 |
elif crs3_list and crs5_list:
|
@@ -13,9 +16,24 @@ def filter_projects(df, crs3_list, crs5_list, sdg_str):
|
|
13 |
elif not crs3_list and crs5_list:
|
14 |
df = df[df['crs_5_code'].apply(lambda x: contains_code(x, crs5_list))]
|
15 |
|
|
|
16 |
if sdg_str != "":
|
17 |
df = df[df["sgd_pred_code"] == int(sdg_str)]
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
return df
|
20 |
|
21 |
|
|
|
4 |
codes = str(crs_codes).split(';')
|
5 |
return any(code in code_list for code in codes)
|
6 |
|
7 |
+
def filter_projects(df, crs3_list, crs5_list, sdg_str, country_code_list, orga_code_list):
|
8 |
+
# Check if filters where not all should be selected are empty
|
9 |
if crs3_list != [] or crs5_list != [] or sdg_str != "":
|
10 |
+
|
11 |
+
# FILTER CRS
|
12 |
if crs3_list and not crs5_list:
|
13 |
df = df[df['crs_3_code'].apply(lambda x: contains_code(x, crs3_list))]
|
14 |
elif crs3_list and crs5_list:
|
|
|
16 |
elif not crs3_list and crs5_list:
|
17 |
df = df[df['crs_5_code'].apply(lambda x: contains_code(x, crs5_list))]
|
18 |
|
19 |
+
# FILTER SDG
|
20 |
if sdg_str != "":
|
21 |
df = df[df["sgd_pred_code"] == int(sdg_str)]
|
22 |
|
23 |
+
# FILTER COUNTRY
|
24 |
+
if country_code_list != []:
|
25 |
+
country_filtered_df = pd.DataFrame()
|
26 |
+
for c in country_code_list:
|
27 |
+
c_df = df[df["country"].str.contains(c, na=False)]
|
28 |
+
country_filtered_df = pd.concat([country_filtered_df, c_df], ignore_index=True)
|
29 |
+
|
30 |
+
df = country_filtered_df
|
31 |
+
|
32 |
+
# FILTER ORGANIZATION
|
33 |
+
if orga_code_list != []:
|
34 |
+
df = df[df['orga_abbreviation'].isin(orga_code_list)]
|
35 |
+
|
36 |
+
|
37 |
return df
|
38 |
|
39 |
|
modules/filter_modules.py
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import streamlit as st
|
3 |
-
|
4 |
-
def country_option(special_cases, country_names):
|
5 |
-
country_option = st.multiselect(
|
6 |
-
'Country / Countries',
|
7 |
-
special_cases + country_names,
|
8 |
-
placeholder="Select"
|
9 |
-
)
|
10 |
-
|
11 |
-
return country_option
|
12 |
-
|
13 |
-
def orga_option(special_cases, orga_names):
|
14 |
-
orga_list = special_cases + [f"{v[0]} ({k})" for k, v in orga_names.items()]
|
15 |
-
orga_option = st.multiselect(
|
16 |
-
'Development Bank / Organization',
|
17 |
-
orga_list,
|
18 |
-
placeholder="Select"
|
19 |
-
)
|
20 |
-
|
21 |
-
return orga_option
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
similarity_page.py
CHANGED
@@ -79,6 +79,18 @@ def getSDG():
|
|
79 |
|
80 |
return SDG_NAMES
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# Load Sentence Transformer Model
|
83 |
@st.cache_resource
|
84 |
def load_model():
|
@@ -110,6 +122,8 @@ CRS3_MERGED = getCRS3()
|
|
110 |
CRS5_MERGED = getCRS5()
|
111 |
SDG_NAMES = getSDG()
|
112 |
|
|
|
|
|
113 |
model = load_model()
|
114 |
sentences, embeddings, faiss_index = load_embeddings_and_index()
|
115 |
|
@@ -153,7 +167,25 @@ def show_page():
|
|
153 |
|
154 |
|
155 |
with col2:
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
|
159 |
# CRS CODE LIST
|
@@ -166,8 +198,14 @@ def show_page():
|
|
166 |
else:
|
167 |
sdg_str = ""
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
# FILTER DF WITH SELECTED FILTER OPTIONS
|
170 |
-
filtered_df = filter_projects(projects_df, crs3_list, crs5_list, sdg_str)
|
171 |
|
172 |
# FIND MATCHES
|
173 |
p1_df, p2_df = calc_matches(filtered_df, projects_df, sim_matrix)
|
|
|
79 |
|
80 |
return SDG_NAMES
|
81 |
|
82 |
+
# Load Country Data
|
83 |
+
@st.cache_data
|
84 |
+
def getCountry():
|
85 |
+
# Read in countries from codelist
|
86 |
+
country_df = pd.read_csv('src/codelists/country_codes_ISO3166-1alpha-2.csv')
|
87 |
+
COUNTRY_CODES = country_df['Alpha-2 code'].tolist()
|
88 |
+
COUNTRY_NAMES = country_df['Country'].tolist()
|
89 |
+
|
90 |
+
COUNTRY_OPTION_LIST = [f"{COUNTRY_NAMES[i]} ({COUNTRY_CODES[i][-3:-1].upper()})"for i in range(len(COUNTRY_NAMES))]
|
91 |
+
|
92 |
+
return COUNTRY_OPTION_LIST
|
93 |
+
|
94 |
# Load Sentence Transformer Model
|
95 |
@st.cache_resource
|
96 |
def load_model():
|
|
|
122 |
CRS5_MERGED = getCRS5()
|
123 |
SDG_NAMES = getSDG()
|
124 |
|
125 |
+
COUNTRY_OPTION_LIST = getCountry()
|
126 |
+
|
127 |
model = load_model()
|
128 |
sentences, embeddings, faiss_index = load_embeddings_and_index()
|
129 |
|
|
|
167 |
|
168 |
|
169 |
with col2:
|
170 |
+
# COUNTRY SELECTION
|
171 |
+
|
172 |
+
|
173 |
+
country_option = st.multiselect(
|
174 |
+
'Country / Countries',
|
175 |
+
COUNTRY_OPTION_LIST,
|
176 |
+
placeholder="Select"
|
177 |
+
)
|
178 |
+
|
179 |
+
# ORGA SELECTION
|
180 |
+
orga_abbreviation = projects_df["orga_abbreviation"].unique()
|
181 |
+
orga_full_names = projects_df["orga_full_name"].unique()
|
182 |
+
orga_list = [f"{orga_full_names[i]} ({orga_abbreviation[i].upper()})"for i in range(len(orga_abbreviation))]
|
183 |
+
|
184 |
+
orga_option = st.multiselect(
|
185 |
+
'Development Bank / Organization',
|
186 |
+
orga_list,
|
187 |
+
placeholder="Select"
|
188 |
+
)
|
189 |
|
190 |
|
191 |
# CRS CODE LIST
|
|
|
198 |
else:
|
199 |
sdg_str = ""
|
200 |
|
201 |
+
# COUNTRY CODES LIST
|
202 |
+
country_code_list = [option[-3:-1] for option in country_option]
|
203 |
+
|
204 |
+
# ORGANIZATION CODES LIST
|
205 |
+
orga_code_list = [option.split("(")[1][:-1].lower() for option in orga_option]
|
206 |
+
|
207 |
# FILTER DF WITH SELECTED FILTER OPTIONS
|
208 |
+
filtered_df = filter_projects(projects_df, crs3_list, crs5_list, sdg_str, country_code_list, orga_code_list)
|
209 |
|
210 |
# FIND MATCHES
|
211 |
p1_df, p2_df = calc_matches(filtered_df, projects_df, sim_matrix)
|