File size: 2,668 Bytes
d0f716d
 
 
 
 
 
 
0ba2e4a
d0f716d
0ba2e4a
d0f716d
 
 
0ba2e4a
d0f716d
 
0ba2e4a
 
 
 
 
d0f716d
0ba2e4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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

# Importing necessary components for the Gradio app
from app.config import config_data
from app.components import html_message, dataframe, files_create_ui


def event_handler_calculate_practical_task_blocks(
    practical_tasks, practical_subtasks, pt_scores
):
    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=0.5,
            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]
        )

        df.to_csv(config_data.Filenames_PT_SKILLS_SCORES)

        df.reset_index(inplace=True)

        return (
            dataframe(
                headers=df.columns.tolist(),
                values=df.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",
            ),
            html_message(config_data.InformationMessages_NOTI_IN_DEV, False, False),
        )
    else:
        gr.Info(config_data.InformationMessages_NOTI_IN_DEV)

        return (
            dataframe(visible=False),
            files_create_ui(
                None,
                "single",
                [".csv"],
                config_data.OtherMessages_EXPORT_PS,
                True,
                False,
                False,
                "csv-container",
            ),
            html_message(config_data.InformationMessages_NOTI_IN_DEV, False, True),
        )