Spaces:
Running
Running
File size: 6,491 Bytes
d0f716d b0f25b3 d0f716d b0f25b3 aa2aec1 d0f716d aa2aec1 d0f716d 20b6a53 b0f25b3 aa2aec1 20b6a53 b0f25b3 20b6a53 b0f25b3 aa2aec1 b0f25b3 20b6a53 b0f25b3 aa2aec1 b0f25b3 aa2aec1 b0f25b3 aa2aec1 b0f25b3 aa2aec1 b0f25b3 20b6a53 b0f25b3 aa2aec1 b0f25b3 aa2aec1 b0f25b3 aa2aec1 b0f25b3 |
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
"""
File: calculate_practical_tasks.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Event handler for Gradio app to calculate practical tasks.
License: MIT License
"""
from app.oceanai_init import b5
import gradio as gr
import pandas as pd
from pathlib import Path
# Importing necessary components for the Gradio app
from app.config import config_data
from app.components import html_message, dataframe, files_create_ui, video_create_ui
def read_csv_file(file_path, drop_id=False):
df = pd.read_csv(file_path)
if drop_id:
df = pd.DataFrame(df.drop(["ID"], axis=1))
df.index.name = "ID"
df.index += 1
df.index = df.index.map(str)
return df
def apply_rounding_and_rename_columns(df):
df_rounded = df.rename(
columns={
"Openness": "OPE",
"Conscientiousness": "CON",
"Extraversion": "EXT",
"Agreeableness": "AGR",
"Non-Neuroticism": "NNEU",
}
)
columns_to_round = df_rounded.columns[1:]
df_rounded[columns_to_round] = df_rounded[columns_to_round].apply(
lambda x: [round(i, 3) for i in x]
)
return df_rounded
def colleague_type(subtask):
return "minor" if "junior" in subtask.lower() else "major"
def event_handler_calculate_practical_task_blocks(
files,
practical_subtasks,
pt_scores,
threshold_professional_skills,
dropdown_professional_skills,
target_score_ope,
target_score_con,
target_score_ext,
target_score_agr,
target_score_nneu,
equal_coefficient,
):
if practical_subtasks.lower() == "professional skills":
df_professional_skills = read_csv_file(config_data.Links_PROFESSIONAL_SKILLS)
b5._priority_skill_calculation(
df_files=pt_scores.iloc[:, 1:],
correlation_coefficients=df_professional_skills,
threshold=threshold_professional_skills,
out=True,
)
# Optional
df = apply_rounding_and_rename_columns(b5.df_files_priority_skill_)
professional_skills_list = (
config_data.Settings_DROPDOWN_PROFESSIONAL_SKILLS.copy()
)
professional_skills_list.remove(dropdown_professional_skills)
professional_skills_list = [
"OPE",
"CON",
"EXT",
"AGR",
"NNEU",
] + professional_skills_list
df_hidden = df.drop(columns=professional_skills_list)
df_hidden.to_csv(config_data.Filenames_PT_SKILLS_SCORES)
df_hidden.reset_index(inplace=True)
df_hidden = df_hidden.sort_values(
by=[dropdown_professional_skills], ascending=False
)
person_id = int(df_hidden.iloc[0]["Person ID"]) - 1
return (
gr.Row(visible=True),
gr.Column(visible=True),
dataframe(
headers=df_hidden.columns.tolist(),
values=df_hidden.values.tolist(),
visible=True,
),
files_create_ui(
config_data.Filenames_PT_SKILLS_SCORES,
"single",
[".csv"],
config_data.OtherMessages_EXPORT_PS,
True,
False,
True,
"csv-container",
),
video_create_ui(
value=files[person_id],
file_name=Path(files[person_id]).name,
label="Best Person ID - " + str(person_id + 1),
visible=True,
),
html_message(config_data.InformationMessages_NOTI_IN_DEV, False, False),
)
elif (
practical_subtasks.lower() == "finding a suitable junior colleague"
or practical_subtasks.lower() == "finding a suitable senior colleague"
):
df_correlation_coefficients = read_csv_file(config_data.Links_FINDING_COLLEAGUE)
b5._colleague_ranking(
df_files=pt_scores.iloc[:, 1:],
correlation_coefficients=df_correlation_coefficients,
target_scores=[
target_score_ope,
target_score_con,
target_score_ext,
target_score_agr,
target_score_nneu,
],
colleague=colleague_type(practical_subtasks),
equal_coefficients=equal_coefficient,
out=False,
)
# Optional
df = df = apply_rounding_and_rename_columns(b5.df_files_colleague_)
professional_skills_list = [
"OPE",
"CON",
"EXT",
"AGR",
"NNEU",
]
df_hidden = df.drop(columns=professional_skills_list)
df_hidden.to_csv(
colleague_type(practical_subtasks) + config_data.Filenames_COLLEAGUE_RANKING
)
df_hidden.reset_index(inplace=True)
person_id = int(df_hidden.iloc[0]["Person ID"]) - 1
return (
gr.Row(visible=True),
gr.Column(visible=True),
dataframe(
headers=df_hidden.columns.tolist(),
values=df_hidden.values.tolist(),
visible=True,
),
files_create_ui(
colleague_type(practical_subtasks)
+ config_data.Filenames_COLLEAGUE_RANKING,
"single",
[".csv"],
config_data.OtherMessages_EXPORT_WT,
True,
False,
True,
"csv-container",
),
video_create_ui(
value=files[person_id],
file_name=Path(files[person_id]).name,
label="Best Person ID - " + str(person_id + 1),
visible=True,
),
html_message(config_data.InformationMessages_NOTI_IN_DEV, False, False),
)
else:
gr.Info(config_data.InformationMessages_NOTI_IN_DEV)
return (
gr.Row(visible=False),
gr.Column(visible=False),
dataframe(visible=False),
files_create_ui(
None,
"single",
[".csv"],
config_data.OtherMessages_EXPORT_PS,
True,
False,
False,
"csv-container",
),
video_create_ui(visible=False),
html_message(config_data.InformationMessages_NOTI_IN_DEV, False, True),
)
|