| 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'],
|
| [0.4, '#FF69B4'],
|
| [0.4, '#4169E1'],
|
| [0.6, '#4169E1'],
|
| [0.6, '#32CD32'],
|
| [0.8, '#32CD32'],
|
| [0.8, '#FFD700'],
|
| [1.0, '#32CD32']
|
| ],
|
| showscale=False,
|
| ))
|
|
|
|
|
| fig.update_traces(
|
| xgap=1,
|
| ygap=1,
|
| )
|
|
|
|
|
| fig.update_layout(
|
|
|
| xaxis=dict(
|
| side='top',
|
| tickangle=45,
|
| tickfont=dict(size=10),
|
| ),
|
| yaxis=dict(
|
| autorange='reversed',
|
| tickfont=dict(size=10),
|
| ),
|
| width=800,
|
|
|
|
|
| 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
|
| ),
|
|
|
| hovermode="x unified",hoverlabel=dict(
|
| bgcolor='rgba(8,8,74,1)',
|
| font_size=10,
|
| ), clickmode='event+select',
|
| )
|
|
|
|
|
| fig.update_xaxes(
|
|
|
| showgrid=True,
|
| gridwidth=1,
|
| gridcolor='lightgrey',
|
| )
|
|
|
| fig.update_yaxes(
|
|
|
| showgrid=True,
|
| gridwidth=1,
|
| gridcolor='lightgrey',
|
| )
|
|
|
|
|
| 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.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_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,
|
|
|
| )
|
| return fig
|
|
|
| async def display_matrixcorrelation():
|
|
|
| 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
|
|
|
| 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 |