Update app.py
Browse files
app.py
CHANGED
|
@@ -347,21 +347,21 @@ else:
|
|
| 347 |
except Exception as e:
|
| 348 |
st.error(f"Erro ao listar usuários: {e}")
|
| 349 |
|
| 350 |
-
|
| 351 |
# --- MÓDULO 4: ALUNOS SEM ACESSO NO SEMESTRE ATUAL ---
|
| 352 |
#######################################################
|
| 353 |
elif menu == "Alunos sem Acesso":
|
| 354 |
st.title("🚫 Alunos sem Acesso (Semestre Atual)")
|
| 355 |
st.write("Alunos do semestre atual que ainda não acessaram a plataforma.")
|
| 356 |
|
| 357 |
-
# Define o semestre atual dinamicamente
|
| 358 |
hoje = datetime.now()
|
| 359 |
semestre_atual = f"{hoje.year}.{1 if hoje.month <= 6 else 2}"
|
| 360 |
|
| 361 |
try:
|
| 362 |
conn = get_connection()
|
| 363 |
|
| 364 |
-
#
|
| 365 |
query_cursos = f"""
|
| 366 |
SELECT DISTINCT nome_curso
|
| 367 |
FROM portal_alunos_flat
|
|
@@ -371,48 +371,67 @@ else:
|
|
| 371 |
df_cursos = pd.read_sql(query_cursos, conn)
|
| 372 |
lista_cursos = ["Todos"] + df_cursos['nome_curso'].tolist()
|
| 373 |
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
|
|
|
|
|
|
|
|
|
| 376 |
if st.button("Gerar Lista"):
|
| 377 |
-
#
|
| 378 |
-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
query_sem_acesso = f"""
|
| 382 |
-
SELECT nome, sobrenome, email, celular, nome_curso, ultimo_acesso
|
| 383 |
FROM portal_alunos_flat
|
| 384 |
WHERE papel = 'Estudante'
|
| 385 |
AND semestre_referencia = '{semestre_atual}'
|
| 386 |
-
{
|
| 387 |
AND (
|
| 388 |
ultimo_acesso IS NULL
|
| 389 |
OR ultimo_acesso = ''
|
| 390 |
OR ultimo_acesso = '0000-00-00 00:00:00'
|
| 391 |
-
|
| 392 |
-
OR
|
| 393 |
-
-- Caso existam registros com 'Nunca' ou algo similar, eles também entram
|
| 394 |
-
OR ultimo_acesso NOT LIKE '%%2026%%'
|
| 395 |
)
|
| 396 |
-
ORDER BY nome_curso ASC, nome ASC
|
| 397 |
"""
|
| 398 |
|
| 399 |
df_sem_acesso = pd.read_sql(query_sem_acesso, conn)
|
| 400 |
|
| 401 |
if not df_sem_acesso.empty:
|
| 402 |
-
st.warning(f"Total de {len(df_sem_acesso)} alunos
|
| 403 |
st.dataframe(df_sem_acesso, use_container_width=True, hide_index=True)
|
| 404 |
|
| 405 |
-
# Log de Operação (Opcional: registrar quem gerou este relatório)
|
| 406 |
csv = df_sem_acesso.to_csv(index=False).encode('utf-8-sig')
|
| 407 |
st.download_button("📥 Baixar Lista para Cobrança", csv, f"sem_acesso_{semestre_atual}.csv", "text/csv")
|
| 408 |
else:
|
| 409 |
-
st.success("Parabéns! Todos os alunos
|
| 410 |
|
| 411 |
conn.close()
|
| 412 |
|
| 413 |
except Exception as e:
|
| 414 |
-
st.error(f"Erro ao processar relatório
|
| 415 |
-
|
| 416 |
#######################################################
|
| 417 |
# --- MÓDULO 5: AUDITORIA DE LOGS (APENAS ADMIN) ---
|
| 418 |
#######################################################
|
|
|
|
| 347 |
except Exception as e:
|
| 348 |
st.error(f"Erro ao listar usuários: {e}")
|
| 349 |
|
| 350 |
+
#######################################################
|
| 351 |
# --- MÓDULO 4: ALUNOS SEM ACESSO NO SEMESTRE ATUAL ---
|
| 352 |
#######################################################
|
| 353 |
elif menu == "Alunos sem Acesso":
|
| 354 |
st.title("🚫 Alunos sem Acesso (Semestre Atual)")
|
| 355 |
st.write("Alunos do semestre atual que ainda não acessaram a plataforma.")
|
| 356 |
|
| 357 |
+
# Define o semestre atual dinamicamente
|
| 358 |
hoje = datetime.now()
|
| 359 |
semestre_atual = f"{hoje.year}.{1 if hoje.month <= 6 else 2}"
|
| 360 |
|
| 361 |
try:
|
| 362 |
conn = get_connection()
|
| 363 |
|
| 364 |
+
# --- FILTRO 1: CURSO ---
|
| 365 |
query_cursos = f"""
|
| 366 |
SELECT DISTINCT nome_curso
|
| 367 |
FROM portal_alunos_flat
|
|
|
|
| 371 |
df_cursos = pd.read_sql(query_cursos, conn)
|
| 372 |
lista_cursos = ["Todos"] + df_cursos['nome_curso'].tolist()
|
| 373 |
|
| 374 |
+
col1, col2 = st.columns(2)
|
| 375 |
+
|
| 376 |
+
with col1:
|
| 377 |
+
curso_selecionado = st.selectbox("Filtrar por Curso:", lista_cursos)
|
| 378 |
+
|
| 379 |
+
# --- FILTRO 2: TURMA (Dependente do Curso) ---
|
| 380 |
+
lista_turmas = ["Todas"]
|
| 381 |
+
if curso_selecionado != "Todos":
|
| 382 |
+
query_turmas = f"""
|
| 383 |
+
SELECT DISTINCT turma
|
| 384 |
+
FROM portal_alunos_flat
|
| 385 |
+
WHERE semestre_referencia = '{semestre_atual}'
|
| 386 |
+
AND nome_curso = '{curso_selecionado}'
|
| 387 |
+
ORDER BY turma
|
| 388 |
+
"""
|
| 389 |
+
df_turmas = pd.read_sql(query_turmas, conn)
|
| 390 |
+
lista_turmas = ["Todas"] + df_turmas['turma'].tolist()
|
| 391 |
|
| 392 |
+
with col2:
|
| 393 |
+
turma_selecionada = st.selectbox("Filtrar por Turma:", lista_turmas, disabled=(curso_selecionado == "Todos"))
|
| 394 |
+
|
| 395 |
if st.button("Gerar Lista"):
|
| 396 |
+
# Montagem dinâmica dos filtros SQL
|
| 397 |
+
filtro_sql = ""
|
| 398 |
+
if curso_selecionado != "Todos":
|
| 399 |
+
filtro_sql += f" AND nome_curso = '{curso_selecionado}'"
|
| 400 |
+
if turma_selecionada != "Todas":
|
| 401 |
+
filtro_sql += f" AND turma = '{turma_selecionada}'"
|
| 402 |
|
| 403 |
query_sem_acesso = f"""
|
| 404 |
+
SELECT nome, sobrenome, email, celular, nome_curso, turma, ultimo_acesso
|
| 405 |
FROM portal_alunos_flat
|
| 406 |
WHERE papel = 'Estudante'
|
| 407 |
AND semestre_referencia = '{semestre_atual}'
|
| 408 |
+
{filtro_sql}
|
| 409 |
AND (
|
| 410 |
ultimo_acesso IS NULL
|
| 411 |
OR ultimo_acesso = ''
|
| 412 |
OR ultimo_acesso = '0000-00-00 00:00:00'
|
| 413 |
+
OR STR_TO_DATE(ultimo_acesso, '%%d/%%m/%%Y') < '{hoje.year}-01-01'
|
| 414 |
+
OR ultimo_acesso NOT LIKE '%%{hoje.year}%%'
|
|
|
|
|
|
|
| 415 |
)
|
| 416 |
+
ORDER BY nome_curso ASC, turma ASC, nome ASC
|
| 417 |
"""
|
| 418 |
|
| 419 |
df_sem_acesso = pd.read_sql(query_sem_acesso, conn)
|
| 420 |
|
| 421 |
if not df_sem_acesso.empty:
|
| 422 |
+
st.warning(f"Total de {len(df_sem_acesso)} alunos sem acesso em {semestre_atual}.")
|
| 423 |
st.dataframe(df_sem_acesso, use_container_width=True, hide_index=True)
|
| 424 |
|
|
|
|
| 425 |
csv = df_sem_acesso.to_csv(index=False).encode('utf-8-sig')
|
| 426 |
st.download_button("📥 Baixar Lista para Cobrança", csv, f"sem_acesso_{semestre_atual}.csv", "text/csv")
|
| 427 |
else:
|
| 428 |
+
st.success("Parabéns! Todos os alunos selecionados já acessaram o sistema.")
|
| 429 |
|
| 430 |
conn.close()
|
| 431 |
|
| 432 |
except Exception as e:
|
| 433 |
+
st.error(f"Erro ao processar relatório: {e}")
|
| 434 |
+
|
| 435 |
#######################################################
|
| 436 |
# --- MÓDULO 5: AUDITORIA DE LOGS (APENAS ADMIN) ---
|
| 437 |
#######################################################
|