Spaces:
Running
Running
| """ | |
| 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 | |
| from pathlib import Path | |
| # Importing necessary components for the Gradio app | |
| from app.config import config_data | |
| from app.utils import ( | |
| read_csv_file, | |
| apply_rounding_and_rename_columns, | |
| preprocess_scores_df, | |
| ) | |
| from app.components import html_message, dataframe, files_create_ui, video_create_ui | |
| def colleague_type(subtask): | |
| return "minor" if "junior" in subtask.lower() else "major" | |
| def consumer_preferences(subtask): | |
| return ( | |
| config_data.Filenames_CAR_CHARACTERISTICS | |
| if "mobile device" in subtask.lower() | |
| else config_data.Filenames_MDA_CATEGORIES | |
| ) | |
| 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, | |
| number_priority, | |
| number_importance_traits, | |
| threshold_consumer_preferences, | |
| number_openness, | |
| number_conscientiousness, | |
| number_extraversion, | |
| number_agreeableness, | |
| number_non_neuroticism, | |
| ): | |
| if practical_subtasks.lower() == "professional groups": | |
| sum_weights = sum( | |
| [ | |
| number_openness, | |
| number_conscientiousness, | |
| number_extraversion, | |
| number_agreeableness, | |
| number_non_neuroticism, | |
| ] | |
| ) | |
| if sum_weights != 100: | |
| gr.Warning(config_data.InformationMessages_SUM_WEIGHTS.format(sum_weights)) | |
| 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_SUM_WEIGHTS.format(sum_weights), | |
| False, | |
| True, | |
| ), | |
| ) | |
| else: | |
| b5._candidate_ranking( | |
| df_files=pt_scores.iloc[:, 1:], | |
| weigths_openness=number_openness, | |
| weigths_conscientiousness=number_conscientiousness, | |
| weigths_extraversion=number_extraversion, | |
| weigths_agreeableness=number_agreeableness, | |
| weigths_non_neuroticism=number_non_neuroticism, | |
| out=False, | |
| ) | |
| df = apply_rounding_and_rename_columns(b5.df_files_ranking_) | |
| df_hidden = df.drop(columns=config_data.Settings_SHORT_PROFESSIONAL_SKILLS) | |
| df_hidden.to_csv(config_data.Filenames_POTENTIAL_CANDIDATES) | |
| 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( | |
| config_data.Filenames_POTENTIAL_CANDIDATES, | |
| "single", | |
| [".csv"], | |
| config_data.OtherMessages_EXPORT_PG, | |
| 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() == "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=False, | |
| ) | |
| 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) | |
| df_hidden = df.drop( | |
| columns=config_data.Settings_SHORT_PROFESSIONAL_SKILLS | |
| + 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, ["ID"] | |
| ) | |
| 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, | |
| ) | |
| df = apply_rounding_and_rename_columns(b5.df_files_colleague_) | |
| df_hidden = df.drop(columns=config_data.Settings_SHORT_PROFESSIONAL_SKILLS) | |
| 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), | |
| ) | |
| elif ( | |
| practical_subtasks.lower() == "car characteristics" | |
| or practical_subtasks.lower() == "mobile device application categories" | |
| ): | |
| if practical_subtasks.lower() == "car characteristics": | |
| df_correlation_coefficients = read_csv_file( | |
| config_data.Links_CAR_CHARACTERISTICS, | |
| ["Style and performance", "Safety and practicality"], | |
| ) | |
| if practical_subtasks.lower() == "mobile device application categories": | |
| df_correlation_coefficients = read_csv_file( | |
| config_data.Links_MDA_CATEGORIES | |
| ) | |
| pt_scores_copy = pt_scores.iloc[:, 1:].copy() | |
| preprocess_scores_df(pt_scores_copy, "Person ID") | |
| b5._priority_calculation( | |
| df_files=pt_scores_copy, | |
| correlation_coefficients=df_correlation_coefficients, | |
| col_name_ocean="Trait", | |
| threshold=threshold_consumer_preferences, | |
| number_priority=number_priority, | |
| number_importance_traits=number_importance_traits, | |
| out=False, | |
| ) | |
| df_files_priority = b5.df_files_priority_.copy() | |
| df_files_priority.reset_index(inplace=True) | |
| df = apply_rounding_and_rename_columns(df_files_priority.iloc[:, 1:]) | |
| preprocess_scores_df(df, "Person ID") | |
| df_hidden = df.drop(columns=config_data.Settings_SHORT_PROFESSIONAL_SKILLS) | |
| df_hidden.to_csv(consumer_preferences(practical_subtasks)) | |
| 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( | |
| consumer_preferences(practical_subtasks), | |
| "single", | |
| [".csv"], | |
| config_data.OtherMessages_EXPORT_CP, | |
| 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), | |
| ) | |