Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show number of correct picks perl player

  • Loading branch information...
commit e649840878447dda68631ed4c726df3d33dff51d 1 parent 6a16401
@mateu authored
View
4 lib/Bracket/Controller/Player.pm
@@ -68,6 +68,10 @@ sub all : Global {
# TODO: Could be turned off when games start.
my $number_of_picks_per_player = $c->model('DBIC')->count_player_picks;
$c->stash->{picks_per_player} = $number_of_picks_per_player;
+ # Count of correct picks per player
+ # TODO: Should be turned on when games start.
+ my $number_of_correct_picks_per_player = $c->model('DBIC')->count_player_picks_correct;
+ $c->stash->{correct_picks_per_player} = $number_of_correct_picks_per_player;
}
View
20 lib/Bracket/Controller/Region.pm
@@ -136,11 +136,9 @@ sub edit : Local {
# Go to home if edits are attempted after closing time
# NOTE: Put a player's id on this list and they can make edits after the cut-off.
- my @open_edit_ids = qw/ 9 13 /;
+ my @open_edit_ids = qw/ /;
my $edit_allowed = 1 if ($c->user->id eq any(@open_edit_ids));
- if (DateTime->now > edit_cutoff_time()
- && (!($c->stash->{is_admin} || $edit_allowed)))
- {
+ if ( $c->stash->{is_game_time} && (!($c->stash->{is_admin} || $edit_allowed)) ) {
$c->flash->{status_msg} = 'Regional edits are closed';
$c->response->redirect($c->uri_for($c->controller('Player')->action_for('home')));
}
@@ -174,20 +172,6 @@ sub edit : Local {
return;
}
-# This need to be edited in future years to reflect the start date/time.
-sub edit_cutoff_time {
-
- return DateTime->new(
- year => 2011,
- month => 3,
- day => 17,
- hour => 16,
- minute => 15,
- second => 0,
- );
-
-}
-
=head1 AUTHOR
mateu x hunter
View
19 lib/Bracket/Controller/Root.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use parent 'Catalyst::Controller';
use Perl6::Junction qw/ any /;
+use DateTime;
#
# Sets the actions in this controller to be registered with no prefix
@@ -70,6 +71,9 @@ sub auto : Private {
if ('admin' eq any(@user_roles)) {
$c->stash->{is_admin} = 1;
}
+
+ # Set cutoff state
+ $c->stash->{is_game_time} = (DateTime->now > edit_cutoff_time());
}
# User found, so return 1 to continue with processing after this 'auto'
@@ -120,6 +124,21 @@ Attempt to render a view, if needed.
sub end : ActionClass('RenderView') {
}
+# This needs to be edited in future years to reflect the start date/time.
+# TODO: Put into conf
+sub edit_cutoff_time {
+
+ return DateTime->new(
+ year => 2011,
+ month => 3,
+ day => 17,
+ hour => 16,
+ minute => 15,
+ second => 0,
+ );
+
+}
+
=head1 AUTHOR
root
View
36 lib/Bracket/Model/DBIC.pm
@@ -107,6 +107,42 @@ sub count_player_picks {
);
}
+=heads2 count_player_picks_correct
+
+Count up how many picks a player has made correct so far.
+Displayed on All Players home page.
+
+=cut
+
+sub count_player_picks_correct {
+ my $self = shift;
+ my $storage = $self->schema->storage;
+ return $storage->dbh_do(
+ sub {
+ my $self = shift;
+ my $dbh = shift;
+ my $sth = $dbh->prepare('
+ select player_picks.player, count(*)
+ from picks player_picks, picks perfect_picks, game game, team team
+ where perfect_picks.pick = player_picks.pick
+ and perfect_picks.game = player_picks.game
+ and player_picks.game = game.id
+ and player_picks.pick = team.id
+ and perfect_picks.player = 1
+ group by player_picks.player
+ ;'
+ );
+ $sth->execute() or die $sth->errstr;
+ my $picks_per_player = {};
+ my $result = $sth->fetchall_arrayref;
+ foreach my $row (@{$result}) {
+ $picks_per_player->{$row->[0]} = $row->[1];
+ }
+ return $picks_per_player;
+ }
+ );
+}
+
=heads2 count_final4_picks
Count up how many picks a player has made in the final 4 (3 total).
View
22 root/player/all_home.tt
@@ -35,16 +35,18 @@
</td>
<td style="font-size: 0.72em;">
<span class="separator"> | </span>
- [%
- SET player_id = player.id;
- SET picks_made = picks_per_player.$player_id || 0;
- %]
- [% IF picks_made < 63;
- '<span style="color:sienna;">' _ picks_made _ '/63 picked</span>';
- ELSE %]
- <span style="color:darkgreen;">complete</span>
- [% END %]
-
+ [% SET player_id = player.id %]
+ [% IF !is_game_time %]
+ [% SET picks_made = picks_per_player.$player_id || 0 %]
+ [% IF picks_made < 63;
+ '<span style="color:sienna;">' _ picks_made _ '/63 picked</span>';
+ ELSE %]
+ <span style="color:darkgreen;">complete</span>
+ [% END %]
+ [% ELSE %]
+ [% SET picks_correct = correct_picks_per_player.$player_id || 0 %]
+ <span style="color:darkgreen;">[% picks_correct %] correct</span>
+ [% END %]
</td>
</tr>
Please sign in to comment.
Something went wrong with that request. Please try again.