Beispiel #1
0
 def players(self) -> Dict[str, int]:
     sleepers_players_cache = Path("cache/football/sleepers-players.p")
     response = load_from_cache(
         sleepers_players_cache,
         lambda: self._get(_nfl_players_url()).json())
     player_ids = dict()
     for sleeper_id, player_json in response.items():
         if player_json["position"] not in ["QB", "TE", "WR", "RB", "DEF"]:
             continue
         name = player_json["first_name"] + " " + player_json["last_name"]
         player_ids[name] = sleeper_id
     return player_ids
Beispiel #2
0
def rank_all_players(last_year: FootballApi, football: FootballApi,
                     fantasy_pros: FantasyProsApi) -> List[Player]:
    avg_count_cache = Path(
        f"cache/football/roster-count-{last_year.league_id}-{last_year.year}.p"
    )
    avg_count = load_from_cache(avg_count_cache,
                                lambda: roster_count_of_all_lineups(last_year))
    # avg_count = {
    #     FootballPosition.QUARTER_BACK: 1.2,
    #     FootballPosition.RUNNING_BACK: 6.0,
    #     FootballPosition.WIDE_RECEIVER: 6.0,
    #     FootballPosition.TIGHT_END: 1.2,
    #     FootballPosition.DEFENSE: 1.0
    # }
    replacement_rank = replacement_level(avg_count, 10)
    projections = projections_by_player(football, fantasy_pros)

    ranked_by_pos = ranked_by_position(projections)
    replacement_values = replacement_level_points(replacement_rank,
                                                  ranked_by_pos)

    values = _player_values(projections, replacement_values)

    sorted_by_value = sorted(values.items(),
                             key=lambda tup: tup[1],
                             reverse=True)

    LOGGER.info("RNK PRNK PLAYER                   VALUE POINTS")
    for rank, (player, value) in list(enumerate(sorted_by_value))[:200]:
        # if player.default_position != FootballPosition.WIDE_RECEIVER:
        #     continue
        position_rankings = enumerate(
            map(lambda tup: tup[0], ranked_by_pos[player.default_position]))
        player_rank_at_position = (
            next(p_rank
                 for (p_rank, p) in position_rankings if p == player) + 1)
        value_bars = int(int(floor(value)) / 10)
        value_str = "|" * value_bars
        LOGGER.info(
            f"{rank + 1:<3} {player.default_position}{player_rank_at_position:<2} {player.name:<24} {value:5.1f} {projections[player]:5.1f} {value_str}"
        )
    return list(map(lambda tup: tup[0], sorted_by_value))
Beispiel #3
0
def _cached_projections_by_name(fantasy_pros: FantasyProsApi):
    today = date.today()
    date_string = str(today)
    return load_from_cache(Path(f"cache/fp-proj-{date_string}.p"),
                           fantasy_pros.week_football_projections)
Beispiel #4
0
def _players_by_name(football: FootballApi):
    players = load_from_cache(
        Path(f"cache/football/players-{football.year}.p"),
        football.all_players_sorted)
    players_by_name = {p.name: p for p in players}
    return players_by_name
Beispiel #5
0
 def _token(self):
     token_cache = Path("cache/football/sleeper-token.p")
     return load_from_cache(token_cache,
                            lambda: self._login()["login"]["token"])