Spaces:
No application file
No application file
File size: 2,522 Bytes
cba8171 bde45ea cba8171 1bc3119 cba8171 1bc3119 cba8171 8039ca4 cba8171 1bc3119 cba8171 8039ca4 cba8171 8039ca4 cba8171 1bc3119 cba8171 8039ca4 cba8171 1bc3119 cba8171 8039ca4 1bc3119 cba8171 8039ca4 cba8171 1bc3119 8039ca4 cba8171 8039ca4 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import datetime
import pandas as pd
import streamlit as st
import timeago
st.set_page_config(layout="wide")
st.markdown(
"""
<style>
.block-container {
padding-top: 1rem;
}
#MainMenu {visibility: hidden;}
</style>
""",
unsafe_allow_html=True
)
now = datetime.datetime.now()
MATCH_RESULTS_URL = "https://huggingface.co/datasets/huggingface-projects/bot-fight-data/raw/main/soccer_history.csv"
@st.cache_data(ttl=1800)
def fetch_match_history():
"""
Fetch the match results from the last 24 hours.
Cache the result for 30min to avoid unnecessary requests.
Return a DataFrame.
"""
df = pd.read_csv(MATCH_RESULTS_URL)
df["timestamp"] = pd.to_datetime(df.timestamp, unit="s")
df = df[df["timestamp"] >= pd.Timestamp.now() - pd.Timedelta(hours=24)]
df.columns = ["home", "away", "timestamp", "result"]
return df
match_df = fetch_match_history()
def num_matches_played():
return match_df.shape[0]
teams = sorted(
list(pd.concat([match_df["home"], match_df["away"]]).unique()), key=str.casefold
)
st.title("🤗 SoccerTwos Challenge Different Metrics - Just for Fun! - Only last 24hours of games considered")
team_results = {}
for i, row in match_df.iterrows():
home_team = row["home"]
away_team = row["away"]
result = row["result"]
if home_team not in team_results:
team_results[home_team] = [0, 0, 0, 0]
if away_team not in team_results:
team_results[away_team] = [0, 0, 0, 0]
if result == 0:
team_results[home_team][2] += 1
team_results[away_team][0] += 1
team_results[home_team][3] += 1
elif result == 1:
team_results[home_team][0] += 1
team_results[away_team][2] += 1
team_results[home_team][3] += 3
else:
team_results[home_team][1] += 1
team_results[away_team][1] += 1
team_results[away_team][3] += 3
df = pd.DataFrame.from_dict(
team_results, orient="index", columns=["wins", "draws", "losses", "points"]
).sort_values(by="points", ascending=False)
df[["owner", "team"]] = df.index.to_series().str.split("/", expand=True)
df = df[["owner", "team", "wins", "draws", "losses", "points"]]
df["win_pct"] = (df["wins"] / (df["wins"] + df["draws"] + df["losses"])) * 100
stats = df
st.header("League Table")
st.dataframe(stats)
st.subheader("Match Results")
st.write("Note: Match results are not displayed in this version of the app.")
|