From 25511ced69e664a5a759f8bc58d5a12efd770772 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Fri, 15 Sep 2017 12:54:36 +0100 Subject: [PATCH] Fix calculation mistake on leadearboard display --- lib/Pear/LocalLoop/Controller/Api/Stats.pm | 7 ++++++- t/api/stats_leaderboards.t | 16 ++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index ddb5152..d909fad 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -92,7 +92,12 @@ sub post_leaderboards { my @leaderboard_array = $today_values->all; if ( $validation->param('type') =~ /total$/ ) { - map { $_->{value} / 100000 } @leaderboard_array; + @leaderboard_array = (map { + { + %$_, + value => $_->{value} / 100000, + } + } @leaderboard_array); } my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id }); diff --git a/t/api/stats_leaderboards.t b/t/api/stats_leaderboards.t index 84eb331..95b71b1 100644 --- a/t/api/stats_leaderboards.t +++ b/t/api/stats_leaderboards.t @@ -80,13 +80,13 @@ my $now = DateTime->today(); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 1, + value => 100000, proof_image => 'a', }); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 9, + value => 900000, proof_image => 'a', purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); @@ -97,13 +97,13 @@ my $now = DateTime->today(); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 3, + value => 300000, proof_image => 'a', }); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 1, + value => 100000, proof_image => 'a', purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); @@ -114,13 +114,13 @@ my $now = DateTime->today(); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 5, + value => 500000, proof_image => 'a', }); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 5, + value => 500000, proof_image => 'a', purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); @@ -131,13 +131,13 @@ my $now = DateTime->today(); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 9, + value => 900000, proof_image => 'a', }); $user_result->create_related( 'purchases', { seller_id => $org_result->id, - value => 3, + value => 300000, proof_image => 'a', purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), });