Spaces:
No application file
No application file
hectorjelly
commited on
Commit
·
1bc3119
1
Parent(s):
8039ca4
Update app.py
Browse files
app.py
CHANGED
@@ -23,12 +23,13 @@ MATCH_RESULTS_URL = "https://huggingface.co/datasets/huggingface-projects/bot-fi
|
|
23 |
@st.cache_data(ttl=1800)
|
24 |
def fetch_match_history():
|
25 |
"""
|
26 |
-
Fetch match
|
27 |
Cache the result for 30min to avoid unnecessary requests.
|
28 |
Return a DataFrame.
|
29 |
"""
|
30 |
df = pd.read_csv(MATCH_RESULTS_URL)
|
31 |
df["timestamp"] = pd.to_datetime(df.timestamp, unit="s")
|
|
|
32 |
df.columns = ["home", "away", "timestamp", "result"]
|
33 |
return df
|
34 |
|
@@ -42,7 +43,7 @@ teams = sorted(
|
|
42 |
list(pd.concat([match_df["home"], match_df["away"]]).unique()), key=str.casefold
|
43 |
)
|
44 |
|
45 |
-
st.title("🤗 SoccerTwos Challenge
|
46 |
|
47 |
team_results = {}
|
48 |
for i, row in match_df.iterrows():
|
@@ -59,7 +60,7 @@ for i, row in match_df.iterrows():
|
|
59 |
if result == 0:
|
60 |
team_results[home_team][2] += 1
|
61 |
team_results[away_team][0] += 1
|
62 |
-
team_results[home_team][3] +=
|
63 |
elif result == 1:
|
64 |
team_results[home_team][0] += 1
|
65 |
team_results[away_team][2] += 1
|
@@ -67,18 +68,16 @@ for i, row in match_df.iterrows():
|
|
67 |
else:
|
68 |
team_results[home_team][1] += 1
|
69 |
team_results[away_team][1] += 1
|
70 |
-
team_results[
|
71 |
-
team_results[away_team][3] += 1
|
72 |
-
|
73 |
|
74 |
df = pd.DataFrame.from_dict(
|
75 |
team_results, orient="index", columns=["wins", "draws", "losses", "points"]
|
76 |
-
).
|
77 |
df[["owner", "team"]] = df.index.to_series().str.split("/", expand=True)
|
78 |
df = df[["owner", "team", "wins", "draws", "losses", "points"]]
|
79 |
df["win_pct"] = (df["wins"] / (df["wins"] + df["draws"] + df["losses"])) * 100
|
80 |
|
81 |
-
stats = df
|
82 |
|
83 |
st.header("League Table")
|
84 |
st.dataframe(stats)
|
|
|
23 |
@st.cache_data(ttl=1800)
|
24 |
def fetch_match_history():
|
25 |
"""
|
26 |
+
Fetch the match results from the last 24 hours.
|
27 |
Cache the result for 30min to avoid unnecessary requests.
|
28 |
Return a DataFrame.
|
29 |
"""
|
30 |
df = pd.read_csv(MATCH_RESULTS_URL)
|
31 |
df["timestamp"] = pd.to_datetime(df.timestamp, unit="s")
|
32 |
+
df = df[df["timestamp"] >= pd.Timestamp.now() - pd.Timedelta(hours=24)]
|
33 |
df.columns = ["home", "away", "timestamp", "result"]
|
34 |
return df
|
35 |
|
|
|
43 |
list(pd.concat([match_df["home"], match_df["away"]]).unique()), key=str.casefold
|
44 |
)
|
45 |
|
46 |
+
st.title("🤗 SoccerTwos Challenge Different Metrics - Just for Fun! - Only last 24hours of games considered")
|
47 |
|
48 |
team_results = {}
|
49 |
for i, row in match_df.iterrows():
|
|
|
60 |
if result == 0:
|
61 |
team_results[home_team][2] += 1
|
62 |
team_results[away_team][0] += 1
|
63 |
+
team_results[home_team][3] += 1
|
64 |
elif result == 1:
|
65 |
team_results[home_team][0] += 1
|
66 |
team_results[away_team][2] += 1
|
|
|
68 |
else:
|
69 |
team_results[home_team][1] += 1
|
70 |
team_results[away_team][1] += 1
|
71 |
+
team_results[away_team][3] += 3
|
|
|
|
|
72 |
|
73 |
df = pd.DataFrame.from_dict(
|
74 |
team_results, orient="index", columns=["wins", "draws", "losses", "points"]
|
75 |
+
).sort_values(by="points", ascending=False)
|
76 |
df[["owner", "team"]] = df.index.to_series().str.split("/", expand=True)
|
77 |
df = df[["owner", "team", "wins", "draws", "losses", "points"]]
|
78 |
df["win_pct"] = (df["wins"] / (df["wins"] + df["draws"] + df["losses"])) * 100
|
79 |
|
80 |
+
stats = df
|
81 |
|
82 |
st.header("League Table")
|
83 |
st.dataframe(stats)
|