Spaces:
Running
Running
James McCool
Enhance team analysis functionality with sidebar options for team selection and prediction settings. Updated init_team_data function to incorporate win/loss predictions and display projected kills and deaths based on user input.
a655909
import streamlit as st | |
st.set_page_config(layout="wide") | |
import numpy as np | |
import pandas as pd | |
import pymongo | |
import time | |
def init_conn(): | |
uri = st.secrets['mongo_uri'] | |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000) | |
db = client["League_of_Legends_Database"] | |
collection = db["gamelogs"] | |
team_names = collection.distinct("teamname") | |
player_names = collection.distinct("playername") | |
return db, team_names, player_names | |
db, team_names, player_names = init_conn() | |
# Create sidebar container for options | |
with st.sidebar: | |
st.header("Team Analysis Options") | |
selected_team = st.selectbox( | |
"Select Team", | |
options=team_names, | |
index=team_names.index("T1") if "T1" in team_names else 0 | |
) | |
st.subheader("Prediction Settings") | |
win_loss = st.selectbox( | |
"Select Win/Loss", | |
options=["Win", "Loss"], | |
index=0 | |
) | |
kill_prediction = st.number_input( | |
"Predicted Team Kills", | |
min_value=0, | |
max_value=100, | |
value=15 | |
) | |
death_prediction = st.number_input( | |
"Predicted Team Deaths", | |
min_value=0, | |
max_value=100, | |
value=10 | |
) | |
def init_team_data(team, win_loss, kill_prediction, death_prediction): | |
collection = db["gamelogs"] | |
cursor = collection.find({"teamname": team}) | |
raw_display = pd.DataFrame(list(cursor)) | |
raw_display = raw_display[['playername', 'teamname', 'playername_avg_kill_share_win', 'playername_avg_death_share_win', 'playername_avg_assist_share_win', 'playername_avg_cs_share_win', 'playername_avg_kill_share_loss', 'playername_avg_death_share_loss', 'playername_avg_assist_share_loss', 'playername_avg_cs_share_loss']] | |
raw_display = raw_display.rename(columns = {'playername_avg_kill_share_win': 'wKill%', 'playername_avg_death_share_win': 'wDeath%', 'playername_avg_assist_share_win': 'wAssist%', 'playername_avg_cs_share_win': 'wCS%', 'playername_avg_kill_share_loss': 'lKill%', 'playername_avg_death_share_loss': 'lDeath%', 'playername_avg_assist_share_loss': 'lAssist%', 'playername_avg_cs_share_loss': 'lCS%'}) | |
team_data = raw_display.drop_duplicates(subset = ['playername']) | |
if win_loss == "Win": | |
team_data['Kill_Proj'] = team_data['wKill%'] * kill_prediction | |
team_data['Death_Proj'] = team_data['wDeath%'] * death_prediction | |
else: | |
team_data['Kill_Proj'] = team_data['lKill%'] * kill_prediction | |
team_data['Death_Proj'] = team_data['lDeath%'] * death_prediction | |
return team_data | |
if st.button("Run"): | |
st.dataframe(init_team_data(selected_team, win_loss, kill_prediction, death_prediction)) |