Add command to create leaderboards
This commit is contained in:
parent
1642b27c23
commit
e2a56227c8
2 changed files with 75 additions and 0 deletions
|
@ -30,6 +30,8 @@ sub startup {
|
||||||
});
|
});
|
||||||
my $config = $self->config;
|
my $config = $self->config;
|
||||||
|
|
||||||
|
push @{ $self->commands->namespaces }, __PACKAGE__ . '::Command';
|
||||||
|
|
||||||
$self->plugin('Pear::LocalLoop::Plugin::Validators');
|
$self->plugin('Pear::LocalLoop::Plugin::Validators');
|
||||||
|
|
||||||
$self->plugin('Authentication' => {
|
$self->plugin('Authentication' => {
|
||||||
|
|
73
lib/Pear/LocalLoop/Command/leaderboard.pm
Normal file
73
lib/Pear/LocalLoop/Command/leaderboard.pm
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
package Pear::LocalLoop::Command::leaderboard;
|
||||||
|
use Mojo::Base 'Mojolicious::Command';
|
||||||
|
|
||||||
|
use Mojo::Util 'getopt';
|
||||||
|
|
||||||
|
has description => 'Build leaderboards';
|
||||||
|
|
||||||
|
has usage => sub { shift->extract_usage };
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ( $self, @args ) = @_;
|
||||||
|
|
||||||
|
getopt \@args,
|
||||||
|
't|type=s' => \my $type,
|
||||||
|
'l|list' => \my $list,
|
||||||
|
'd|date=s' => \my $date;
|
||||||
|
|
||||||
|
my $leaderboard_rs = $self->app->schema->resultset('Leaderboard');
|
||||||
|
|
||||||
|
if ( defined $list ) {
|
||||||
|
say sprintf('%20s : %20s', 'Type', 'Name');
|
||||||
|
for my $leaderboard ( $leaderboard_rs->all ) {
|
||||||
|
say sprintf('%20s : %20s', $leaderboard->type, $leaderboard->name);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( defined $type ) {
|
||||||
|
my $leaderboard = $leaderboard_rs->find({ type => $type });
|
||||||
|
|
||||||
|
unless ( defined $leaderboard ) {
|
||||||
|
say "Unknown Leaderboard Type";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( defined $date ) {
|
||||||
|
say "Creating leaderboard of type $type with date $date";
|
||||||
|
|
||||||
|
my $date_formatter = DateTime::Format::Strptime->new(
|
||||||
|
pattern => '%Y-%m-%d'
|
||||||
|
);
|
||||||
|
|
||||||
|
my $datetime = $date_formatter->parse_datetime($date);
|
||||||
|
|
||||||
|
unless ( defined $datetime ) {
|
||||||
|
say "Unrecognised date format, please use 'YYYY-MM-DD' Format";
|
||||||
|
}
|
||||||
|
|
||||||
|
$leaderboard->create_new($datetime);
|
||||||
|
|
||||||
|
say "Done";
|
||||||
|
} else {
|
||||||
|
say 'Leaderboards of type ' . $type . ' available:';
|
||||||
|
for my $set ( $leaderboard->sets->all ) {
|
||||||
|
say $set->date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
Usage: APPLICATION leaderboard [OPTIONS]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-l, --list List all leaderboard types
|
||||||
|
-t, --type Leaderboard type to create
|
||||||
|
-d, --date Start Date (in YYYY-MM-DD format)
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
1;
|
Reference in a new issue