Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files26 unmodified lines27282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858626 unmodified linesst.set_page_config(page_title="DS Gaming Dashboard", layout="wide")st.title("๐ DS Gaming - CS 1.6 Admin Dashboard")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"# --- Start Analysis ----------------------------------------------------------if uploaded_file is not None and st.button("Analyze"):# --- 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.")# --- CASE 2: Log file (.log) uploaded ---elif uploaded_file.name.endswith(".log"):# --- Parsing Logs ----------------------------------------------------log_content = uploaded_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 = {}26 unmodified lines2728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311426 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"])# --- Globals -----------------------------------------------------------------DATA_DIR = Path(__file__).resolve().parent / "data"# ADMIN_FILE = DATA_DIR / "admins.txt"# --- Start Analysis ----------------------------------------------------------if uploaded_files is not None and st.button("Analyze"):# Filter files by typetxt_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 combinationsif 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: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 ---if CASE == "with log":# --- Parsing Logs ----------------------------------------------------log_content = log_file.read().decode("utf-8", errors="ignore")admin_actions = parse_log_file(log_content)# --- Combine stats ---------------------------------------------------combined_stats = {}
src/streamlit_app.py+70-42