Jan Mühlnikel commited on
Commit
784ae4f
1 Parent(s): 83fabd0

rmv checkboxes

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__/single_similar.cpython-310.pyc CHANGED
Binary files a/functions/__pycache__/single_similar.cpython-310.pyc and b/functions/__pycache__/single_similar.cpython-310.pyc differ
 
functions/single_similar.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
 
4
  def find_similar(p_index, similarity_matrix, projects_df, top_x):
5
  selected_row = similarity_matrix[p_index]
6
- top_indexes = np.argsort(selected_row)[-10:][::-1]
7
  top_values = selected_row[top_indexes]
8
 
9
  top_projects_df = projects_df.iloc[top_indexes]
 
3
 
4
  def find_similar(p_index, similarity_matrix, projects_df, top_x):
5
  selected_row = similarity_matrix[p_index]
6
+ top_indexes = np.argsort(selected_row)[-top_x:][::-1]
7
  top_values = selected_row[top_indexes]
8
 
9
  top_projects_df = projects_df.iloc[top_indexes]
modules/singlematch_result_table.py CHANGED
@@ -3,81 +3,84 @@ import pandas as pd
3
 
4
  def show_single_table(result_df):
5
 
6
- result_df = result_df.reset_index(drop=True)
 
 
 
7
 
8
- # Transformations
9
- result_df["crs_3_code_list"] = result_df['crs_3_code'].str.split(";").apply(lambda x: x[:-1] if x else [])
10
- result_df["crs_5_code_list"] = result_df['crs_5_code'].str.split(";").apply(lambda x: x[:-1] if x else [])
11
- result_df["sdg_list"] = result_df['sgd_pred_code'].apply(lambda x: [x] if pd.notna(x) else [])
12
- result_df["flag"] = result_df['country'].apply(lambda x: f"https://flagicons.lipis.dev/flags/4x3/{x[:2].lower()}.svg" if pd.notna(x) else "https://flagicons.lipis.dev/flags/4x3/xx.svg")
13
-
14
- st.dataframe(
15
- result_df[["similarity", "iati_id", "title_main", "orga_abbreviation", "client", "description_main", "country", "flag", "sdg_list", "crs_3_code_list", "crs_5_code_list"]],
16
- use_container_width = True,
17
- height = 35 + 35 * len(result_df),
18
- column_config={
19
- "similarity": st.column_config.TextColumn(
20
- "Similarity",
21
- help="similarity to selected project",
22
- disabled=True,
23
- width="small"
24
- ),
25
- "iati_id": st.column_config.TextColumn(
26
- "IATI ID",
27
- help="IATI Project ID",
28
- disabled=True,
29
- width="small"
30
- ),
31
- "orga_abbreviation": st.column_config.TextColumn(
32
- "Organization",
33
- help="If description not in English, description in other language provided",
34
- disabled=True,
35
- width="small"
36
- ),
37
- "client": st.column_config.TextColumn(
38
- "Client",
39
- help="Client organization of customer",
40
- disabled=True,
41
- width="small"
42
- ),
43
- "title_main": st.column_config.TextColumn(
44
- "Title",
45
- help="If title not in English, title in other language provided",
46
- disabled=True,
47
- width="large"
48
- ),
49
- "description_main": st.column_config.TextColumn(
50
- "Description",
51
- help="If description not in English, description in other language provided",
52
- disabled=True,
53
- width="large"
54
- ),
55
- "country": st.column_config.TextColumn(
56
- "Country",
57
- help="Country of project",
58
- disabled=True,
59
- width="small"
60
- ),
61
- "flag": st.column_config.ImageColumn(
62
- "Flag",
63
- help="country flag",
64
- width="small"
65
- ),
66
- "sdg_list": st.column_config.ListColumn(
67
- "SDG Prediction",
68
- help="Prediction of SDG's",
69
- width="small"
70
- ),
71
- "crs_3_code_list": st.column_config.ListColumn(
72
- "CRS 3",
73
- help="CRS 3 code given by organization",
74
- width="small"
75
- ),
76
- "crs_5_code_list": st.column_config.ListColumn(
77
- "CRS 5",
78
- help="CRS 5 code given by organization",
79
- width="small"
80
- ),
81
- },
82
- hide_index=True,
83
- )
 
3
 
4
  def show_single_table(result_df):
5
 
6
+ if len(result_df) == 0:
7
+ st.write("No resuolts found!")
8
+ else:
9
+ result_df = result_df.reset_index(drop=True)
10
 
11
+ # Transformations
12
+ result_df["crs_3_code_list"] = result_df['crs_3_code'].str.split(";").apply(lambda x: x[:-1] if x else [])
13
+ result_df["crs_5_code_list"] = result_df['crs_5_code'].str.split(";").apply(lambda x: x[:-1] if x else [])
14
+ result_df["sdg_list"] = result_df['sgd_pred_code'].apply(lambda x: [x] if pd.notna(x) else [])
15
+ result_df["flag"] = result_df['country'].apply(lambda x: f"https://flagicons.lipis.dev/flags/4x3/{x[:2].lower()}.svg" if pd.notna(x) else "https://flagicons.lipis.dev/flags/4x3/xx.svg")
16
+
17
+ st.dataframe(
18
+ result_df[["similarity", "iati_id", "title_main", "orga_abbreviation", "client", "description_main", "country", "flag", "sdg_list", "crs_3_code_list", "crs_5_code_list"]],
19
+ use_container_width = True,
20
+ height = 35 + 35 * len(result_df),
21
+ column_config={
22
+ "similarity": st.column_config.TextColumn(
23
+ "Similarity",
24
+ help="similarity to selected project",
25
+ disabled=True,
26
+ width="small"
27
+ ),
28
+ "iati_id": st.column_config.TextColumn(
29
+ "IATI ID",
30
+ help="IATI Project ID",
31
+ disabled=True,
32
+ width="small"
33
+ ),
34
+ "orga_abbreviation": st.column_config.TextColumn(
35
+ "Organization",
36
+ help="If description not in English, description in other language provided",
37
+ disabled=True,
38
+ width="small"
39
+ ),
40
+ "client": st.column_config.TextColumn(
41
+ "Client",
42
+ help="Client organization of customer",
43
+ disabled=True,
44
+ width="small"
45
+ ),
46
+ "title_main": st.column_config.TextColumn(
47
+ "Title",
48
+ help="If title not in English, title in other language provided",
49
+ disabled=True,
50
+ width="large"
51
+ ),
52
+ "description_main": st.column_config.TextColumn(
53
+ "Description",
54
+ help="If description not in English, description in other language provided",
55
+ disabled=True,
56
+ width="large"
57
+ ),
58
+ "country": st.column_config.TextColumn(
59
+ "Country",
60
+ help="Country of project",
61
+ disabled=True,
62
+ width="small"
63
+ ),
64
+ "flag": st.column_config.ImageColumn(
65
+ "Flag",
66
+ help="country flag",
67
+ width="small"
68
+ ),
69
+ "sdg_list": st.column_config.ListColumn(
70
+ "SDG Prediction",
71
+ help="Prediction of SDG's",
72
+ width="small"
73
+ ),
74
+ "crs_3_code_list": st.column_config.ListColumn(
75
+ "CRS 3",
76
+ help="CRS 3 code given by organization",
77
+ width="small"
78
+ ),
79
+ "crs_5_code_list": st.column_config.ListColumn(
80
+ "CRS 5",
81
+ help="CRS 5 code given by organization",
82
+ width="small"
83
+ ),
84
+ },
85
+ hide_index=True,
86
+ )
similarity_page.py CHANGED
@@ -268,24 +268,26 @@ def show_single_matching_page():
268
  options = search_list,
269
  )
270
 
271
- different_orga_checkbox_ = st.checkbox("Only matches for organisations other than the selected project")
272
- filterd_country_only_checkbox_ = st.checkbox("Only matches in the same countries as project selection")
273
 
 
274
  if project_option:
 
275
 
 
276
  if filterd_country_only_checkbox_:
277
  country = projects_df.iloc[selected_index]["country"]
278
  same_country_df = projects_df[projects_df['country'] == country]
279
  else:
280
  same_country_df = projects_df
281
 
282
- selected_index = search_list.index(project_option)
283
  if different_orga_checkbox_:
284
  orga = projects_df.iloc[selected_index]["orga_abbreviation"]
285
  different_orga_df = same_country_df[same_country_df['orga_abbreviation'] != orga]
286
  else:
287
  different_orga_df = same_country_df
288
-
289
- top_projects_df = find_similar(selected_index, sim_matrix, different_orga_df, 10)
290
  show_single_table(top_projects_df)
291
 
 
268
  options = search_list,
269
  )
270
 
271
+ #different_orga_checkbox_ = st.checkbox("Only matches for organisations other than the selected project")
272
+ #filterd_country_only_checkbox_ = st.checkbox("Only matches in the same countries as project selection")
273
 
274
+ #selected_index = None
275
  if project_option:
276
+ selected_index = search_list.index(project_option)
277
 
278
+ """
279
  if filterd_country_only_checkbox_:
280
  country = projects_df.iloc[selected_index]["country"]
281
  same_country_df = projects_df[projects_df['country'] == country]
282
  else:
283
  same_country_df = projects_df
284
 
 
285
  if different_orga_checkbox_:
286
  orga = projects_df.iloc[selected_index]["orga_abbreviation"]
287
  different_orga_df = same_country_df[same_country_df['orga_abbreviation'] != orga]
288
  else:
289
  different_orga_df = same_country_df
290
+ """
291
+ top_projects_df = find_similar(selected_index, sim_matrix, projects_df, 10)
292
  show_single_table(top_projects_df)
293