From 4f09483f591675669aef74647adc56f3fb3a1afb Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 19 Jul 2017 17:29:00 +0100 Subject: [PATCH 1/3] Front page stat sending added --- lib/Pear/LocalLoop/Controller/Api/Stats.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index f0da881..24b859c 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 => $current_user_position, }); } From 16abfe34ea068196fe66c69eb5406d12569b27c1 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 20 Jul 2017 11:56:24 +0100 Subject: [PATCH 2/3] Fixed rank sending and added leaderboard creation script --- lib/Pear/LocalLoop/Controller/Api/Stats.pm | 2 +- make_leaderboards | 54 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 make_leaderboards diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index 24b859c..496e25d 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -53,7 +53,7 @@ sub post_index { user_count => $user_count, global_sum => $global_sum || 0, global_count => $global_count, - user_position => $current_user_position, + 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 From 5713f03cf2756d39d3cf51c86b673e5b4ff3f4e4 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 20 Jul 2017 16:41:35 +0100 Subject: [PATCH 3/3] Fix test Needed to initialise a leaderboard for monthly stats --- t/api/stats.t | 2 ++ 1 file changed, 2 insertions(+) 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)