AIdeaText commited on
Commit
991247e
verified
1 Parent(s): ecb7489

Update modules/database/current_situation_mongo_db.py

Browse files
modules/database/current_situation_mongo_db.py CHANGED
@@ -13,8 +13,36 @@ def store_current_situation_result(username, text, metrics, feedback):
13
  Guarda los resultados del an谩lisis de situaci贸n actual.
14
  """
15
  try:
16
- collection = get_collection('student_current_situation')
 
 
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  # Crear documento
19
  document = {
20
  'username': username,
@@ -29,7 +57,13 @@ def store_current_situation_result(username, text, metrics, feedback):
29
  result = collection.insert_one(document)
30
 
31
  if result.inserted_id:
32
- logger.info(f"An谩lisis de situaci贸n actual guardado para {username}")
 
 
 
 
 
 
33
  return True
34
 
35
  logger.error("No se pudo insertar el documento")
 
13
  Guarda los resultados del an谩lisis de situaci贸n actual.
14
  """
15
  try:
16
+ # Verificar par谩metros
17
+ if not all([username, text, metrics]):
18
+ logger.error("Faltan par谩metros requeridos")
19
+ return False
20
 
21
+ collection = get_collection('student_current_situation')
22
+ if collection is None:
23
+ logger.error("No se pudo obtener la colecci贸n")
24
+ return False
25
+
26
+ # Formatear m茅tricas para MongoDB
27
+ formatted_metrics = {
28
+ 'vocabulary': {
29
+ 'score': metrics['vocabulary']['normalized_score'],
30
+ 'details': metrics['vocabulary']['details']
31
+ },
32
+ 'structure': {
33
+ 'score': metrics['structure']['normalized_score'],
34
+ 'details': metrics['structure']['details']
35
+ },
36
+ 'cohesion': {
37
+ 'score': metrics['cohesion']['normalized_score'],
38
+ 'details': metrics['cohesion']['details']
39
+ },
40
+ 'clarity': {
41
+ 'score': metrics['clarity']['normalized_score'],
42
+ 'details': metrics['clarity']['details']
43
+ }
44
+ }
45
+
46
  # Crear documento
47
  document = {
48
  'username': username,
 
57
  result = collection.insert_one(document)
58
 
59
  if result.inserted_id:
60
+ logger.info(f"""
61
+ An谩lisis guardado exitosamente:
62
+ - Usuario: {username}
63
+ - ID: {result.inserted_id}
64
+ - Longitud del texto: {len(text)}
65
+ - M茅tricas: {formatted_metrics}
66
+ """)
67
  return True
68
 
69
  logger.error("No se pudo insertar el documento")