| |
| import streamlit as st |
| import joblib |
| import pandas as pd |
| import os |
| from dotenv import load_dotenv |
|
|
| |
| |
| |
| |
| load_dotenv() |
|
|
| |
| ruta_base = os.getenv("PROYECTO_RUTA_BASE") |
|
|
| |
| if not ruta_base: |
| |
| st.error("Error Cr铆tico: La variable 'PROYECTO_RUTA_BASE' no se encontr贸 en el archivo .env.") |
| st.stop() |
|
|
| |
| CARPETA_PROCESADO = os.path.join(ruta_base, "PROCESADO") |
| ARCHIVO_PIPELINE = os.path.join(CARPETA_PROCESADO, "modelo_prioridad_pipeline_FINAL.joblib") |
| ARCHIVO_CSV = os.path.join(CARPETA_PROCESADO, "reporte_mesa_ayuda_COMBINADO.csv") |
|
|
| |
| |
| |
| @st.cache_data(show_spinner=False) |
| def cargar_pipeline(path): |
| return joblib.load(path) |
|
|
| @st.cache_data(show_spinner=False) |
| def cargar_csv(path): |
| return pd.read_csv(path) |
|
|
| pipeline = cargar_pipeline(ARCHIVO_PIPELINE) |
| df_csv = cargar_csv(ARCHIVO_CSV) |
|
|
| |
| |
| |
| if 'Asunto' not in df_csv.columns: |
| df_csv['Asunto'] = "No informado" |
| else: |
| df_csv['Asunto'] = df_csv['Asunto'].fillna("No informado") |
|
|
| |
| columnas_input = ['Categoria', 'Grupo_Asignado', 'Area_Solicitante', 'Asunto'] |
| df_input = df_csv[columnas_input] |
|
|
| |
| |
| |
| df_csv['Prioridad_PREDICHA'] = pipeline.predict(df_input) |
|
|
| |
| df_csv['Area_Solicitante'] = df_csv['Area_Solicitante'].str.upper() |
| df_csv['Grupo_Asignado'] = df_csv['Grupo_Asignado'].str.upper() |
| df_csv['Prioridad_PREDICHA'] = df_csv['Prioridad_PREDICHA'].str.upper() |
|
|
| |
| |
| |
| df_grouped = df_csv.groupby( |
| ['Grupo_Asignado', 'Area_Solicitante', 'Prioridad_PREDICHA'] |
| ).size().reset_index(name='Cantidad_Tickets') |
|
|
| |
| df_pivot = df_grouped.pivot_table( |
| index=['Grupo_Asignado', 'Area_Solicitante'], |
| columns='Prioridad_PREDICHA', |
| values='Cantidad_Tickets', |
| fill_value=0 |
| ).reset_index() |
|
|
| |
| |
| |
| df_pivot = df_pivot.sort_values(by=['Grupo_Asignado', 'Area_Solicitante']).reset_index(drop=True) |
|
|
| |
| |
| |
| def color_max_priority(row): |
| styles = pd.Series("", index=row.index) |
| |
| prioridades = ['ALTA', 'MEDIA', 'BAJA'] |
| exist_cols = [c for c in prioridades if c in row.index] |
| if exist_cols: |
| max_val = row[exist_cols].max() |
| for col in exist_cols: |
| if row[col] == max_val and max_val > 0: |
| styles[col] = 'background-color: green; color: white; font-weight: bold' |
| return styles |
|
|
| |
| |
| |
| st.title("Dashboard de Tickets - Prioridad Predicha") |
| st.write("馃搶 Resumen agrupado por Grupo y 脕rea. La prioridad con mayor cantidad se pinta de verde.") |
|
|
| st.dataframe(df_pivot.style.apply(color_max_priority, axis=1)) |
|
|