Update modules/database.py
Browse files- modules/database.py +0 -89
modules/database.py
CHANGED
|
@@ -127,95 +127,6 @@ def get_user(username):
|
|
| 127 |
print(f"Error al obtener usuario {username}: {str(e)}")
|
| 128 |
return None
|
| 129 |
|
| 130 |
-
################################################################################
|
| 131 |
-
# Funciones para Cosmos DB MongoDB API (análisis de texto)
|
| 132 |
-
def display_student_progress(username, lang_code='es'):
|
| 133 |
-
student_data = get_student_data(username)
|
| 134 |
-
|
| 135 |
-
if student_data is None:
|
| 136 |
-
st.warning("No se encontraron datos para este estudiante.")
|
| 137 |
-
st.info("Intenta realizar algunos análisis de texto primero.")
|
| 138 |
-
return
|
| 139 |
-
|
| 140 |
-
st.title(f"Progreso de {username}")
|
| 141 |
-
|
| 142 |
-
if student_data['entries_count'] > 0:
|
| 143 |
-
# Mostrar el conteo de palabras
|
| 144 |
-
if student_data['word_count']:
|
| 145 |
-
with st.expander("Total de palabras por categoría gramatical", expanded=False):
|
| 146 |
-
df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
|
| 147 |
-
df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}", axis=1)
|
| 148 |
-
df = df.sort_values('count', ascending=False)
|
| 149 |
-
|
| 150 |
-
fig, ax = plt.subplots(figsize=(12, 6))
|
| 151 |
-
bars = ax.bar(df['label'], df['count'], color=df['category'])
|
| 152 |
-
|
| 153 |
-
ax.set_xlabel('Categoría Gramatical')
|
| 154 |
-
ax.set_ylabel('Cantidad de Palabras')
|
| 155 |
-
ax.set_title('Total de palabras por categoría gramatical')
|
| 156 |
-
plt.xticks(rotation=45, ha='right')
|
| 157 |
-
|
| 158 |
-
for bar in bars:
|
| 159 |
-
height = bar.get_height()
|
| 160 |
-
ax.text(bar.get_x() + bar.get_width()/2., height, f'{height}', ha='center', va='bottom')
|
| 161 |
-
|
| 162 |
-
plt.tight_layout()
|
| 163 |
-
st.pyplot(fig)
|
| 164 |
-
|
| 165 |
-
# Mostrar análisis morfosintáctico
|
| 166 |
-
morphosyntax_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
|
| 167 |
-
if morphosyntax_entries:
|
| 168 |
-
with st.expander("Análisis Morfosintáctico - Diagramas de Arco", expanded=False):
|
| 169 |
-
for i, entry in enumerate(morphosyntax_entries):
|
| 170 |
-
st.subheader(f"Análisis {i+1} - {entry['timestamp']}")
|
| 171 |
-
st.write(entry['text'])
|
| 172 |
-
for j, diagram in enumerate(entry.get('arc_diagrams', [])):
|
| 173 |
-
st.subheader(f"Diagrama de Arco {j+1}")
|
| 174 |
-
st.write(diagram, unsafe_allow_html=True)
|
| 175 |
-
|
| 176 |
-
# Mostrar análisis semántico
|
| 177 |
-
if student_data['semantic_analyses']:
|
| 178 |
-
with st.expander("Análisis Semántico - Diagramas de Red", expanded=False):
|
| 179 |
-
for i, entry in enumerate(student_data['semantic_analyses']):
|
| 180 |
-
st.subheader(f"Análisis Semántico {i+1} - {entry['timestamp']}")
|
| 181 |
-
st.write(entry['text'])
|
| 182 |
-
if 'network_diagram' in entry:
|
| 183 |
-
image_bytes = base64.b64decode(entry['network_diagram'])
|
| 184 |
-
st.image(image_bytes)
|
| 185 |
-
|
| 186 |
-
# Mostrar análisis del discurso
|
| 187 |
-
if student_data['discourse_analyses']:
|
| 188 |
-
with st.expander("Análisis del Discurso - Comparación de Grafos", expanded=False):
|
| 189 |
-
for i, entry in enumerate(student_data['discourse_analyses']):
|
| 190 |
-
st.subheader(f"Análisis del Discurso {i+1} - {entry['timestamp']}")
|
| 191 |
-
st.write("Texto del documento patrón:")
|
| 192 |
-
st.write(entry.get('text1', 'No disponible'))
|
| 193 |
-
st.write("Texto del documento comparado:")
|
| 194 |
-
st.write(entry.get('text2', 'No disponible'))
|
| 195 |
-
if 'graph1' in entry:
|
| 196 |
-
st.image(base64.b64decode(entry['graph1']))
|
| 197 |
-
if 'graph2' in entry:
|
| 198 |
-
st.image(base64.b64decode(entry['graph2']))
|
| 199 |
-
|
| 200 |
-
# Mostrar conversaciones del chat
|
| 201 |
-
if student_data['chat_history']:
|
| 202 |
-
with st.expander("Historial de Conversaciones del Chat", expanded=False):
|
| 203 |
-
for i, chat in enumerate(student_data['chat_history']):
|
| 204 |
-
st.subheader(f"Conversación {i+1} - {chat['timestamp']}")
|
| 205 |
-
for message in chat['messages']:
|
| 206 |
-
if message['role'] == 'user':
|
| 207 |
-
st.write("Usuario: " + message['content'])
|
| 208 |
-
else:
|
| 209 |
-
st.write("Asistente: " + message['content'])
|
| 210 |
-
st.write("---")
|
| 211 |
-
else:
|
| 212 |
-
st.warning("No se encontraron entradas para este estudiante.")
|
| 213 |
-
st.info("Intenta realizar algunos análisis de texto primero.")
|
| 214 |
-
|
| 215 |
-
# Añadir logs para depuración
|
| 216 |
-
st.write("Datos del estudiante (para depuración):")
|
| 217 |
-
st.json(student_data)
|
| 218 |
-
|
| 219 |
#######################################################################################################
|
| 220 |
|
| 221 |
def store_morphosyntax_result(username, text, repeated_words, arc_diagrams):
|
|
|
|
| 127 |
print(f"Error al obtener usuario {username}: {str(e)}")
|
| 128 |
return None
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
#######################################################################################################
|
| 131 |
|
| 132 |
def store_morphosyntax_result(username, text, repeated_words, arc_diagrams):
|