Change leaderboards to only follow customers
This commit is contained in:
parent
5e06f0a69b
commit
daeeac811c
3 changed files with 20 additions and 43 deletions
|
@ -51,7 +51,7 @@ sub create_new {
|
|||
} elsif ( $type eq 'monthly_total' ) {
|
||||
return $self->_create_total_set( $start, $start->clone->add( months => 1 ) );
|
||||
} elsif ( $type eq 'all_time_total' ) {
|
||||
return $self->_create_total_all_time;
|
||||
return $self->_create_total_all_time( $start );
|
||||
} elsif ( $type eq 'daily_count' ) {
|
||||
return $self->_create_count_set( $start, $start->clone->add( days => 1 ) );
|
||||
} elsif ( $type eq 'weekly_count' ) {
|
||||
|
@ -59,18 +59,23 @@ sub create_new {
|
|||
} elsif ( $type eq 'monthly_count' ) {
|
||||
return $self->_create_count_set( $start, $start->clone->add( months => 1 ) );
|
||||
} elsif ( $type eq 'all_time_count' ) {
|
||||
return $self->_create_count_all_time;
|
||||
return $self->_create_count_all_time( $start );
|
||||
}
|
||||
warn "Unrecognised type";
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub _get_customer_rs {
|
||||
my $self = shift;
|
||||
return $self->result_source->schema->resultset('User')->search({
|
||||
organisation_id => undef,
|
||||
});
|
||||
}
|
||||
|
||||
sub _create_total_set {
|
||||
my ( $self, $start, $end ) = @_;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
|
||||
my $user_rs = $schema->resultset('User');
|
||||
my $user_rs = $self->_get_customer_rs;
|
||||
|
||||
my @leaderboard;
|
||||
|
||||
|
@ -99,9 +104,7 @@ sub _create_total_set {
|
|||
sub _create_count_set {
|
||||
my ( $self, $start, $end ) = @_;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
|
||||
my $user_rs = $schema->resultset('User');
|
||||
my $user_rs = $self->_get_customer_rs;
|
||||
|
||||
my @leaderboard;
|
||||
|
||||
|
@ -128,14 +131,10 @@ sub _create_count_set {
|
|||
}
|
||||
|
||||
sub _create_total_all_time {
|
||||
my ( $self ) = @_;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
|
||||
my $user_rs = $schema->resultset('User');
|
||||
|
||||
my $end = DateTime->today;
|
||||
my ( $self, $end ) = @_;
|
||||
|
||||
my $user_rs = $self->_get_customer_rs;
|
||||
|
||||
my @leaderboard;
|
||||
|
||||
while ( my $user_result = $user_rs->next ) {
|
||||
|
@ -161,13 +160,9 @@ sub _create_total_all_time {
|
|||
}
|
||||
|
||||
sub _create_count_all_time {
|
||||
my ( $self ) = @_;
|
||||
my ( $self, $end ) = @_;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
|
||||
my $user_rs = $schema->resultset('User');
|
||||
|
||||
my $end = DateTime->today;
|
||||
my $user_rs = $self->_get_customer_rs;
|
||||
|
||||
my @leaderboard;
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ sub test_leaderboard {
|
|||
|
||||
my $today_board = $leaderboard_rs->find({ type => $name })->create_new($date)->get_latest;
|
||||
|
||||
is $today_board->values->count, 5, 'correct value count';
|
||||
is $today_board->values->count, 4, 'correct value count';
|
||||
|
||||
my $today_values = $today_board->values->search(
|
||||
{},
|
||||
|
@ -147,7 +147,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 85 },
|
||||
{ user_id => 2, value => 75 },
|
||||
{ user_id => 1, value => 65 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -160,7 +159,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 10 },
|
||||
{ user_id => 3, value => 10 },
|
||||
{ user_id => 4, value => 10 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -173,7 +171,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 185 },
|
||||
{ user_id => 2, value => 175 },
|
||||
{ user_id => 1, value => 165 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -186,7 +183,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 10 },
|
||||
{ user_id => 3, value => 10 },
|
||||
{ user_id => 4, value => 10 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -199,7 +195,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 470 },
|
||||
{ user_id => 2, value => 450 },
|
||||
{ user_id => 1, value => 430 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -212,7 +207,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 20 },
|
||||
{ user_id => 3, value => 20 },
|
||||
{ user_id => 4, value => 20 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -225,7 +219,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 940 },
|
||||
{ user_id => 2, value => 900 },
|
||||
{ user_id => 1, value => 860 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -238,7 +231,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 40 },
|
||||
{ user_id => 3, value => 40 },
|
||||
{ user_id => 4, value => 40 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -250,7 +242,7 @@ subtest 'get_latest' => sub {
|
|||
|
||||
my $today_board = $leaderboard_rs->find({ type => 'daily_total' })->get_latest;
|
||||
|
||||
is $today_board->values->count, 5, 'correct value count';
|
||||
is $today_board->values->count, 4, 'correct value count';
|
||||
|
||||
my $today_values = $today_board->values->search(
|
||||
{},
|
||||
|
@ -266,7 +258,6 @@ subtest 'get_latest' => sub {
|
|||
{ user_id => 3, value => 85 },
|
||||
{ user_id => 2, value => 75 },
|
||||
{ user_id => 1, value => 65 },
|
||||
{ user_id => 5, value => 0 },
|
||||
];
|
||||
|
||||
is_deeply [ $today_values->all ], $expected, 'array as expected';
|
||||
|
|
|
@ -125,7 +125,7 @@ sub test_leaderboard {
|
|||
|
||||
my $today_board = $leaderboard_rs->get_latest( $name );
|
||||
|
||||
is $today_board->values->count, 5, 'correct value count';
|
||||
is $today_board->values->count, 4, 'correct value count';
|
||||
|
||||
my $today_values = $today_board->values->search(
|
||||
{},
|
||||
|
@ -149,7 +149,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 85 },
|
||||
{ user_id => 2, value => 75 },
|
||||
{ user_id => 1, value => 65 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -162,7 +161,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 10 },
|
||||
{ user_id => 3, value => 10 },
|
||||
{ user_id => 4, value => 10 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -175,7 +173,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 185 },
|
||||
{ user_id => 2, value => 175 },
|
||||
{ user_id => 1, value => 165 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -188,7 +185,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 10 },
|
||||
{ user_id => 3, value => 10 },
|
||||
{ user_id => 4, value => 10 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -201,7 +197,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 470 },
|
||||
{ user_id => 2, value => 450 },
|
||||
{ user_id => 1, value => 430 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -214,7 +209,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 20 },
|
||||
{ user_id => 3, value => 20 },
|
||||
{ user_id => 4, value => 20 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -227,7 +221,6 @@ test_leaderboard(
|
|||
{ user_id => 3, value => 940 },
|
||||
{ user_id => 2, value => 900 },
|
||||
{ user_id => 1, value => 860 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -240,7 +233,6 @@ test_leaderboard(
|
|||
{ user_id => 2, value => 40 },
|
||||
{ user_id => 3, value => 40 },
|
||||
{ user_id => 4, value => 40 },
|
||||
{ user_id => 5, value => 0 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -252,7 +244,7 @@ subtest 'get_latest' => sub {
|
|||
|
||||
my $today_board = $leaderboard_rs->get_latest( 'daily_total' );
|
||||
|
||||
is $today_board->values->count, 5, 'correct value count';
|
||||
is $today_board->values->count, 4, 'correct value count';
|
||||
|
||||
my $today_values = $today_board->values->search(
|
||||
{},
|
||||
|
@ -268,7 +260,6 @@ subtest 'get_latest' => sub {
|
|||
{ user_id => 3, value => 85 },
|
||||
{ user_id => 2, value => 75 },
|
||||
{ user_id => 1, value => 65 },
|
||||
{ user_id => 5, value => 0 },
|
||||
];
|
||||
|
||||
is_deeply [ $today_values->all ], $expected, 'array as expected';
|
||||
|
|
Reference in a new issue