-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathranking_app.py
More file actions
72 lines (56 loc) · 2.01 KB
/
Copy pathranking_app.py
File metadata and controls
72 lines (56 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import pandas as pd
from pathlib import Path
from streamlit_autorefresh import st_autorefresh
# Caminho do arquivo CSV
FILE_PATH = Path("ranking.csv")
st.set_page_config(page_title="🏆 Ranking Seringal Bros", page_icon="🦫", layout="centered")
st.title("🏆 Top 20 - Seringal Bros")
st.caption("Melhores pontuações registradas no jogo")
st_autorefresh(interval=5000, key="refresh_ranking")
# --- Carrega o arquivo ---
if not FILE_PATH.exists():
st.warning("⚠️ Ainda não há pontuações registradas.")
st.stop()
df = pd.read_csv(FILE_PATH)
# -----------------------------
# Leitura e processamento
# -----------------------------
df = pd.read_csv(FILE_PATH)
# Compatibilidade com versões antigas
if "melhor_score" not in df.columns and "score" in df.columns:
df["melhor_score"] = df["score"]
# Converte a data para datetime
df["data_hora"] = pd.to_datetime(df["data_hora"], errors="coerce")
# Ordena por pontuação (descendente) e data (ascendente)
ranking = df.sort_values(
by=["melhor_score", "data_hora"],
ascending=[False, True]
).reset_index(drop=True)
# Mantém apenas os 20 primeiros
ranking = ranking.head(20)
# Adiciona posição (começando em 1)
ranking.insert(0, "Rank", range(1, len(ranking) + 1))
# Medalhas para os 3 primeiros
medalhas = ["🥇", "🥈", "🥉"]
ranking["Rank"] = ranking["Rank"].apply(
lambda x: medalhas[x-1] if x <= 3 else f"{x}ᵒ"
)
# Formata a coluna de data/hora no formato "HH:MM:SS YYYY"
ranking["data_hora"] = ranking["data_hora"].dt.strftime("%H:%M:%S %d/%m/%Y")
# Renomeia colunas pra exibição
ranking = ranking.rename(columns={
"nome": "Jogador",
"melhor_score": "Pontuação",
"data_hora": "Hora"
})
# -----------------------------
# Exibição no Streamlit
# -----------------------------
st.dataframe(
ranking[["Rank", "Jogador", "Pontuação", "Hora"]]
.style.format({"Pontuação": "{:.0f}"}),
use_container_width=True,
hide_index=True
)
# st.caption("*Atualizado automaticamente a cada 5 segundos")