-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: use dynamic region IDs in scoring #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -169,6 +169,8 @@ sub _update_points_portable { | |||||||
| my %times; | ||||||||
| my $current_time = time(); | ||||||||
| my $previous_time = $current_time; | ||||||||
| my @region_ids = _region_ids_for_schema($schema); | ||||||||
|
||||||||
| my @region_ids = _region_ids_for_schema($schema); | |
| my @region_ids = _region_ids_for_schema($schema); | |
| @region_ids = (1 .. 4) unless @region_ids; |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
count_region_picks now initializes its result map from Region rows; if there are no Region rows, it will return an empty hashref, which makes callers that iterate expected region IDs see undef instead of 0. Consider applying the same empty-region fallback here (e.g., (1..4)) so the return shape stays stable even when the Region table is empty.
| my @region_ids = _region_ids_for_schema($self->schema); | |
| my @region_ids = _region_ids_for_schema($self->schema); | |
| @region_ids = (1 .. 4) unless @region_ids; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| use strict; | ||
| use warnings; | ||
|
|
||
| use Test::More; | ||
|
|
||
| use lib qw(lib t/lib); | ||
| use BracketTestSchema; | ||
| use Bracket::Model::DBIC; | ||
|
|
||
| { | ||
| package TestDBICModel; | ||
| sub new { my ($class, $schema) = @_; return bless { schema => $schema }, $class; } | ||
| sub schema { return $_[0]->{schema}; } | ||
| } | ||
|
|
||
| my $schema = BracketTestSchema->init_schema(populate => 1); | ||
|
|
||
| $schema->resultset('Region')->create({ | ||
| id => 5, | ||
| name => 'Wildcard', | ||
| }); | ||
| $schema->resultset('Team')->create({ | ||
| id => 500, | ||
| seed => 1, | ||
| name => 'Wildcard Team', | ||
| region => 5, | ||
| round_out => 7, | ||
| }); | ||
| $schema->resultset('Game')->create({ | ||
| id => 500, | ||
| winner => undef, | ||
| round => 1, | ||
| lower_seed => 0, | ||
| }); | ||
|
|
||
| my $player = $schema->resultset('Player')->create({ | ||
| email => 'dynamic-region-counts@example.com', | ||
| password => 'secret', | ||
| first_name => 'Dynamic', | ||
| last_name => 'Region', | ||
| }); | ||
|
|
||
| $schema->resultset('Pick')->create({ | ||
| player => $player->id, | ||
| game => 500, | ||
| pick => 500, | ||
| }); | ||
|
|
||
| my $model = TestDBICModel->new($schema); | ||
| my $counts = Bracket::Model::DBIC::count_region_picks($model, $player->id); | ||
|
|
||
| ok(exists $counts->{5}, 'count map includes dynamically added region'); | ||
| is($counts->{5}, 1, 'count map includes picks from dynamically added region'); | ||
|
|
||
| for my $region_id (1 .. 4) { | ||
| is($counts->{$region_id}, 0, "existing region $region_id defaults to zero when no picks exist"); | ||
| } | ||
|
|
||
| done_testing(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@region_idsis derived purely from the Region table; if that table is empty, this action will skip the per-region loop entirely and won't create/update any RegionScore rows. Consider adding the same fallback used in incomplete_submissions (e.g., default to 1..4 when no Region rows exist) so admin score refresh remains consistent on a fresh/partially populated DB.