Update modules/database.py
Browse files- modules/database.py +19 -16
modules/database.py
CHANGED
|
@@ -23,6 +23,7 @@ mongo_client = None
|
|
| 23 |
mongo_db = None
|
| 24 |
analysis_collection = None
|
| 25 |
|
|
|
|
| 26 |
def initialize_cosmos_sql_connection():
|
| 27 |
global cosmos_client, user_database, user_container
|
| 28 |
try:
|
|
@@ -42,6 +43,7 @@ def initialize_cosmos_sql_connection():
|
|
| 42 |
logger.error(f"Error al conectar con Cosmos DB SQL API: {str(e)}")
|
| 43 |
return False
|
| 44 |
|
|
|
|
| 45 |
def initialize_mongodb_connection():
|
| 46 |
global mongo_client, mongo_db, analysis_collection
|
| 47 |
try:
|
|
@@ -69,8 +71,8 @@ def initialize_mongodb_connection():
|
|
| 69 |
logger.error(f"Error al conectar con Cosmos DB MongoDB API: {str(e)}", exc_info=True)
|
| 70 |
return False
|
| 71 |
|
|
|
|
| 72 |
# Funciones para Cosmos DB SQL API (manejo de usuarios)
|
| 73 |
-
|
| 74 |
def get_user(username):
|
| 75 |
try:
|
| 76 |
query = f"SELECT * FROM c WHERE c.id = '{username}'"
|
|
@@ -111,21 +113,22 @@ def get_student_data(username):
|
|
| 111 |
|
| 112 |
# Formatear los datos
|
| 113 |
formatted_data = {
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
| 129 |
|
| 130 |
# Agregar conteo de palabras
|
| 131 |
for category, count in entry.get("word_count", {}).items():
|
|
|
|
| 23 |
mongo_db = None
|
| 24 |
analysis_collection = None
|
| 25 |
|
| 26 |
+
#####################################################################################33
|
| 27 |
def initialize_cosmos_sql_connection():
|
| 28 |
global cosmos_client, user_database, user_container
|
| 29 |
try:
|
|
|
|
| 43 |
logger.error(f"Error al conectar con Cosmos DB SQL API: {str(e)}")
|
| 44 |
return False
|
| 45 |
|
| 46 |
+
############################################################################################3
|
| 47 |
def initialize_mongodb_connection():
|
| 48 |
global mongo_client, mongo_db, analysis_collection
|
| 49 |
try:
|
|
|
|
| 71 |
logger.error(f"Error al conectar con Cosmos DB MongoDB API: {str(e)}", exc_info=True)
|
| 72 |
return False
|
| 73 |
|
| 74 |
+
#######################################################################################################
|
| 75 |
# Funciones para Cosmos DB SQL API (manejo de usuarios)
|
|
|
|
| 76 |
def get_user(username):
|
| 77 |
try:
|
| 78 |
query = f"SELECT * FROM c WHERE c.id = '{username}'"
|
|
|
|
| 113 |
|
| 114 |
# Formatear los datos
|
| 115 |
formatted_data = {
|
| 116 |
+
"username": username,
|
| 117 |
+
"entries": [
|
| 118 |
+
{
|
| 119 |
+
"timestamp": entry["timestamp"].isoformat(),
|
| 120 |
+
"text": entry["text"],
|
| 121 |
+
"word_count": entry.get("word_count", {}),
|
| 122 |
+
"arc_diagrams": entry.get("arc_diagrams", []),
|
| 123 |
+
"network_diagram": entry.get("network_diagram", "")
|
| 124 |
+
}
|
| 125 |
+
for entry in cursor
|
| 126 |
+
],
|
| 127 |
+
"entries_count": count,
|
| 128 |
+
"word_count": aggregated_word_count
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return formatted_data
|
| 132 |
|
| 133 |
# Agregar conteo de palabras
|
| 134 |
for category, count in entry.get("word_count", {}).items():
|