File size: 2,407 Bytes
fc2963d
 
 
 
 
 
 
 
2f46275
 
 
fc2963d
 
2f46275
fc2963d
 
2f46275
fc2963d
 
 
 
 
 
 
2f46275
fc2963d
 
 
 
 
 
 
 
 
2f46275
fc2963d
 
2f46275
fc2963d
 
 
2f46275
fc2963d
 
 
 
2f46275
fc2963d
 
2f46275
 
fc2963d
2f46275
fc2963d
 
 
 
 
 
 
 
2f46275
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# modules/database/morphosyntax_iterative_mongo_db.py

from datetime import datetime, timezone
import logging
from .mongo_db import get_collection, insert_document, find_documents, update_document, delete_document

logger = logging.getLogger(__name__)

# Nombres de colecciones manteniendo coherencia
COLLECTION_NAME = 'student_morphosyntax_analysis'
COLLECTION_NAME_ITERATIONS = 'student_morphosyntax_iterations'

def store_student_morphosyntax_base(username, text, arc_diagrams):
    """Almacena el an谩lisis morfosint谩ctico base"""
    try:
        base_document = {
            'username': username,  # key principal
            'timestamp': datetime.now(timezone.utc).isoformat(),
            'text': text,
            'arc_diagrams': arc_diagrams,
            'analysis_type': 'morphosyntax_base',
            'has_iterations': False
        }
        
        collection = get_collection(COLLECTION_NAME)
        result = collection.insert_one(base_document)
        logger.info(f"An谩lisis base guardado para {username}")
        return str(result.inserted_id)
        
    except Exception as e:
        logger.error(f"Error almacenando an谩lisis base: {str(e)}")
        return None

def store_student_morphosyntax_iteration(username, base_id, original_text, iteration_text, arc_diagrams):
    """Almacena una iteraci贸n de an谩lisis morfosint谩ctico"""
    try:
        iteration_document = {
            'username': username,  # key principal
            'base_id': base_id,
            'timestamp': datetime.now(timezone.utc).isoformat(),
            'original_text': original_text,
            'iteration_text': iteration_text,
            'arc_diagrams': arc_diagrams,
            'analysis_type': 'morphosyntax_iteration'
        }
        
        collection = get_collection(COLLECTION_NAME_ITERATIONS)
        result = collection.insert_one(iteration_document)
        
        # Actualizar documento base
        base_collection = get_collection(COLLECTION_NAME)
        base_collection.update_one(
            {'_id': base_id, 'username': username},  # incluir username en queries
            {'$set': {'has_iterations': True}}
        )
        
        logger.info(f"Iteraci贸n guardada para {username}, base_id: {base_id}")
        return str(result.inserted_id)
        
    except Exception as e:
        logger.error(f"Error almacenando iteraci贸n: {str(e)}")
        return None