File size: 6,137 Bytes
883557f |
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import streamlit as st
import pandas as pd
"""
Result table of the Multi Project Matching
"""
def show_multi_table(p1_df, p2_df):
"""
p1_df & p2_df from functions/multi_project_matching
"""
st.write("------------------")
p1_df = p1_df.reset_index(drop=True)
p2_df = p2_df.reset_index(drop=True)
# Convert orga_abbreviation to uppercase for the selected project
p2_df['orga_abbreviation'] = p2_df['orga_abbreviation'].str.upper()
p1_df['orga_abbreviation'] = p1_df['orga_abbreviation'].str.upper()
actual_ind = 0
# Loop to display every matching pair from p1 and p2 dfs
for i in range(0, len(p1_df), 2): # stepsize 2 to not display duplicates
actual_ind += 1
match_df = pd.DataFrame()
row_from_p1 = p1_df.iloc[[i]]
row_from_p2 = p2_df.iloc[[i]]
# INTEGRATE IN PREPROCESSING !!!
# transform strings to list
"""
Add this to preprocessing
- flag url
- crs code lists
"""
try:
row_from_p1["crs_3_code_list"] = [row_from_p1['crs_3_name'].item().split(";")[:-1]]
row_from_p2["crs_3_code_list"] = [row_from_p2['crs_3_name'].item().split(";")[:-1]]
except:
row_from_p1["crs_3_code_list"] = [""]
row_from_p2["crs_3_code_list"] = [""]
try:
row_from_p1["crs_5_code_list"] = [row_from_p1['crs_5_name'].item().split(";")[:-1]]
row_from_p2["crs_5_code_list"] = [row_from_p2['crs_5_name'].item().split(";")[:-1]]
except:
row_from_p1["crs_5_code_list"] = [""]
row_from_p2["crs_5_code_list"] = [""]
row_from_p1["sdg_list"] = [row_from_p1['sgd_pred_code'].item()]
row_from_p2["sdg_list"] = [row_from_p2['sgd_pred_code'].item()]
# Check for missing country and set flag URL accordingly
def get_flag_url(country):
if pd.isna(country) or country.strip() == "":
return ""
return f"https://flagicons.lipis.dev/flags/4x3/{country[:2].lower()}.svg"
row_from_p1["flag"] = get_flag_url(row_from_p1['country'].item())
row_from_p2["flag"] = get_flag_url(row_from_p2['country'].item())
# concat p1_df and p2_df rows
match_df = pd.concat([row_from_p1, row_from_p2], ignore_index=True)
col1, col2 = st.columns([1, 12])
# MATCHING INFOS
with col1:
# remove arrow from standard st.metric()
st.write(
"""
<style>
[data-testid="stMetricDelta"] svg {
display: none;
}
</style>
""",
unsafe_allow_html=True,
)
st.metric(label="Match", value=f"{actual_ind}", delta=f"~ {str(round(row_from_p1['similarity'].item(), 5) * 100)[:4]} %")
# MATCHING Project Informations as table
with col2:
st.write(" ")
st.dataframe(
match_df[["iati_id", "title_main", "orga_abbreviation", "description_main", "country_name", "flag", "sdg_list", "crs_3_code_list", "crs_5_code_list", "Project Link"]],
use_container_width=True,
height=35 + 35 * len(match_df),
column_config={
"iati_id": st.column_config.TextColumn(
"IATI ID",
help="IATI Project ID",
disabled=True,
width="small"
),
"orga_abbreviation": st.column_config.TextColumn(
"Organization",
help="If description not in English, description in other language provided",
disabled=True,
width="small"
),
"title_main": st.column_config.TextColumn(
"Title",
help="If title not in English, title in other language provided",
disabled=True,
width="large"
),
"description_main": st.column_config.TextColumn(
"Description",
help="If description not in English, description in other language provided",
disabled=True,
width="large"
),
"country_name": st.column_config.TextColumn(
"Country",
help="Country of project",
disabled=True,
width="small"
),
"flag": st.column_config.ImageColumn(
"Flag",
help="country flag",
width="small"
),
"sdg_list": st.column_config.ListColumn(
"SDG Prediction",
help="Prediction of SDG's",
width="small"
),
"crs_3_code_list": st.column_config.ListColumn(
"CRS 3",
help="CRS 3 code given by organization",
width="medium"
),
"crs_5_code_list": st.column_config.ListColumn(
"CRS 5",
help="CRS 5 code given by organization",
width="medium"
),
"Project Link": st.column_config.TextColumn(
"Project Link",
help="Link to the project",
disabled=True,
width="small"
),
},
hide_index=True,
)
st.write("------------------")
|