""" 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 event_handler_calculate_practical_task_blocks( files, practical_subtasks, pt_scores, threshold_professional_skills, dropdown_professional_skills, ): if practical_subtasks.lower() == "professional skills": df_professional_skills = pd.read_csv(config_data.Links_PROFESSIONAL_SKILLS) df_professional_skills.index.name = "ID" df_professional_skills.index += 1 df_professional_skills.index = df_professional_skills.index.map(str) b5._priority_skill_calculation( df_files=pt_scores.iloc[:, 1:], correlation_coefficients=df_professional_skills, threshold=threshold_professional_skills, out=True, ) # Optional df = b5.df_files_priority_skill_.rename( columns={ "Openness": "OPE", "Conscientiousness": "CON", "Extraversion": "EXT", "Agreeableness": "AGR", "Non-Neuroticism": "NNEU", } ) columns_to_round = df.columns[1:] df[columns_to_round] = df[columns_to_round].apply( lambda x: [round(i, 3) for i in x] ) 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), ) 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), )