File size: 8,505 Bytes
a284a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import plotly.express as px
import pandas as pd
import glob
import json
import plotly.graph_objects as go
import numpy as np
import textwrap
import re
import os

def readExcel(data):
    return pd.read_excel(data)

def matrixcorrelation(matrix,df,list_labo):
    fig = go.Figure(data=go.Heatmap(
    z=matrix.values,
    x=matrix.columns,
    y=matrix.index,
    colorscale=[
        [0, 'rgba(6,6,33,1)'],
        [0.2, 'rgba(6,6,33,1)'],
        [0.2, '#FF69B4'],  # Rose pour technique
        [0.4, '#FF69B4'],
        [0.4, '#4169E1'],  # Bleu pour management
        [0.6, '#4169E1'],
        [0.6, '#32CD32'],  # Vert pour environnement
        [0.8, '#32CD32'],
        [0.8, '#FFD700'],  # Jaune pour économie
        [1.0, '#32CD32']
        ],
        showscale=False,
    ))

    # Ajout des bordures aux cellules
    fig.update_traces(
        xgap=1,
        ygap=1,
    )
    
    # Mise en forme
    fig.update_layout(
        #title='Matrice des emplois types<br>par famille de compétences<br>professionnelles',
        xaxis=dict(
            side='top',
            tickangle=45,
            tickfont=dict(size=10),
        ),
        yaxis=dict(
            autorange='reversed',
            tickfont=dict(size=10),
        ),
        width=800,
        #height=300,
        #height=len(list_labo) * 20,
        height=1200,
        template='plotly_dark',
        paper_bgcolor = 'rgba(6,6,33,1)',
        plot_bgcolor='rgba(6,6,33,1)',
        margin=dict(
            t=10,
            l=50,
            r=10,
            b=50
        ),
        #annotations=annotations,
        hovermode="x unified",hoverlabel=dict(
            bgcolor='rgba(8,8,74,1)',
            font_size=10,
        ), clickmode='event+select',
    )

    # Personnalisation du style des axes
    fig.update_xaxes(
        #showspikes=True,
        showgrid=True,
        gridwidth=1,
        gridcolor='lightgrey',
    )

    fig.update_yaxes(
        #showspikes=True,
        showgrid=True,
        gridwidth=1,
        gridcolor='lightgrey',
    )

    # Ajout d'un hover template personnalisé
    hover_text = []
    wrapper = textwrap.TextWrapper(width=10)
    df_info = df[["Laboratoires", "Thématiques Ville Durable", "Ville","Nom du Laboratoire","Thématiques Transversales","Thématiques Spécifiques", "Productions Pédagogiques", "Équipements"]].copy()
    df_info['Thématiques Ville Durable'] = df_info['Thématiques Ville Durable'].str.split('; ')
    df_info = df_info.explode('Thématiques Ville Durable')
    
    #df_info = df_info.drop_duplicates(subset=['Thématiques ODD11'])
    df_info.set_index("Thématiques Ville Durable", inplace=True)

    for idx in matrix.index:
        row = []
        for col in matrix.columns:
            if matrix.loc[idx,col] == 1:
                #df_psycho = df_score[(df_score['Thématiques Pedago'].str.contains(row['Thématiques Pedago'])) & (df_score['labStructName_s'] == row['labStructName_s'])]

                df_extract = df_info.loc[col]
                label_y = idx
                df_test = df_extract[df_extract["Laboratoires"] == idx].copy()
                if len(df_test) > 0:
                    nom_labo = "<br>".join(df_test["Nom du Laboratoire"].values.tolist())
                    transversales = "<br>".join(df_test["Thématiques Transversales"].values.tolist())
                    specifiques = "<br>".join(df_test["Thématiques Spécifiques"].values.tolist())
                    pedagogiques = "<br>".join(df_test["Productions Pédagogiques"].values.tolist())
                    equipements = "<br>".join(df_test["Équipements"].values.tolist())
                    row.append(
                    f'<b>🔬 Laboratoire: {label_y}</b> : {nom_labo}<br>' +
                    f'<b>🏙️ Thématiques Ville Durable: {col.capitalize()}</b><br><br>' +
                    f'📣 Thématiques Transversales :<br>{transversales}<br><br>' +
                    f'📣 Thématiques Spécifiques :<br>{specifiques}<br><br>' +
                    f'🧑‍ Productions Pédagogiques:<br>{pedagogiques}<br><br>' +
                    f'🎓 Équipements: {equipements}'
                    )
            else:
                row.append('')

        hover_text.append(row)

    fig.update_traces(
        hovertemplate="%{customdata}<extra></extra>",
        customdata=hover_text,
        #y=[y[0:-10].replace('(','') if y.find('(essential)')!=-1 or y.find('(optional)')!=-1 else y for y in color_values.index]
    )
    return fig

async def display_matrixcorrelation():
    ######## Matrice de corrélation ########
    df = readExcel("public/Fiches-laboratoires-Thematiques-AVID.xlsx")
    df_labo = df[["Laboratoires"]].copy()
    df_labo = df_labo.drop_duplicates(subset=["Laboratoires"])
    list_labo = df_labo["Laboratoires"].values.tolist()
    
    df_thematique = df[['Thématiques Ville Durable']].copy()
    df_thematique['Thématiques Ville Durable'] = df_thematique['Thématiques Ville Durable'].str.split('; ')
    df_thematique = df_thematique.explode('Thématiques Ville Durable')
    df_thematique = df_thematique.drop_duplicates(subset=['Thématiques Ville Durable'])
    list_thematique = df_thematique['Thématiques Ville Durable'].values.tolist()
    
    matrix = pd.DataFrame(0, index=list_labo, columns=list_thematique)
    for labo in list_labo:
        for thematique in list_thematique:
            df_test = df[df['Thématiques Ville Durable'] == thematique]
            if labo in df_test.values :
                matrix.loc[labo, thematique] = 1 # Replace with actual condition logic

    return matrixcorrelation(matrix,df,list_labo)

async def display_barplotcorrelation():
    df = readExcel("public/Fiches-laboratoires-Thematiques-AVID.xlsx")
    df['Thématiques Ville Durable'] = df['Thématiques Ville Durable'].str.split('; ')
    df = df.explode('Thématiques Ville Durable')
    df = df.groupby(['Thématiques Ville Durable','Laboratoires']).size().reset_index(name='count')
    fig = px.bar(df, x='count', y='Thématiques Ville Durable', color='Laboratoires', height=1200, width=1200, orientation='h',color_discrete_sequence=px.colors.qualitative.Safe, text_auto=True, template='plotly_dark').update_layout(font=dict(size=10, color='white'),autosize=True, paper_bgcolor='rgba(6,6,33,1)', plot_bgcolor='rgba(6,6,33,1)').update_traces(showlegend=True)
    return fig
    
async def display_barplotpublication():
    df = readExcel("public/all-LABOUGE-publications_2020-2025_Thematiques_AVID.xlsx")
    df.dropna(subset=['Thématiques Ville Durable'], inplace=True)
    df['Thématiques Ville Durable'] = df['Thématiques Ville Durable'].str.split('; ')
    df = df.explode('Thématiques Ville Durable')
    df['Thématiques Ville Durable'] = df['Thématiques Ville Durable'].apply(lambda x: str(x).split('(')).apply(lambda x: x[0])
    df = df.groupby(['Thématiques Ville Durable','Laboratoire Université Gustave Eiffel']).size().reset_index(name='count')
    fig = px.bar(df, x='count', y='Thématiques Ville Durable', color='Laboratoire Université Gustave Eiffel', height=1200, width=1200, orientation='h',color_discrete_sequence=px.colors.qualitative.Safe, text_auto=True, template='plotly_dark').update_layout(font=dict(size=10, color='white'),autosize=True, paper_bgcolor='rgba(6,6,33,1)', plot_bgcolor='rgba(6,6,33,1)').update_traces(showlegend=True)
    return fig

async def display_barplotformation():
    df = readExcel("public/Formations-correlation-thematiquesVD_AVID.xlsx")
    df.dropna(subset=['Thématiques Ville Durable'], inplace=True)
    df['Thématiques Ville Durable'] = df['Thématiques Ville Durable'].str.split('; ')
    df = df.explode('Thématiques Ville Durable')
    df['Thématiques Ville Durable'] = df['Thématiques Ville Durable'].apply(lambda x: str(x).split('(')).apply(lambda x: x[0])
    df = df.groupby(['Thématiques Ville Durable','Niveau']).size().reset_index(name='count')
    fig = px.bar(df, x='count', y='Thématiques Ville Durable', color='Niveau', height=1200, width=1200, orientation='h',color_discrete_sequence=px.colors.qualitative.Safe, text_auto=True, template='plotly_dark').update_layout(font=dict(size=10, color='white'),autosize=True, paper_bgcolor='rgba(6,6,33,1)', plot_bgcolor='rgba(6,6,33,1)').update_traces(showlegend=False)
    return fig