-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - Show game logs on player details page (#35)
* style game logs for the player details view * show game log stats on player details page * add sticky table heading * update package version
- Loading branch information
1 parent
089f87c
commit 9685825
Showing
11 changed files
with
169 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "rel-bball-analytics" | ||
version = "1.2.2" | ||
version = "1.3.0" | ||
description = "" | ||
authors = ["Arielle Murad <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pandas as pd | ||
|
||
import rel_bball_analytics.static.py.games as styles | ||
|
||
from .utils import GAME_LOG_COLUMNS | ||
|
||
|
||
def format_game_log(game_log: pd.DataFrame): | ||
"""Returns HTML with formatted game log table to be displayed on details page""" | ||
game_log = game_log.sort_values(by=["date"]) | ||
|
||
game_log["date"] = game_log["date"].apply(format_date) | ||
game_log["result"] = game_log.apply(format_result, axis=1) | ||
game_log["opponent"] = game_log.apply(get_opponent, axis=1) | ||
|
||
game_log = game_log[GAME_LOG_COLUMNS.keys()].rename(columns=GAME_LOG_COLUMNS) | ||
|
||
return ( | ||
game_log.style.format(precision=1, na_rep="") | ||
.set_table_styles(styles.game_log_table()) | ||
.hide(axis=0) | ||
.to_html() | ||
) | ||
|
||
|
||
def format_date(date): | ||
return date.date().strftime("%Y-%m-%d") | ||
|
||
|
||
def format_result(row): | ||
result = "W" if row["team"] == row["winner"] else "L" | ||
sign = "+" if row["team"] == row["winner"] else "-" | ||
|
||
return f"{result} ({sign}{row['difference']})" | ||
|
||
|
||
def get_opponent(row): | ||
return row["home"] if row["team"] == row["away"] else row["away"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
TEXT_PRIMARY = "black" | ||
|
||
BG_LIGHT = "#D3D3D3" | ||
|
||
BORDER_PRIMARY = "2px solid black" | ||
|
||
PADDING = "12px" | ||
|
||
FONT_FAMILY = "Helvetica, sans-serif" | ||
FONT_SIZE = "14px" | ||
|
||
|
||
def game_log_table(): | ||
return [ | ||
{ | ||
"selector": "", | ||
"props": [ | ||
("border-collapse", "collapse"), | ||
("font-family", FONT_FAMILY), | ||
("font-size", FONT_SIZE), | ||
], | ||
}, | ||
{ | ||
"selector": "td", | ||
"props": [ | ||
("padding", PADDING), | ||
("text-align", "center"), | ||
("border-top", BORDER_PRIMARY), | ||
], | ||
}, | ||
{ | ||
"selector": "th", | ||
"props": [ | ||
("position", "sticky"), | ||
("top", "56px"), | ||
("background-color", "white"), | ||
], | ||
}, | ||
{ | ||
"selector": "thead th", | ||
"props": [ | ||
("font-weight", "bold"), | ||
("padding", PADDING), | ||
("text-align", "center"), | ||
], | ||
}, | ||
{ | ||
"selector": "tbody tr:hover", | ||
"props": [ | ||
("background-color", BG_LIGHT), | ||
], | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<h1 class="title mt-4">Welcome to Basketball Analytics</h1> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h1 class="mt-4 mb-2">NBA Player Search</h1> | ||
<div class="container"> | ||
<h1 class="mt-4 mb-2">NBA Player Search</h1> | ||
|
||
<form class="form-inline" method="post"> | ||
<div class="form-group"> | ||
<input type="text" name="name" placeholder="Last Name" class="form-control mr-4" required></input> | ||
<select name="season" id="season" class="form-control mr-4" required> | ||
<option value="" selected disabled>Season</option> | ||
<option value="2022">2022-23</option> | ||
<option value="2021">2021-22</option> | ||
<option value="2020">2020-21</option> | ||
<option value="2019">2019-20</option> | ||
<option value="2018">2018-19</option> | ||
<option value="2017">2017-18</option> | ||
<option value="2016">2016-17</option> | ||
<option value="2015">2015-16</option> | ||
</select> | ||
<button type="submit" class="btn btn-primary">Search</button> | ||
</div> | ||
</form> | ||
<form class="form-inline" method="post"> | ||
<div class="form-group"> | ||
<input type="text" name="name" placeholder="Last Name" class="form-control mr-4" required></input> | ||
<select name="season" id="season" class="form-control mr-4" required> | ||
<option value="" selected disabled>Season</option> | ||
<option value="2022">2022-23</option> | ||
<option value="2021">2021-22</option> | ||
<option value="2020">2020-21</option> | ||
<option value="2019">2019-20</option> | ||
<option value="2018">2018-19</option> | ||
<option value="2017">2017-18</option> | ||
<option value="2016">2016-17</option> | ||
<option value="2015">2015-16</option> | ||
</select> | ||
<button type="submit" class="btn btn-primary">Search</button> | ||
</div> | ||
</form> | ||
|
||
<div class="container mt-4"> | ||
{% block players %} {% endblock %} | ||
<div class="mt-4"> | ||
{% block players %} {% endblock %} | ||
</div> | ||
</div> | ||
{% endblock %} |