Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,7 @@ else:
|
|
| 74 |
menu = st.sidebar.radio("Navegação", opcoes_menu)
|
| 75 |
|
| 76 |
st.sidebar.markdown("---")
|
| 77 |
-
if st.sidebar.button("
|
| 78 |
st.session_state.logado = False
|
| 79 |
st.rerun()
|
| 80 |
|
|
@@ -102,10 +102,10 @@ else:
|
|
| 102 |
alunos = df[['nome', 'sobrenome', 'email', 'ultimo_acesso']].drop_duplicates()
|
| 103 |
for _, aluno in alunos.iterrows():
|
| 104 |
with st.expander(f"👤 {aluno['nome']} {aluno['sobrenome']} ({aluno['email']})"):
|
| 105 |
-
st.metric(label="📅 Último Logon
|
| 106 |
st.write("---")
|
| 107 |
hist = df[df['email'] == aluno['email']][['semestre_referencia', 'nome_curso', 'papel', 'turmas', 'data_inicial']]
|
| 108 |
-
hist = hist.sort_values(by=['semestre_referencia', 'nome_curso']
|
| 109 |
hist.columns = ['Semestre', 'Curso', 'Papel', 'Turmas', 'Início']
|
| 110 |
st.dataframe(hist, use_container_width=True, hide_index=True)
|
| 111 |
else:
|
|
@@ -116,26 +116,21 @@ else:
|
|
| 116 |
# --- MÓDULO 2: RELATÓRIO DE RETENÇÃO ---
|
| 117 |
elif menu == "Relatórios de Retenção":
|
| 118 |
st.title("📊 Relatório de Retenção: Ciclo IX para X")
|
| 119 |
-
st.write("
|
| 120 |
|
| 121 |
-
qtd_semestres = st.number_input("
|
| 122 |
-
min_value=1, max_value=10, value=2)
|
| 123 |
|
| 124 |
hoje = datetime.now()
|
| 125 |
-
ano = hoje.year
|
| 126 |
-
sem_atual = 1 if hoje.month <= 6 else 2
|
| 127 |
lista_semestres = []
|
| 128 |
-
|
| 129 |
|
| 130 |
for _ in range(qtd_semestres):
|
| 131 |
-
if
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
else:
|
| 135 |
-
temp_sem = 1
|
| 136 |
-
lista_semestres.append(f"{temp_ano}.{temp_sem}")
|
| 137 |
|
| 138 |
-
st.info(f"Analisando
|
| 139 |
|
| 140 |
if st.button("Gerar Relatório"):
|
| 141 |
try:
|
|
@@ -157,22 +152,21 @@ else:
|
|
| 157 |
conn.close()
|
| 158 |
|
| 159 |
if not df_retidos.empty:
|
| 160 |
-
st.success(f"Encontrados {len(df_retidos)} alunos
|
| 161 |
st.dataframe(df_retidos, use_container_width=True, hide_index=True)
|
| 162 |
csv = df_retidos.to_csv(index=False).encode('utf-8-sig')
|
| 163 |
-
st.download_button(
|
| 164 |
-
file_name=f"retidos_IX_X_{datetime.now().strftime('%Y%m%d')}.csv")
|
| 165 |
else:
|
| 166 |
-
st.warning("Nenhum aluno encontrado
|
| 167 |
except Exception as e:
|
| 168 |
-
st.error(f"Erro
|
| 169 |
|
| 170 |
# --- MÓDULO 3: GESTÃO DE USUÁRIOS ---
|
| 171 |
elif menu == "Gerenciar Usuários":
|
| 172 |
st.title("👥 Gestão de Usuários")
|
| 173 |
-
with st.expander("➕
|
| 174 |
-
with st.form("
|
| 175 |
-
n_nome = st.text_input("Nome
|
| 176 |
n_email = st.text_input("E-mail")
|
| 177 |
n_senha = st.text_input("Senha", type="password")
|
| 178 |
n_perfil = st.selectbox("Perfil", ["consulta", "admin"])
|
|
@@ -180,14 +174,13 @@ else:
|
|
| 180 |
try:
|
| 181 |
conn = get_connection()
|
| 182 |
cursor = conn.cursor()
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
(n_nome, n_email, h, n_perfil))
|
| 186 |
conn.commit()
|
| 187 |
conn.close()
|
| 188 |
-
st.success("
|
| 189 |
except Exception as e:
|
| 190 |
-
st.error(f"Erro
|
| 191 |
|
| 192 |
try:
|
| 193 |
conn = get_connection()
|
|
@@ -195,5 +188,5 @@ else:
|
|
| 195 |
conn.close()
|
| 196 |
st.dataframe(df_users, use_container_width=True)
|
| 197 |
except Exception as e:
|
| 198 |
-
st.error(f"Erro ao
|
| 199 |
|
|
|
|
| 74 |
menu = st.sidebar.radio("Navegação", opcoes_menu)
|
| 75 |
|
| 76 |
st.sidebar.markdown("---")
|
| 77 |
+
if st.sidebar.button("Sair"):
|
| 78 |
st.session_state.logado = False
|
| 79 |
st.rerun()
|
| 80 |
|
|
|
|
| 102 |
alunos = df[['nome', 'sobrenome', 'email', 'ultimo_acesso']].drop_duplicates()
|
| 103 |
for _, aluno in alunos.iterrows():
|
| 104 |
with st.expander(f"👤 {aluno['nome']} {aluno['sobrenome']} ({aluno['email']})"):
|
| 105 |
+
st.metric(label="📅 Último Logon", value=str(aluno['ultimo_acesso']))
|
| 106 |
st.write("---")
|
| 107 |
hist = df[df['email'] == aluno['email']][['semestre_referencia', 'nome_curso', 'papel', 'turmas', 'data_inicial']]
|
| 108 |
+
hist = hist.sort_values(by=['semestre_referencia', 'nome_curso'])
|
| 109 |
hist.columns = ['Semestre', 'Curso', 'Papel', 'Turmas', 'Início']
|
| 110 |
st.dataframe(hist, use_container_width=True, hide_index=True)
|
| 111 |
else:
|
|
|
|
| 116 |
# --- MÓDULO 2: RELATÓRIO DE RETENÇÃO ---
|
| 117 |
elif menu == "Relatórios de Retenção":
|
| 118 |
st.title("📊 Relatório de Retenção: Ciclo IX para X")
|
| 119 |
+
st.write("Alunos que cursaram Ciclo IX, mas não constam no Ciclo X.")
|
| 120 |
|
| 121 |
+
qtd_semestres = st.number_input("Semestres anteriores (excluindo atual):", 1, 10, 2)
|
|
|
|
| 122 |
|
| 123 |
hoje = datetime.now()
|
| 124 |
+
ano, sem_atual = hoje.year, (1 if hoje.month <= 6 else 2)
|
|
|
|
| 125 |
lista_semestres = []
|
| 126 |
+
t_ano, t_sem = ano, sem_atual
|
| 127 |
|
| 128 |
for _ in range(qtd_semestres):
|
| 129 |
+
if t_sem == 1: t_ano -= 1; t_sem = 2
|
| 130 |
+
else: t_sem = 1
|
| 131 |
+
lista_semestres.append(f"{t_ano}.{t_sem}")
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
st.info(f"Analisando: {', '.join(lista_semestres)}")
|
| 134 |
|
| 135 |
if st.button("Gerar Relatório"):
|
| 136 |
try:
|
|
|
|
| 152 |
conn.close()
|
| 153 |
|
| 154 |
if not df_retidos.empty:
|
| 155 |
+
st.success(f"Encontrados {len(df_retidos)} alunos.")
|
| 156 |
st.dataframe(df_retidos, use_container_width=True, hide_index=True)
|
| 157 |
csv = df_retidos.to_csv(index=False).encode('utf-8-sig')
|
| 158 |
+
st.download_button("📥 Baixar CSV", csv, "retidos.csv", "text/csv")
|
|
|
|
| 159 |
else:
|
| 160 |
+
st.warning("Nenhum aluno encontrado.")
|
| 161 |
except Exception as e:
|
| 162 |
+
st.error(f"Erro no processamento: {e}")
|
| 163 |
|
| 164 |
# --- MÓDULO 3: GESTÃO DE USUÁRIOS ---
|
| 165 |
elif menu == "Gerenciar Usuários":
|
| 166 |
st.title("👥 Gestão de Usuários")
|
| 167 |
+
with st.expander("➕ Novo Usuário"):
|
| 168 |
+
with st.form("cad_user"):
|
| 169 |
+
n_nome = st.text_input("Nome")
|
| 170 |
n_email = st.text_input("E-mail")
|
| 171 |
n_senha = st.text_input("Senha", type="password")
|
| 172 |
n_perfil = st.selectbox("Perfil", ["consulta", "admin"])
|
|
|
|
| 174 |
try:
|
| 175 |
conn = get_connection()
|
| 176 |
cursor = conn.cursor()
|
| 177 |
+
cursor.execute("INSERT INTO app_usuarios (nome, email, senha_hash, perfil) VALUES (%s,%s,%s,%s)",
|
| 178 |
+
(n_nome, n_email, gerar_hash(n_senha), n_perfil))
|
|
|
|
| 179 |
conn.commit()
|
| 180 |
conn.close()
|
| 181 |
+
st.success("Salvo!")
|
| 182 |
except Exception as e:
|
| 183 |
+
st.error(f"Erro: {e}")
|
| 184 |
|
| 185 |
try:
|
| 186 |
conn = get_connection()
|
|
|
|
| 188 |
conn.close()
|
| 189 |
st.dataframe(df_users, use_container_width=True)
|
| 190 |
except Exception as e:
|
| 191 |
+
st.error(f"Erro ao listar usuários: {e}")
|
| 192 |
|