Skip to content

Commit

Permalink
added base feature class, added high roller feature, added check for …
Browse files Browse the repository at this point in the history
…updates setting, and updated report layout
  • Loading branch information
uberfastman committed Oct 4, 2024
1 parent 29fc8c6 commit 9ef11f3
Show file tree
Hide file tree
Showing 19 changed files with 1,237 additions and 1,073 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Every time you run the app it will check to see if you are using the latest vers

If you wish to update the app yourself manually, you can just type `n` to skip automatically updating, and run `git pull origin main` manually from within the application directory on the command line.

If you wish to disable the automatic check for updates, you can set `CHECK_FOR_UPDATES=False` in your `.env` file and the app will skip checking GitHub for any updates. *Please note that until you set the `CHECK_FOR_UPDATES` environment variable back to its default value of `True`, the app will **never** attempt to check for updates again.*

---

<a name="dependencies"></a>
Expand Down
42 changes: 40 additions & 2 deletions calculate/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ def get_bad_boy_data(bad_boy_results: List[BaseTeam]) -> List[List[Any]]:
for team in bad_boy_results:
ranked_team_name = team.name
ranked_team_manager = team.manager_str
ranked_bb_points = str(team.bad_boy_points)
ranked_bad_boy_points = str(team.bad_boy_points)
ranked_offense = team.worst_offense
ranked_count = str(team.num_offenders)

bad_boy_results_data.append(
[place, ranked_team_name, ranked_team_manager, ranked_bb_points, ranked_offense, ranked_count]
[place, ranked_team_name, ranked_team_manager, ranked_bad_boy_points, ranked_offense, ranked_count]
)

place += 1
Expand All @@ -375,6 +375,28 @@ def get_beef_rank_data(beef_results: List[BaseTeam]) -> List[List[Any]]:
place += 1
return beef_results_data

@staticmethod
def get_high_roller_data(high_roller_results: List[BaseTeam]) -> List[List[Any]]:
logger.debug("Creating league high roller data.")

high_roller_results_data = []
place = 1
team: BaseTeam
for team in high_roller_results:
ranked_team_name = team.name
ranked_team_manager = team.manager_str
ranked_total_fines = str(team.fines_total)
ranked_violation = team.worst_violation
ranked_violation_fine = str(team.worst_violation_fine)

high_roller_results_data.append(
[place, ranked_team_name, ranked_team_manager, ranked_total_fines, ranked_violation,
ranked_violation_fine]
)

place += 1
return high_roller_results_data

def get_ties_count(self, results_data: List[List[Any]], tie_type: str, break_ties: bool) -> int:

if tie_type == "power_ranking":
Expand Down Expand Up @@ -420,6 +442,15 @@ def get_ties_count(self, results_data: List[List[Any]], tie_type: str, break_tie
team[4],
team[5]
]
elif tie_type == "high_roller":
results_data[team_index] = [
str(place) + ("*" if group_has_ties else ""),
team[1],
team[2],
team[3],
team[4],
team[5]
]
else:
results_data[team_index] = [
str(place) + ("*" if group_has_ties else ""),
Expand All @@ -441,6 +472,13 @@ def get_ties_count(self, results_data: List[List[Any]], tie_type: str, break_tie
if len(group) > 1 and int(group[0][3]) > 0:
num_ties += sum(range(len(group)))

if tie_type == "high_roller":
groups = [list(group) for key, group in itertools.groupby(results_data, lambda x: x[3])]
num_ties = 0
for group in groups:
if len(group) > 1 and float(group[0][3]) > 0:
num_ties += sum(range(len(group)))

return num_ties

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
services:

app:
image: ghcr.io/uberfastman/fantasy-football-metrics-weekly-report:18.1.3
image: ghcr.io/uberfastman/fantasy-football-metrics-weekly-report:19.0.0
platform: linux/amd64
ports:
- "5001:5000"
Expand Down
131 changes: 82 additions & 49 deletions dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import json
from collections import defaultdict
from pathlib import Path
from typing import Set, Union, List, Dict, Any, Callable
from typing import Set, Union, List, Dict, Any, Callable, Optional

from calculate.playoff_probabilities import PlayoffProbabilities
from features.bad_boy import BadBoyFeature
from features.beef import BeefFeature
from calculate.playoff_probabilities import PlayoffProbabilities
from features.high_roller import HighRollerFeature


# noinspection GrazieInspection
Expand Down Expand Up @@ -99,7 +100,7 @@ def __init__(self, root_dir: Path, data_dir: Path, league_id: str, season: int,
self.offline: bool = offline

# attributes mapped directly from platform API data
self.name: Union[str, None] = None
self.name: Optional[str] = None
self.week: int = 0
self.start_week: int = 1
self.num_teams: int = 0
Expand All @@ -113,7 +114,7 @@ def __init__(self, root_dir: Path, data_dir: Path, league_id: str, season: int,
self.has_waiver_priorities: bool = False
self.is_faab: bool = False
self.faab_budget: int = 0
self.url: Union[str, None] = None
self.url: Optional[str] = None

# attributes calculated externally from platform API data
self.roster_positions: List[str] = []
Expand All @@ -140,8 +141,8 @@ def __init__(self, root_dir: Path, data_dir: Path, league_id: str, season: int,
self.median_standings: List[BaseTeam] = []
self.current_median_standings: List[BaseTeam] = []

self.player_data_by_week_function: Union[Callable, None] = None
self.player_data_by_week_key: Union[str, None] = None
self.player_data_by_week_function: Optional[Callable] = None
self.player_data_by_week_key: Optional[str] = None

def get_player_data_by_week(self, player_id: str, week: int = None) -> Any:
return getattr(self.player_data_by_week_function(player_id, week), self.player_data_by_week_key)
Expand Down Expand Up @@ -243,21 +244,31 @@ def get_playoff_probs(self, save_data: bool = False, playoff_prob_sims: int = No
offline=offline
)

def get_bad_boy_stats(self, save_data: bool = False, offline: bool = False, refresh: bool = False) -> BadBoyFeature:
def get_bad_boy_stats(self, refresh: bool = False, save_data: bool = False, offline: bool = False) -> BadBoyFeature:
return BadBoyFeature(
self.root_dir,
self.data_dir / str(self.season) / self.league_id,
self.root_dir,
refresh=refresh,
save_data=save_data,
offline=offline,
refresh=refresh
offline=offline
)

def get_beef_stats(self, save_data: bool = False, offline: bool = False, refresh: bool = False) -> BeefFeature:
def get_beef_stats(self, refresh: bool = False, save_data: bool = False, offline: bool = False) -> BeefFeature:
return BeefFeature(
self.data_dir / str(self.season) / self.league_id,
refresh=refresh,
save_data=save_data,
offline=offline
)

def get_high_roller_stats(self, refresh: bool = False, save_data: bool = False,
offline: bool = False) -> HighRollerFeature:
return HighRollerFeature(
self.data_dir / str(self.season) / self.league_id,
self.season,
refresh=refresh,
save_data=save_data,
offline=offline,
refresh=refresh
offline=offline
)


Expand Down Expand Up @@ -289,31 +300,43 @@ def __init__(self):
super().__init__()

self.week: int = 0
self.name: Union[str, None] = None
self.name: Optional[str] = None
self.num_moves: int = 0
self.num_trades: int = 0
self.managers: List[BaseManager] = []
self.team_id: Union[str, None] = None
self.division: Union[str, None] = None
self.team_id: Optional[str] = None
self.division: Optional[str] = None
self.points: float = 0
self.projected_points: float = 0
self.home_field_advantage_points: float = 0
self.waiver_priority: int = 0
self.faab: int = 0
self.url: Union[str, None] = None
self.url: Optional[str] = None
self.roster: List[BasePlayer] = []

# - - - - - - - - - - - -
# custom report attributes
self.manager_str: Union[str, None] = None
# v v v v v v v v v v v v

self.manager_str: Optional[str] = None
self.bench_points: float = 0
self.streak_str: Union[str, None] = None
self.division_streak_str: Union[str, None] = None
self.streak_str: Optional[str] = None
self.division_streak_str: Optional[str] = None

self.bad_boy_points: int = 0
self.worst_offense: Union[str, None] = None
self.num_offenders: int = 0
self.worst_offense: Optional[str] = None
self.worst_offense_score: int = 0
self.num_offenders: int = 0

self.total_weight: float = 0.0
self.tabbu: float = 0
self.tabbu: float = 0.0

self.fines_count: int = 0
self.fines_total: float = 0.0
self.worst_violation: Optional[str] = None
self.worst_violation_fine: float = 0.0
self.num_violators: int = 0

self.positions_filled_active: List[str] = []
self.coaching_efficiency: Union[float, str] = 0.0
self.luck: float = 0
Expand Down Expand Up @@ -580,11 +603,11 @@ class BaseManager(FantasyFootballReportObject):
def __init__(self):
super().__init__()

self.manager_id: Union[str, None] = None
self.email: Union[str, None] = None
self.name: Union[str, None] = None
self.name_str: Union[str, None] = None
self.nickname: Union[str, None] = None
self.manager_id: Optional[str] = None
self.email: Optional[str] = None
self.name: Optional[str] = None
self.name_str: Optional[str] = None
self.nickname: Optional[str] = None

def __setattr__(self, key: str, value: Any):
if key == "name":
Expand All @@ -607,46 +630,56 @@ def __init__(self):
super().__init__()

self.week_for_report: int = 0
self.player_id: Union[str, None] = None
self.player_id: Optional[str] = None
self.bye_week: int = 0
self.display_position: Union[str, None] = None
self.nfl_team_id: Union[str, None] = None
self.nfl_team_abbr: Union[str, None] = None
self.nfl_team_name: Union[str, None] = None
self.first_name: Union[str, None] = None
self.last_name: Union[str, None] = None
self.full_name: Union[str, None] = None
self.headshot_url: Union[str, None] = None
self.owner_team_id: Union[str, None] = None
self.owner_team_name: Union[str, None] = None
self.display_position: Optional[str] = None
self.nfl_team_id: Optional[str] = None
self.nfl_team_abbr: Optional[str] = None
self.nfl_team_name: Optional[str] = None
self.first_name: Optional[str] = None
self.last_name: Optional[str] = None
self.full_name: Optional[str] = None
self.headshot_url: Optional[str] = None
self.owner_team_id: Optional[str] = None
self.owner_team_name: Optional[str] = None
self.percent_owned: float = 0.0
self.points: float = 0.0
self.projected_points: float = 0.0
self.season_points: float = 0.0
self.season_projected_points: float = 0.0
self.season_average_points: float = 0.0
self.position_type: Union[str, None] = None
self.primary_position: Union[str, None] = None
self.selected_position: Union[str, None] = None
self.position_type: Optional[str] = None
self.primary_position: Optional[str] = None
self.selected_position: Optional[str] = None
self.selected_position_is_flex: bool = False
self.status: Union[str, None] = None
self.status: Optional[str] = None
self.eligible_positions: Set[str] = set()
self.stats: List[BaseStat] = []

# - - - - - - - - - - - -
# custom report attributes
self.bad_boy_crime: Union[str, None] = None
# v v v v v v v v v v v v

self.bad_boy_crime: Optional[str] = None
self.bad_boy_points: int = 0
self.bad_boy_num_offenders: int = 0
self.weight: int = 0
self.tabbu: float = 0.0

self.beef_weight: int = 0
self.beef_tabbu: float = 0.0

self.high_roller_fines_count: int = 0
self.high_roller_fines_total: float = 0.0
self.high_roller_worst_violation: Optional[str] = None
self.high_roller_worst_violation_fine: float = 0.0
self.high_roller_num_violators: int = 0


class BaseStat(FantasyFootballReportObject):

def __init__(self):
super().__init__()

self.stat_id: Union[str, None] = None
self.name: Union[str, None] = None
self.abbreviation: Union[str, None] = None
self.stat_id: Optional[str] = None
self.name: Optional[str] = None
self.abbreviation: Optional[str] = None
self.value: float = 0.0
2 changes: 1 addition & 1 deletion dao/platforms/cbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def map_data_to_base(self) -> BaseLeague:

cbs_platform = LeagueData(
root_directory,
Path(__file__).parent.parent.parent / 'data',
Path(__file__).parent.parent.parent / "output" / "data",
settings.league_id,
settings.season,
2,
Expand Down
Loading

0 comments on commit 9ef11f3

Please sign in to comment.