-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c50785
commit 2fc235a
Showing
5 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 31 additions & 25 deletions
56
fbsurvivor/core/management/commands/pick_lottery_winner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
from secrets import choice | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db.models.functions import Lower | ||
|
||
from fbsurvivor.core.models import Player, Season | ||
from fbsurvivor.core.models import PlayerStatus, Season | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Pick the winner of free entry for next season" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("year", type=int) | ||
|
||
def handle(self, *args, **options): | ||
current_seasons = Season.objects.filter(is_current=True) | ||
|
||
for current_season in current_seasons: | ||
# filter out players who retired, won survivor, and me | ||
players = Player.objects.filter( | ||
playerstatus__season=current_season, | ||
playerstatus__is_retired=False, | ||
playerstatus__is_survivor=False, | ||
).exclude(username="DanTheAutomator") | ||
|
||
# filter out players who missed picks during the season | ||
ep = [ | ||
p.username | ||
for p in players | ||
if not p.pick_set.filter(team__isnull=True, week__season=current_season) | ||
and sum( | ||
p.payout_set.filter(season=current_season).values_list("amount", flat=True) | ||
) | ||
< 30 | ||
] | ||
display = "\n".join(ep) | ||
|
||
print(f"\n\n{current_season.year} Eligible Players:\n\n{display}\n\n") | ||
print(f"And the winner is... {choice(ep)}\n\n") | ||
year = options["year"] | ||
season = Season.objects.get(year=year) | ||
|
||
# filter out players who don't have full picks, have won money, and me | ||
ps = ( | ||
PlayerStatus.objects.filter( | ||
season=season, | ||
has_complete_picks=True, | ||
has_won_gt_buy_in=False, | ||
is_retired=False, | ||
) | ||
.exclude(player__username="DanTheAutomator") | ||
.annotate(lower=Lower("player__username")) | ||
.prefetch_related("player") | ||
.order_by("-win_count", "lower") | ||
) | ||
|
||
hat = [] | ||
for p in ps: | ||
hat.extend([p.player.username] * p.win_count) | ||
|
||
total = len(hat) | ||
for p in ps: | ||
print(f"{p.player}: {round(p.win_count / total * 100, 2)}%") | ||
|
||
print(f"And the winner is... {choice(hat)}\n\n") |
22 changes: 22 additions & 0 deletions
22
fbsurvivor/core/migrations/0047_playerstatus_has_complete_picks_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 5.1.3 on 2024-11-19 23:41 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0046_season_is_live"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="playerstatus", | ||
name="has_complete_picks", | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AddField( | ||
model_name="playerstatus", | ||
name="has_won_gt_buy_in", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters