|
|
|
|
|
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__) |
|
|
|
|
|
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, |
|
'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, |
|
'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) |
|
|
|
|
|
base_collection = get_collection(COLLECTION_NAME) |
|
base_collection.update_one( |
|
{'_id': base_id, 'username': username}, |
|
{'$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 |