Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files26 unmodified lines2728293031323334353637383940414243444546314748495035515253385455565758596061626364656667686970717240414243444546474849505152535455565758596061626364656667686970717374757677787980818283848586878889909192939495969798991001011021031041051067410710876109110111798081828311211311426 unmodified linesst.set_page_config(page_title="DS Gaming Dashboard", layout="wide")st.title("๐ DS Gaming - CS 1.6 Admin Dashboard")
# uploaded_files = st.file_uploader(# "Upload one or more server log files (*.log) or admin files (*.txt)",# type=["log", "txt"],# accept_multiple_files=True# )
st.markdown( """**Upload either a single admin file (`*.txt`) or a pair of files: a `*.log` and a `*.txt`.**
- If the text file is named **`admins.txt`**, data will be taken from the **DS GAMING PUBLIC SERVER**.- If it is named **`admins_afk.txt`**, data will be taken from the **DS GAMING AFK SERVER**.""")
uploaded_files = st.file_uploader("Upload your files", type=["log", "txt"],accept_multiple_files=True)
uploaded_file = st.file_uploader("Upload a server log file (*.log) or an **admins_type.txt** file containing the admin names, with one name per line. The type can be either **public** or **afk**.", type=["log", "txt"])# uploaded_file = st.file_uploader("Upload a server log file (*.log) or an **admins_type.txt** file containing the admin names, with one name per line. The type can be either **public** or **afk**.", type=["log", "txt"])
# --- Globals -----------------------------------------------------------------DATA_DIR = Path(__file__).resolve().parent / "data"ADMIN_FILE = DATA_DIR / "admins.txt"# ADMIN_FILE = DATA_DIR / "admins.txt"
# --- Start Analysis ----------------------------------------------------------if uploaded_file is not None and st.button("Analyze"):if uploaded_files is not None and st.button("Analyze"):
# Filter files by type txt_files = [f for f in uploaded_files if f.name.lower().endswith(".txt")] log_files = [f for f in uploaded_files if f.name.lower().endswith(".log")]
CASE = None # Check allowed combinations if len(uploaded_files) == 1 and len(txt_files) == 1: admin_file = txt_files[0] st.success(f"Admin file uploaded: {admin_file.name}")
elif len(uploaded_files) == 2 and len(txt_files) == 1 and len(log_files) == 1: admin_file = txt_files[0] log_file = log_files[0] st.success(f"Files uploaded: Admin = {admin_file.name}, Log = {log_file.name}") CASE = "with log"
else: # --- CASE 1: Admin list (.txt) uploaded --- if uploaded_file.name.endswith(".txt"): # --- Grab Admin Names from File -------------------------------------- content = uploaded_file.getvalue().decode("utf-8") admins = [line.strip() for line in content.splitlines() if line.strip()] # --- Check if AFK or PUBLIC ------------------------------------------ if "afk" in uploaded_file.name: server = "afk" else: server = "public" st.info(f"Grabbing data from DS GAMING {server.upper()} SERVER.") # --- GameTracker Section --------------------------------------------- st.subheader("๐ฎ GameTracker Playtime") with st.spinner("โณ Fetching GameTracker Data..."): gt_results = fetch_playtimes(admins, server) # gt_results = fetch_playtimes(ADMIN_FILE)
# --- Leaderboard ----------------------------------------------------- st.subheader("๐ Leaderboard (Minutes Played)") if gt_results: leaderboard = pd.DataFrame({ "Admin": list(gt_results.keys()), "Minutes": list(gt_results.values()) }) leaderboard = leaderboard.sort_values("Minutes", ascending=False).reset_index(drop=True) leaderboard.insert(0, "Rank", range(1, len(leaderboard)+1)) st.dataframe(leaderboard.set_index("Rank"), height=400, width=600) else: st.info("No GameTracker results found.") st.error("โ Invalid upload. Please upload either a single *.txt or exactly one *.log and one *.txt file.")
# --- Grab Admin Names from File -------------------------------------- content = admin_file.getvalue().decode("utf-8") admins = [line.strip() for line in content.splitlines() if line.strip()]
# --- Check if AFK or PUBLIC ------------------------------------------ if "afk" in admin_file.name: server = "afk" else: server = "public"
st.info(f"Grabbing data from DS GAMING {server.upper()} SERVER.")
# --- GameTracker Section --------------------------------------------- st.subheader("๐ฎ GameTracker Playtime") with st.spinner("โณ Fetching GameTracker Data..."): gt_results = fetch_playtimes(admins, server) # gt_results = fetch_playtimes(ADMIN_FILE)
# --- Leaderboard ----------------------------------------------------- st.subheader("๐ Leaderboard (Minutes Played)") if gt_results: leaderboard = pd.DataFrame({ "Admin": list(gt_results.keys()), "Minutes": list(gt_results.values()) }) leaderboard = leaderboard.sort_values("Minutes", ascending=False).reset_index(drop=True) leaderboard.insert(0, "Rank", range(1, len(leaderboard)+1)) st.dataframe(leaderboard.set_index("Rank"), height=400, width=600) else: st.info("No GameTracker results found.")
# --- CASE 2: Log file (.log) uploaded --- elif uploaded_file.name.endswith(".log"): if CASE == "with log": # --- Parsing Logs ---------------------------------------------------- log_content = uploaded_file.read().decode("utf-8", errors="ignore") log_content = log_file.read().decode("utf-8", errors="ignore") admin_actions = parse_log_file(log_content) # --- GameTracker Section --------------------------------------------- st.subheader("๐ฎ GameTracker Playtime") with st.spinner("โณ Fetching GameTracker Data..."): gt_results = fetch_playtimes(ADMIN_FILE) # gt_results = fetch_playtimes(ADMIN_FILE) # --- Combine stats --------------------------------------------------- combined_stats = {}src/streamlit_app.py+70-42