File size: 8,445 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import streamlit as st
import pandas as pd


"""

Result table of the Single Project Matching

"""


def show_single_table(selected_project_index, projects_df, result_df):
    
    """

    TODO: Add this to preprocessing



    """
    result_df['crs_3_code_list'] = result_df['crs_3_name'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1])
    )
    result_df['crs_5_code_list'] = result_df['crs_5_name'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1])
    )
    result_df['sdg_list'] = result_df['sgd_pred_code'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";"))
    )

    # Convert orga_abbreviation to uppercase for the selected project
    result_df['orga_abbreviation'] = result_df['orga_abbreviation'].str.upper()

    # Set country_flag to None if country_name is missing
    result_df['country_flag'] = result_df.apply(
        lambda row: None if pd.isna(row['country_name']) else row['country_flag'],
        axis=1
    )
    sel_p_row = projects_df.iloc[[selected_project_index]]

    sel_p_row['crs_3_code_list'] = sel_p_row['crs_3_name'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1])
    )
    sel_p_row['crs_5_code_list'] = sel_p_row['crs_5_name'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1])
    )
    sel_p_row['sdg_list'] = sel_p_row['sgd_pred_code'].apply(
    lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";"))
    )

    # Convert orga_abbreviation to uppercase for the selected project
    sel_p_row['orga_abbreviation'] = sel_p_row['orga_abbreviation'].str.upper()

    # Displaye selected project and infos
    st.subheader("Reference Project")
    st.dataframe(
                    sel_p_row[["iati_id", "title_main", "orga_abbreviation", "description_main", "country_name", "country_flag", "sdg_list", "crs_3_code_list", "crs_5_code_list", "Project Link"]],
                    use_container_width = True,
                    height = 35 + 35 * len(sel_p_row),
                    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"
                        ),
                        "country_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,
                )


    # Display the similar projects of the selected project
    if len(result_df) == 0:
        st.write("No results found!")
    else:
        result_df = result_df.reset_index(drop=True)
        result_df['similarity'] = (result_df['similarity'] * 100).round(4)

        st.write("----------------------")
        st.subheader("Similar Projects")
        st.dataframe(
            result_df[["similarity", "iati_id", "title_main", "orga_abbreviation", "description_main", "country_name", "country_flag", "sdg_list", "crs_3_code_list", "crs_5_code_list", "Project Link"]],
            use_container_width = True,
            height = 35 + 35 * len(result_df),
            column_config={
                "similarity": st.column_config.ProgressColumn(
                    "Similarity",
                    help="Similarity",
                    format=" %f %%",
                    min_value=0,
                    max_value=100,
                ),
                "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"
                ),
                "country_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"
                ),
            },
            hide_index=True,
        )