Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
@@ -65,6 +65,8 @@ def display_student_activities(username: str, lang_code: str, t: dict):
|
|
65 |
logger.error(f"Error mostrando actividades: {str(e)}")
|
66 |
st.error(t.get('error_loading_activities', 'Error al cargar las actividades'))
|
67 |
|
|
|
|
|
68 |
def display_morphosyntax_activities(username: str, t: dict):
|
69 |
"""Muestra actividades de análisis morfosintáctico"""
|
70 |
try:
|
@@ -90,6 +92,7 @@ def display_morphosyntax_activities(username: str, t: dict):
|
|
90 |
logger.error(f"Error mostrando análisis morfosintáctico: {str(e)}")
|
91 |
st.error(t.get('error_morpho', 'Error al mostrar análisis morfosintáctico'))
|
92 |
|
|
|
93 |
def display_semantic_activities(username: str, t: dict):
|
94 |
"""Muestra actividades de análisis semántico"""
|
95 |
try:
|
@@ -99,36 +102,32 @@ def display_semantic_activities(username: str, t: dict):
|
|
99 |
return
|
100 |
|
101 |
for analysis in analyses:
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
# Mostrar texto analizado
|
107 |
-
st.text(f"{t.get('analyzed_file', 'Archivo analizado')}:")
|
108 |
-
st.write(analysis['text'])
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
124 |
|
125 |
except Exception as e:
|
126 |
logger.error(f"Error mostrando análisis semántico: {str(e)}")
|
127 |
st.error(t.get('error_semantic', 'Error al mostrar análisis semántico'))
|
128 |
|
129 |
###################################################################################################
|
130 |
-
|
131 |
-
|
132 |
def display_discourse_activities(username: str, t: dict):
|
133 |
"""Muestra actividades de análisis del discurso"""
|
134 |
try:
|
@@ -138,62 +137,26 @@ def display_discourse_activities(username: str, t: dict):
|
|
138 |
return
|
139 |
|
140 |
for analysis in analyses:
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
df1 = pd.DataFrame(
|
162 |
-
analysis['key_concepts1'],
|
163 |
-
columns=['Concepto', 'Frecuencia']
|
164 |
-
)
|
165 |
-
st.dataframe(df1)
|
166 |
-
|
167 |
-
with col2:
|
168 |
-
st.markdown(f"**{t.get('concepts_text_2', 'Conceptos Texto 2')}**")
|
169 |
-
df2 = pd.DataFrame(
|
170 |
-
analysis['key_concepts2'],
|
171 |
-
columns=['Concepto', 'Frecuencia']
|
172 |
-
)
|
173 |
-
st.dataframe(df2)
|
174 |
-
|
175 |
-
# Mostrar gráficos
|
176 |
-
if all(key in analysis for key in ['graph1', 'graph2']):
|
177 |
-
st.subheader(t.get('visualizations', 'Visualizaciones'))
|
178 |
-
|
179 |
-
col1, col2 = st.columns(2)
|
180 |
-
with col1:
|
181 |
-
st.markdown(f"**{t.get('graph_text_1', 'Grafo Texto 1')}**")
|
182 |
-
if analysis['graph1']:
|
183 |
-
image_bytes = base64.b64decode(analysis['graph1'])
|
184 |
-
st.image(image_bytes)
|
185 |
-
|
186 |
-
with col2:
|
187 |
-
st.markdown(f"**{t.get('graph_text_2', 'Grafo Texto 2')}**")
|
188 |
-
if analysis['graph2']:
|
189 |
-
image_bytes = base64.b64decode(analysis['graph2'])
|
190 |
-
st.image(image_bytes)
|
191 |
-
|
192 |
-
# Mostrar gráfico combinado si existe
|
193 |
-
if 'combined_graph' in analysis and analysis['combined_graph']:
|
194 |
-
st.subheader(t.get('combined_visualization', 'Visualización Combinada'))
|
195 |
-
image_bytes = base64.b64decode(analysis['combined_graph'])
|
196 |
-
st.image(image_bytes)
|
197 |
|
198 |
except Exception as e:
|
199 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
@@ -215,6 +178,46 @@ def display_discourse_comparison(analysis: dict, t: dict):
|
|
215 |
df2 = pd.DataFrame(analysis['key_concepts2'])
|
216 |
st.dataframe(df2)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
#################################################################################
|
219 |
def display_chat_activities(username: str, t: dict):
|
220 |
"""
|
|
|
65 |
logger.error(f"Error mostrando actividades: {str(e)}")
|
66 |
st.error(t.get('error_loading_activities', 'Error al cargar las actividades'))
|
67 |
|
68 |
+
|
69 |
+
###################################################################################
|
70 |
def display_morphosyntax_activities(username: str, t: dict):
|
71 |
"""Muestra actividades de análisis morfosintáctico"""
|
72 |
try:
|
|
|
92 |
logger.error(f"Error mostrando análisis morfosintáctico: {str(e)}")
|
93 |
st.error(t.get('error_morpho', 'Error al mostrar análisis morfosintáctico'))
|
94 |
|
95 |
+
###################################################################################
|
96 |
def display_semantic_activities(username: str, t: dict):
|
97 |
"""Muestra actividades de análisis semántico"""
|
98 |
try:
|
|
|
102 |
return
|
103 |
|
104 |
for analysis in analyses:
|
105 |
+
try:
|
106 |
+
# Convertir timestamp a datetime para formato
|
107 |
+
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
|
108 |
+
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
|
|
|
109 |
|
110 |
+
with st.expander(
|
111 |
+
f"{t.get('analysis_date', 'Fecha')}: {formatted_date}",
|
112 |
+
expanded=False
|
113 |
+
):
|
114 |
+
# Mostrar solo el grafo de conceptos
|
115 |
+
if 'concept_graph' in analysis and analysis['concept_graph']:
|
116 |
+
st.subheader(t.get('concept_network', 'Red de Conceptos'))
|
117 |
+
image_bytes = base64.b64decode(analysis['concept_graph'])
|
118 |
+
st.image(image_bytes)
|
119 |
+
else:
|
120 |
+
st.info(t.get('no_graph', 'No hay visualización disponible'))
|
121 |
+
|
122 |
+
except Exception as e:
|
123 |
+
logger.error(f"Error mostrando análisis individual: {str(e)}")
|
124 |
+
continue
|
125 |
|
126 |
except Exception as e:
|
127 |
logger.error(f"Error mostrando análisis semántico: {str(e)}")
|
128 |
st.error(t.get('error_semantic', 'Error al mostrar análisis semántico'))
|
129 |
|
130 |
###################################################################################################
|
|
|
|
|
131 |
def display_discourse_activities(username: str, t: dict):
|
132 |
"""Muestra actividades de análisis del discurso"""
|
133 |
try:
|
|
|
137 |
return
|
138 |
|
139 |
for analysis in analyses:
|
140 |
+
try:
|
141 |
+
# Convertir timestamp a datetime para formato
|
142 |
+
timestamp = datetime.fromisoformat(analysis['timestamp'].replace('Z', '+00:00'))
|
143 |
+
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
144 |
+
|
145 |
+
with st.expander(
|
146 |
+
f"{t.get('analysis_date', 'Fecha')}: {formatted_date}",
|
147 |
+
expanded=False
|
148 |
+
):
|
149 |
+
# Mostrar solo el gráfico combinado
|
150 |
+
if 'combined_graph' in analysis and analysis['combined_graph']:
|
151 |
+
st.subheader(t.get('comparative_analysis', 'Análisis Comparativo'))
|
152 |
+
image_bytes = base64.b64decode(analysis['combined_graph'])
|
153 |
+
st.image(image_bytes)
|
154 |
+
else:
|
155 |
+
st.info(t.get('no_visualization', 'No hay visualización comparativa disponible'))
|
156 |
+
|
157 |
+
except Exception as e:
|
158 |
+
logger.error(f"Error mostrando análisis individual: {str(e)}")
|
159 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
except Exception as e:
|
162 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
|
|
178 |
df2 = pd.DataFrame(analysis['key_concepts2'])
|
179 |
st.dataframe(df2)
|
180 |
|
181 |
+
|
182 |
+
|
183 |
+
###################################################################################
|
184 |
+
# También podemos optimizar las consultas a la base de datos para que solo traigan los campos necesarios:
|
185 |
+
|
186 |
+
def get_student_semantic_analysis(username, limit=10):
|
187 |
+
"""
|
188 |
+
Recupera solo los grafos de los análisis semánticos
|
189 |
+
"""
|
190 |
+
query = {"username": username, "analysis_type": "semantic"}
|
191 |
+
projection = {
|
192 |
+
"timestamp": 1,
|
193 |
+
"concept_graph": 1
|
194 |
+
}
|
195 |
+
return find_documents(
|
196 |
+
COLLECTION_NAME,
|
197 |
+
query=query,
|
198 |
+
projection=projection,
|
199 |
+
sort=[("timestamp", -1)],
|
200 |
+
limit=limit
|
201 |
+
)
|
202 |
+
|
203 |
+
def get_student_discourse_analysis(username, limit=10):
|
204 |
+
"""
|
205 |
+
Recupera solo los grafos combinados de los análisis de discurso
|
206 |
+
"""
|
207 |
+
query = {"username": username, "analysis_type": "discourse"}
|
208 |
+
projection = {
|
209 |
+
"timestamp": 1,
|
210 |
+
"combined_graph": 1
|
211 |
+
}
|
212 |
+
return find_documents(
|
213 |
+
COLLECTION_NAME,
|
214 |
+
query=query,
|
215 |
+
projection=projection,
|
216 |
+
sort=[("timestamp", -1)],
|
217 |
+
limit=limit
|
218 |
+
)
|
219 |
+
|
220 |
+
|
221 |
#################################################################################
|
222 |
def display_chat_activities(username: str, t: dict):
|
223 |
"""
|