diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index f0da881..496e25d 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -37,6 +37,10 @@ sub post_index { my $global_sum = $global_rs->get_column('value')->sum; my $global_count = $global_rs->count; + my $leaderboard_rs = $c->schema->resultset('Leaderboard'); + my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' ); + my $current_user_position = $monthly_board->values->find({ user_id => $c->stash->{api_user}->id }); + return $c->render( json => { success => Mojo::JSON->true, today_sum => $today_sum || 0, @@ -49,6 +53,7 @@ sub post_index { user_count => $user_count, global_sum => $global_sum || 0, global_count => $global_count, + user_position => defined $current_user_position ? $current_user_position->position : 0, }); } diff --git a/make_leaderboards b/make_leaderboards new file mode 100644 index 0000000..81b8abe --- /dev/null +++ b/make_leaderboards @@ -0,0 +1,54 @@ +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-01 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-02 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-03 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-04 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-05 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-06 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-07 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-08 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-09 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-10 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-11 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-12 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-13 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-14 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-15 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-16 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-17 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-18 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-19 +./script/pear-local_loop leaderboard -t daily_total -d 2017-07-20 + +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-01 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-02 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-03 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-04 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-05 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-06 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-07 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-08 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-09 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-10 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-11 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-12 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-13 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-14 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-15 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-16 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-17 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-18 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-19 +./script/pear-local_loop leaderboard -t daily_count -d 2017-07-20 + +./script/pear-local_loop leaderboard -t weekly_count -d 2017-07-03 +./script/pear-local_loop leaderboard -t weekly_count -d 2017-07-10 +./script/pear-local_loop leaderboard -t weekly_total -d 2017-07-03 +./script/pear-local_loop leaderboard -t weekly_total -d 2017-07-10 + +./script/pear-local_loop leaderboard -t monthly_total -d 2017-05-01 +./script/pear-local_loop leaderboard -t monthly_total -d 2017-06-01 +./script/pear-local_loop leaderboard -t monthly_count -d 2017-05-01 +./script/pear-local_loop leaderboard -t monthly_count -d 2017-06-01 + +./script/pear-local_loop leaderboard -t all_time_total -d 2017-07-13 +./script/pear-local_loop leaderboard -t all_time_count -d 2017-07-13 diff --git a/t/api/stats.t b/t/api/stats.t index 7468795..57ce15a 100644 --- a/t/api/stats.t +++ b/t/api/stats.t @@ -44,6 +44,8 @@ my $session_key = $framework->login({ password => $user->{password}, }); +$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) ); + $t->post_ok('/api/stats' => json => { session_key => $session_key } ) ->status_is(200) ->json_is('/success', Mojo::JSON->true)