AIdeaText commited on
Commit
e76598d
verified
1 Parent(s): f6e1b58

Update modules/studentact/student_activities_v2.py

Browse files
modules/studentact/student_activities_v2.py CHANGED
@@ -287,23 +287,20 @@ def display_current_situation_activities(username: str, t: dict):
287
  return
288
 
289
  # Crear un diccionario para indexar an谩lisis por timestamp
290
- # Esto permite emparejar diagn贸sticos y recomendaciones del mismo momento
291
  logger.info("Creando 铆ndice temporal de an谩lisis")
292
  analyses_by_timestamp = {}
293
 
294
  # Indexar an谩lisis de situaci贸n actual
295
  for analysis in situation_analyses:
296
  if 'timestamp' in analysis:
297
- # Normalizar el formato de timestamp para comparaci贸n
298
- timestamp_key = analysis['timestamp'].split('.')[0] # Remover milisegundos
299
  if timestamp_key not in analyses_by_timestamp:
300
  analyses_by_timestamp[timestamp_key] = {'situation': analysis}
301
 
302
  # Indexar recomendaciones de Claude
303
  for recommendation in claude_recommendations:
304
  if 'timestamp' in recommendation:
305
- # Normalizar el formato de timestamp para comparaci贸n
306
- timestamp_key = recommendation['timestamp'].split('.')[0] # Remover milisegundos
307
  if timestamp_key in analyses_by_timestamp:
308
  analyses_by_timestamp[timestamp_key]['recommendation'] = recommendation
309
  else:
@@ -334,13 +331,12 @@ def display_current_situation_activities(username: str, t: dict):
334
  if not situation_data and not recommendation_data:
335
  continue
336
 
337
- # Determinar qu茅 texto mostrar (priorizar el de la situaci贸n)
338
  text_to_show = situation_data.get('text', recommendation_data.get('text', ''))
339
  text_type = situation_data.get('text_type', recommendation_data.get('text_type', ''))
340
 
341
  # Formatear fecha para mostrar
342
  try:
343
- # Usar timestamp de situation_data si est谩 disponible, sino usar el de recommendation_data
344
  timestamp_str = situation_data.get('timestamp', recommendation_data.get('timestamp', timestamp_key))
345
  timestamp = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
346
  formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
@@ -358,30 +354,24 @@ def display_current_situation_activities(username: str, t: dict):
358
  }.get(text_type, text_type)
359
  title += f" - {text_type_display}"
360
 
361
- # Generar clave 煤nica para este expander
362
- expander_key = generate_unique_key("situation", f"expander_{i}", username)
363
-
364
  # Mostrar el an谩lisis en un expander
365
- with st.expander(title, expanded=False, key=expander_key):
366
  # Mostrar texto analizado
367
  st.subheader(t.get('analyzed_text', 'Texto analizado'))
368
- # Usar clave 煤nica para el text_area
369
- text_area_key = generate_unique_key("situation", f"text_area_{i}", username)
370
  st.text_area(
371
  label="Texto analizado",
372
  value=text_to_show,
373
  height=100,
374
  disabled=True,
375
- key=text_area_key,
376
  label_visibility="hidden"
377
  )
378
 
379
  # Crear tabs para separar diagn贸stico y recomendaciones
380
- tab_key = generate_unique_key("situation", f"tabs_{i}", username)
381
  diagnosis_tab, recommendations_tab = st.tabs([
382
  t.get('diagnosis_tab', 'Diagn贸stico'),
383
  t.get('recommendations_tab', 'Recomendaciones')
384
- ], key=tab_key)
385
 
386
  # Tab de diagn贸stico
387
  with diagnosis_tab:
@@ -396,7 +386,7 @@ def display_current_situation_activities(username: str, t: dict):
396
  st.subheader(t.get('key_metrics', 'M茅tricas clave'))
397
 
398
  # Mostrar cada m茅trica principal
399
- for metric_name, metric_data in metrics.items():
400
  if isinstance(metric_data, dict) and 'normalized_score' in metric_data:
401
  score = metric_data['normalized_score']
402
 
@@ -412,45 +402,40 @@ def display_current_situation_activities(username: str, t: dict):
412
  color = "#ccffcc" # light green
413
 
414
  # Mostrar la m茅trica con estilo
415
- metric_key = generate_unique_key("situation", f"metric_{i}_{metric_name}", username)
416
  st.markdown(f"""
417
  <div style="background-color:{color}; padding:10px; border-radius:5px; margin-bottom:10px;">
418
  <b>{emoji} {metric_name.capitalize()}:</b> {score:.2f}
419
  </div>
420
- """, unsafe_allow_html=True, key=metric_key)
421
 
422
  # Mostrar detalles adicionales si est谩n disponibles
423
  with col2:
424
  st.subheader(t.get('details', 'Detalles'))
425
 
426
- # Recursivamente mostrar detalles de las m茅tricas como JSON o texto plano
427
- for metric_name, metric_data in metrics.items():
428
  if isinstance(metric_data, dict) and 'details' in metric_data and metric_data['details']:
429
- detail_key = generate_unique_key("situation", f"detail_{i}_{metric_name}", username)
430
- with st.container():
431
- st.markdown(f"**{metric_name.capitalize()}**")
432
- st.json(metric_data['details'], key=detail_key)
433
  else:
434
  st.info(t.get('no_diagnosis', 'No hay datos de diagn贸stico disponibles'))
435
 
436
  # Tab de recomendaciones
437
  with recommendations_tab:
438
  if recommendation_data and 'recommendations' in recommendation_data:
439
- recom_key = generate_unique_key("situation", f"recom_{i}", username)
440
  st.markdown(f"""
441
  <div style="padding: 20px; border-radius: 10px;
442
  background-color: #f8f9fa; margin-bottom: 20px;">
443
  {recommendation_data['recommendations']}
444
  </div>
445
- """, unsafe_allow_html=True, key=recom_key)
446
  elif recommendation_data and 'feedback' in recommendation_data:
447
- feedback_key = generate_unique_key("situation", f"feedback_{i}", username)
448
  st.markdown(f"""
449
  <div style="padding: 20px; border-radius: 10px;
450
  background-color: #f8f9fa; margin-bottom: 20px;">
451
  {recommendation_data['feedback']}
452
  </div>
453
- """, unsafe_allow_html=True, key=feedback_key)
454
  else:
455
  st.info(t.get('no_recommendations', 'No hay recomendaciones disponibles'))
456
 
@@ -462,6 +447,7 @@ def display_current_situation_activities(username: str, t: dict):
462
  logger.error(f"Error mostrando actividades de situaci贸n actual: {str(e)}")
463
  st.error(t.get('error_current_situation', 'Error al mostrar an谩lisis de situaci贸n actual'))
464
 
 
465
  #################################################################################
466
  def display_discourse_comparison(analysis: dict, t: dict):
467
  """Muestra la comparaci贸n de an谩lisis del discurso"""
 
287
  return
288
 
289
  # Crear un diccionario para indexar an谩lisis por timestamp
 
290
  logger.info("Creando 铆ndice temporal de an谩lisis")
291
  analyses_by_timestamp = {}
292
 
293
  # Indexar an谩lisis de situaci贸n actual
294
  for analysis in situation_analyses:
295
  if 'timestamp' in analysis:
296
+ timestamp_key = analysis['timestamp'].split('.')[0]
 
297
  if timestamp_key not in analyses_by_timestamp:
298
  analyses_by_timestamp[timestamp_key] = {'situation': analysis}
299
 
300
  # Indexar recomendaciones de Claude
301
  for recommendation in claude_recommendations:
302
  if 'timestamp' in recommendation:
303
+ timestamp_key = recommendation['timestamp'].split('.')[0]
 
304
  if timestamp_key in analyses_by_timestamp:
305
  analyses_by_timestamp[timestamp_key]['recommendation'] = recommendation
306
  else:
 
331
  if not situation_data and not recommendation_data:
332
  continue
333
 
334
+ # Determinar qu茅 texto mostrar
335
  text_to_show = situation_data.get('text', recommendation_data.get('text', ''))
336
  text_type = situation_data.get('text_type', recommendation_data.get('text_type', ''))
337
 
338
  # Formatear fecha para mostrar
339
  try:
 
340
  timestamp_str = situation_data.get('timestamp', recommendation_data.get('timestamp', timestamp_key))
341
  timestamp = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
342
  formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
 
354
  }.get(text_type, text_type)
355
  title += f" - {text_type_display}"
356
 
 
 
 
357
  # Mostrar el an谩lisis en un expander
358
+ with st.expander(title, expanded=False, key=f"situation_expander_{i}"):
359
  # Mostrar texto analizado
360
  st.subheader(t.get('analyzed_text', 'Texto analizado'))
 
 
361
  st.text_area(
362
  label="Texto analizado",
363
  value=text_to_show,
364
  height=100,
365
  disabled=True,
366
+ key=f"situation_text_{i}",
367
  label_visibility="hidden"
368
  )
369
 
370
  # Crear tabs para separar diagn贸stico y recomendaciones
 
371
  diagnosis_tab, recommendations_tab = st.tabs([
372
  t.get('diagnosis_tab', 'Diagn贸stico'),
373
  t.get('recommendations_tab', 'Recomendaciones')
374
+ ])
375
 
376
  # Tab de diagn贸stico
377
  with diagnosis_tab:
 
386
  st.subheader(t.get('key_metrics', 'M茅tricas clave'))
387
 
388
  # Mostrar cada m茅trica principal
389
+ for j, (metric_name, metric_data) in enumerate(metrics.items()):
390
  if isinstance(metric_data, dict) and 'normalized_score' in metric_data:
391
  score = metric_data['normalized_score']
392
 
 
402
  color = "#ccffcc" # light green
403
 
404
  # Mostrar la m茅trica con estilo
 
405
  st.markdown(f"""
406
  <div style="background-color:{color}; padding:10px; border-radius:5px; margin-bottom:10px;">
407
  <b>{emoji} {metric_name.capitalize()}:</b> {score:.2f}
408
  </div>
409
+ """, unsafe_allow_html=True)
410
 
411
  # Mostrar detalles adicionales si est谩n disponibles
412
  with col2:
413
  st.subheader(t.get('details', 'Detalles'))
414
 
415
+ # Mostrar detalles como texto simple
416
+ for j, (metric_name, metric_data) in enumerate(metrics.items()):
417
  if isinstance(metric_data, dict) and 'details' in metric_data and metric_data['details']:
418
+ st.markdown(f"**{metric_name.capitalize()}**")
419
+ st.json(metric_data['details'])
 
 
420
  else:
421
  st.info(t.get('no_diagnosis', 'No hay datos de diagn贸stico disponibles'))
422
 
423
  # Tab de recomendaciones
424
  with recommendations_tab:
425
  if recommendation_data and 'recommendations' in recommendation_data:
 
426
  st.markdown(f"""
427
  <div style="padding: 20px; border-radius: 10px;
428
  background-color: #f8f9fa; margin-bottom: 20px;">
429
  {recommendation_data['recommendations']}
430
  </div>
431
+ """, unsafe_allow_html=True)
432
  elif recommendation_data and 'feedback' in recommendation_data:
 
433
  st.markdown(f"""
434
  <div style="padding: 20px; border-radius: 10px;
435
  background-color: #f8f9fa; margin-bottom: 20px;">
436
  {recommendation_data['feedback']}
437
  </div>
438
+ """, unsafe_allow_html=True)
439
  else:
440
  st.info(t.get('no_recommendations', 'No hay recomendaciones disponibles'))
441
 
 
447
  logger.error(f"Error mostrando actividades de situaci贸n actual: {str(e)}")
448
  st.error(t.get('error_current_situation', 'Error al mostrar an谩lisis de situaci贸n actual'))
449
 
450
+
451
  #################################################################################
452
  def display_discourse_comparison(analysis: dict, t: dict):
453
  """Muestra la comparaci贸n de an谩lisis del discurso"""