From 63e5a476ac895073144ca66fc14c0c4e9bc69b10 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Sun, 13 Nov 2022 22:46:08 -0500 Subject: [PATCH 1/9] Update Procfile --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 0692307..66d103e 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web gunicorn doritostats.wsgi:application --log-file - \ No newline at end of file +web gunicorn doritostats.wsgi:application --log-file \ No newline at end of file From a9f95a56010c95238aa0bfd2fd5d93dfbc34917e Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Sun, 13 Nov 2022 22:55:19 -0500 Subject: [PATCH 2/9] Update Procfile --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 66d103e..41eadcb 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web gunicorn doritostats.wsgi:application --log-file \ No newline at end of file +web: gunicorn doritostats.wsgi:application --log-file - \ No newline at end of file From fc85d1cf4e408e71ff2503e5aadf0686853675cc Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Sun, 13 Nov 2022 23:06:11 -0500 Subject: [PATCH 3/9] Create requirements.txt --- requirements.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f0d0a0d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +Django>=3.2.7 +dj-database-url>=0.5.0 +django-on-heroku>=1.1.2 +django-environ>=0.8.1 +python-dotenv>=0.21.0 +espn-api>=0.17.0 +gunicorn>=20.1.0 +joblib>=1.2.0 +numpy>=1.17.5 +pandas>=0.25.3 +psycopg2-binary>=2.9.1 +tabulate>=0.8.9 \ No newline at end of file From f743298fa3fe47fe9d963d2c1e245cb4dc61ff2b Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Sun, 13 Nov 2022 23:14:27 -0500 Subject: [PATCH 4/9] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f0d0a0d..64b31a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ joblib>=1.2.0 numpy>=1.17.5 pandas>=0.25.3 psycopg2-binary>=2.9.1 -tabulate>=0.8.9 \ No newline at end of file +tabulate>=0.8.9 +matplotlib>0.1.0 \ No newline at end of file From f3bfa084e788104adf6748039e358987f832c818 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Mon, 14 Nov 2022 20:29:00 -0500 Subject: [PATCH 5/9] fix: remove default survey values --- templates/fantasy_stats/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/fantasy_stats/index.html b/templates/fantasy_stats/index.html index 531aa90..490a895 100644 --- a/templates/fantasy_stats/index.html +++ b/templates/fantasy_stats/index.html @@ -46,13 +46,13 @@

Don't see your league? Add it manually by entering your league's details bel
{% csrf_token %}
-
+



-
+

-

+


From c853bb0b2c3644b602eef546adfe57caa330f831 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Mon, 14 Nov 2022 20:29:20 -0500 Subject: [PATCH 6/9] feat: add league name to html title --- templates/fantasy_stats/league.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/fantasy_stats/league.html b/templates/fantasy_stats/league.html index 5140312..72bbaaa 100644 --- a/templates/fantasy_stats/league.html +++ b/templates/fantasy_stats/league.html @@ -6,7 +6,7 @@ - Dorito Stats | League Stats + Dorito Stats | {{league_info.league_name}} @@ -195,4 +195,3 @@

Standings

- From 6fa1c6aa0559aa14aae11f5351c31817b62ddc4d Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Mon, 14 Nov 2022 20:29:26 -0500 Subject: [PATCH 7/9] Update requirements.txt --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 64b31a7..f0d0a0d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,4 @@ joblib>=1.2.0 numpy>=1.17.5 pandas>=0.25.3 psycopg2-binary>=2.9.1 -tabulate>=0.8.9 -matplotlib>0.1.0 \ No newline at end of file +tabulate>=0.8.9 \ No newline at end of file From 9615779ebcb049b87f990ac27ccbeb1144b1a3cd Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Mon, 14 Nov 2022 20:32:46 -0500 Subject: [PATCH 8/9] feat: add "return to home" link --- templates/fantasy_stats/league.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/fantasy_stats/league.html b/templates/fantasy_stats/league.html index 72bbaaa..1b2b419 100644 --- a/templates/fantasy_stats/league.html +++ b/templates/fantasy_stats/league.html @@ -26,7 +26,6 @@

Welcome to Dorito Stats!

{{league_info.league_name}}

League ID: {{league_info.league_id}}

League year: {{league_info.league_year}}

- {% comment %}

Week: {{page_week}}

{% endcomment %} {% comment %} Select a different week {% endcomment %}
@@ -52,6 +51,8 @@

{{league_info.league_name}}

+
+ Return to home page
From dff0438da9b59baf10c0d3f88fdf589503c132e1 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Mon, 14 Nov 2022 20:49:53 -0500 Subject: [PATCH 9/9] feat: filter leagues by year Now the main dropdown only shows leagues for the current year, while a secondary dropdown shows all historical leagues --- fantasy_stats/views.py | 118 +++++++++++++++++++---------- templates/fantasy_stats/index.html | 17 ++++- 2 files changed, 94 insertions(+), 41 deletions(-) diff --git a/fantasy_stats/views.py b/fantasy_stats/views.py index 877a0aa..aa28cf3 100644 --- a/fantasy_stats/views.py +++ b/fantasy_stats/views.py @@ -7,59 +7,99 @@ django_luck_index, django_power_rankings, django_standings, - django_weekly_stats + django_weekly_stats, ) # Create your views here. def index(request): - all_leagues = LeagueInfo.objects.order_by('-league_id', '-league_year') - return HttpResponse(render(request, 'fantasy_stats/index.html', {'all_leagues': all_leagues})) + current_year = (datetime.datetime.today() - datetime.timedelta(weeks=12)).year + leagues_current_year = ( + LeagueInfo.objects.filter(league_year=current_year) + .order_by("-league_id", "-league_year") + .distinct("league_id", "league_year") + ) + leagues_previous_year = ( + LeagueInfo.objects.filter(league_year__lt=current_year) + .order_by("-league_id", "-league_year") + .distinct("league_id", "league_year") + ) + return HttpResponse( + render( + request, + "fantasy_stats/index.html", + { + "leagues_current_year": leagues_current_year, + "leagues_previous_year": leagues_previous_year, + }, + ) + ) def league_input(request): - league_id = request.POST.get('league_id', None) - league_year = int(request.POST.get('league_year', None)) - swid = request.POST.get('swid', None) - espn_s2 = request.POST.get('espn_s2', None) + league_id = request.POST.get("league_id", None) + league_year = int(request.POST.get("league_year", None)) + swid = request.POST.get("swid", None) + espn_s2 = request.POST.get("espn_s2", None) try: - print('Checking for League {} ({}) in database...'.format( - league_id, league_year)) + print( + "Checking for League {} ({}) in database...".format(league_id, league_year) + ) league_info = LeagueInfo.objects.get( - league_id=league_id, league_year=league_year) - print('League found!') + league_id=league_id, league_year=league_year + ) + print("League found!") except LeagueInfo.DoesNotExist: - print('League {} ({}) NOT FOUND! Fetching league from ESPN...'.format( - league_id, league_year)) + print( + "League {} ({}) NOT FOUND! Fetching league from ESPN...".format( + league_id, league_year + ) + ) league = fetch_league(league_id, league_year, swid, espn_s2) - league_info = LeagueInfo(league_id=league_id, - league_year=league_year, - swid=swid, - espn_s2=espn_s2, - league_name=league.name) + league_info = LeagueInfo( + league_id=league_id, + league_year=league_year, + swid=swid, + espn_s2=espn_s2, + league_name=league.name, + ) league_info.save() - print('League {} ({}) fetched and saved to the databse.'.format( - league_id, league_year)) + print( + "League {} ({}) fetched and saved to the databse.".format( + league_id, league_year + ) + ) - return redirect('/fantasy_stats/league/{}/{}'.format(league_year, league_id, week=None)) + return redirect( + "/fantasy_stats/league/{}/{}".format(league_year, league_id, week=None) + ) def league(request, league_id, league_year, week=None): - league_info = LeagueInfo.objects.get( - league_id=league_id, league_year=league_year) - league = fetch_league(league_info.league_id, league_info.league_year, - league_info.swid, league_info.espn_s2) + league_info = LeagueInfo.objects.get(league_id=league_id, league_year=league_year) + league = fetch_league( + league_info.league_id, + league_info.league_year, + league_info.swid, + league_info.espn_s2, + ) # Set default week to display on page if week is None: - if datetime.datetime.now().strftime('%A') in ["Tuesday", "Wednesday"]: + if datetime.datetime.now().strftime("%A") in ["Tuesday", "Wednesday"]: week = league.current_week - 1 else: week = league.current_week if week == 0: - box_scores, weekly_awards, power_rankings, luck_index, standings = [], [], [], [], [] + box_scores, weekly_awards, power_rankings, luck_index, standings = ( + [], + [], + [], + [], + [], + ) else: box_scores = league.box_scores(week) @@ -69,22 +109,22 @@ def league(request, league_id, league_year, week=None): standings = django_standings(league) context = { - 'league_info': league_info, - 'league': league, - 'page_week': week, - 'box_scores': box_scores, - 'weekly_awards': weekly_awards, - 'power_rankings': power_rankings, - 'luck_index': luck_index, - 'standings': standings + "league_info": league_info, + "league": league, + "page_week": week, + "box_scores": box_scores, + "weekly_awards": weekly_awards, + "power_rankings": power_rankings, + "luck_index": luck_index, + "standings": standings, } - return HttpResponse(render(request, 'fantasy_stats/league.html', context)) + return HttpResponse(render(request, "fantasy_stats/league.html", context)) def standings(reqeust): - return HttpResponse('League still exitst') + return HttpResponse("League still exitst") def all_leagues(request): - leagues = LeagueInfo.objects.order_by('-league_id', '-league_year') - return render(request, 'fantasy_stats/all_leagues.html', {'leagues': leagues}) + leagues = LeagueInfo.objects.order_by("-league_id", "-league_year") + return render(request, "fantasy_stats/all_leagues.html", {"leagues": leagues}) diff --git a/templates/fantasy_stats/index.html b/templates/fantasy_stats/index.html index 490a895..4b3654b 100644 --- a/templates/fantasy_stats/index.html +++ b/templates/fantasy_stats/index.html @@ -24,18 +24,30 @@

Welcome to Dorito Stats!


- {# Dropdown list containing all leagues in database #} + {# Dropdown list containing all leagues in database from current year #}

Select your leage


+ + {# Dropdown list containing all leagues in database from previous years #} +
+ +

@@ -56,6 +68,7 @@

Don't see your league? Add it manually by entering your league's details bel
+

Don't know your SWID or espn_s2? (instructions for Mac / PC)