Jon Solow commited on
Commit
b7e6b42
·
1 Parent(s): 17f905b

Add stats into scoreboard

Browse files
Files changed (1) hide show
  1. src/pages/11_Scoreboard.py +14 -12
src/pages/11_Scoreboard.py CHANGED
@@ -7,6 +7,7 @@ from shared_page import common_page_config
7
  from data_storage import get_all_users, get_all_rosters
8
  from domain.playoffs import CURRENT_PLAYOFF_WEEK, PLAYOFF_WEEK_TO_NAME
9
  from load_options import get_map_week_player_id_option, PlayerOption
 
10
 
11
 
12
  POSITION_LABELS = [
@@ -52,21 +53,21 @@ def get_roster_html_str(week: int, user_map: dict[str, PlayerOption]) -> str:
52
  for pos_label in POSITION_LABELS:
53
  week_pos_label = f"{week}-{pos_label}"
54
  player = user_map.get(week_pos_label, PlayerOption.empty_player(week=week))
55
- players_str += get_player_html_str(player)
 
56
  roster_str = f"""<ul className='user__roster'>
57
  {players_str}
58
  </ul>"""
59
  return roster_str
60
 
61
 
62
- def get_player_html_str(player_opt: PlayerOption) -> str:
63
  # TODO
64
  multiplier = 1
65
  game_status = " "
66
  score = 0
67
  game_score = " "
68
- stats: list = []
69
- player_stats = get_player_stats_html_str(stats)
70
 
71
  player_classes = "player"
72
  if player_opt.team:
@@ -92,25 +93,26 @@ def get_player_html_str(player_opt: PlayerOption) -> str:
92
  <span className='{multiplier_classes}'>{multiplier}X</span>
93
  <span className="player__game-status">{game_status}</span>
94
  <span className="player__game-score">{game_score}</span>
95
- {player_stats}
96
  </li>"""
97
 
98
  return player_str
99
 
100
 
101
- def get_stat_list_item_html_str(stat) -> str:
102
- # TODO
103
- stat_key = "TODO"
104
- stat_value = "TODO"
105
-
106
  return f"""<li className="stat">
107
  <div className="stat__key">{stat_key}</div>
108
  <div className="stat__value">{stat_value}</div>
109
  </li>"""
110
 
111
 
112
- def get_player_stats_html_str(stats_list: list) -> str:
113
- stat_items_str = "\n".join([get_stat_list_item_html_str(s) for s in stats_list])
 
 
 
 
 
114
  stats_str = f"""<ul className="player-stats">{stat_items_str}</ul>"""
115
  return stats_str
116
 
 
7
  from data_storage import get_all_users, get_all_rosters
8
  from domain.playoffs import CURRENT_PLAYOFF_WEEK, PLAYOFF_WEEK_TO_NAME
9
  from load_options import get_map_week_player_id_option, PlayerOption
10
+ from stats import get_stats_map
11
 
12
 
13
  POSITION_LABELS = [
 
53
  for pos_label in POSITION_LABELS:
54
  week_pos_label = f"{week}-{pos_label}"
55
  player = user_map.get(week_pos_label, PlayerOption.empty_player(week=week))
56
+ player_stats = get_stats_map().get(week, {}).get(player.gsis_id, {})
57
+ players_str += get_player_html_str(player, player_stats)
58
  roster_str = f"""<ul className='user__roster'>
59
  {players_str}
60
  </ul>"""
61
  return roster_str
62
 
63
 
64
+ def get_player_html_str(player_opt: PlayerOption, player_stats: dict[str, float]) -> str:
65
  # TODO
66
  multiplier = 1
67
  game_status = " "
68
  score = 0
69
  game_score = " "
70
+ player_stats_str = get_player_stats_html_str(player_stats)
 
71
 
72
  player_classes = "player"
73
  if player_opt.team:
 
93
  <span className='{multiplier_classes}'>{multiplier}X</span>
94
  <span className="player__game-status">{game_status}</span>
95
  <span className="player__game-score">{game_score}</span>
96
+ {player_stats_str}
97
  </li>"""
98
 
99
  return player_str
100
 
101
 
102
+ def get_stat_list_item_html_str(stat_key: str, stat_value: str | float) -> str:
 
 
 
 
103
  return f"""<li className="stat">
104
  <div className="stat__key">{stat_key}</div>
105
  <div className="stat__value">{stat_value}</div>
106
  </li>"""
107
 
108
 
109
+ def get_player_stats_html_str(stats_dict: dict[str, float]) -> str:
110
+ sorted_stat_tuple = list(
111
+ filter(lambda x: x[1] != 0, sorted(list(stats_dict.items()), key=lambda x: x[1], reverse=True))
112
+ )
113
+ max_stats = 4
114
+ stat_items_str = "\n".join([get_stat_list_item_html_str(s, v) for s, v in sorted_stat_tuple[:max_stats]])
115
+
116
  stats_str = f"""<ul className="player-stats">{stat_items_str}</ul>"""
117
  return stats_str
118