Skip to content

Commit

Permalink
Merge pull request #123 from DesiPilla/add-season-records
Browse files Browse the repository at this point in the history
feat: Add season records page, BuyMeACoffee
  • Loading branch information
DesiPilla authored Dec 2, 2024
2 parents 7121e94 + 3632564 commit 10e736a
Show file tree
Hide file tree
Showing 17 changed files with 1,195 additions and 428 deletions.
5 changes: 5 additions & 0 deletions fantasy_stats/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
views.simulation,
name="simulation",
),
path(
"season_stats/<int:league_year>/<int:league_id>/",
views.season_stats,
name="season_stats",
),
#
#
#
Expand Down
37 changes: 35 additions & 2 deletions fantasy_stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

from fantasy_stats.email_notifications.email import send_new_league_added_alert
from .models import LeagueInfo
from src.doritostats.analytic_utils import get_naughty_list_str, season_stats_analysis
from src.doritostats.django_utils import (
django_luck_index,
django_power_rankings,
django_simulation,
django_season_stats,
django_standings,
django_strength_of_schedule,
django_weekly_stats,
Expand All @@ -21,7 +23,6 @@
get_leagues_previous_year,
ordinal,
)
from src.doritostats.analytic_utils import get_naughty_list_str
from src.doritostats.fetch_utils import fetch_league

MIN_WEEK_TO_DISPLAY = 4 # Only run simulations after Week 4 has completed
Expand Down Expand Up @@ -325,7 +326,7 @@ def league(request, league_id: int, league_year: int, week: int = None):
"strength_of_schedule": strength_of_schedule,
"sos_weeks": schedule_period,
"standings": standings,
"scores_are_finalized": league_obj.current_week <= week,
"scores_are_finalized": league_obj.current_week > week,
}

return HttpResponse(render(request, "fantasy_stats/league.html", context))
Expand Down Expand Up @@ -425,6 +426,38 @@ def simulation(
return HttpResponse(render(request, "fantasy_stats/simulation.html", context))


def season_stats(
request,
league_id: int,
league_year: int,
):
# Fetch the league
league_info = LeagueInfo.objects.get(league_id=league_id, league_year=league_year)
league_obj = fetch_league(
league_info.league_id,
league_info.league_year,
league_info.swid,
league_info.espn_s2,
)

(
best_team_stats_list,
worst_team_stats_list,
best_position_stats_list,
worst_position_stats_list,
) = django_season_stats(league=league_obj)

context = {
"league_info": league_info,
"scores_are_finalized": league_obj.is_season_complete,
"best_team_stats": best_team_stats_list,
"worst_team_stats": worst_team_stats_list,
"best_position_stats": best_position_stats_list,
"worst_position_stats": worst_position_stats_list,
}
return HttpResponse(render(request, "fantasy_stats/season_stats.html", context))


#############################################################
## VIEWS THAT DO NOT WORK YET AND ARE IN THE TESTING PHASE ##
#############################################################
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "doritostats"
version = "3.4.22"
version = "3.5.1"
description = "This project aims to make ESPN Fantasy Football statistics easily available. With the introduction of version 3 of the ESPN's API, this structure creates leagues, teams, and player classes that allow for advanced data analytics and the potential for many new features to be added."
authors = ["Desi Pilla <[email protected]>"]
license = "https://github.com/DesiPilla/espn-api-v3/blob/master/LICENSE"
Expand Down
Loading

0 comments on commit 10e736a

Please sign in to comment.