From c6726682d45c6a8ab424005e507bb4f68b540da2 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 14 Aug 2017 16:10:14 +0100 Subject: [PATCH] Leaderboards corrected and fixes --- lib/Pear/LocalLoop.pm | 9 +++++---- lib/Pear/LocalLoop/Command/dev_transactions.pm | 2 +- lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm | 2 +- t/api/stats.t | 10 +++++----- t/api/stats_leaderboards.t | 10 +++++----- t/schema/leaderboard.t | 6 +++--- t/schema/leaderboard_trend.t | 8 ++++---- t/schema/resultset_leaderboard.t | 8 ++++---- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index da69e23..5134e95 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -201,10 +201,11 @@ sub startup { while ( my $from_org_transaction = $from_org_transaction_rs->next ) { $to_org->create_related( 'transactions', { - buyer_id => $from_org_transaction->buyer_id, - value => $from_org_transaction->value, - proof_image => $from_org_transaction->proof_image, - submitted_at => $from_org_transaction->submitted_at, + buyer_id => $from_org_transaction->buyer_id, + value => $from_org_transaction->value, + proof_image => $from_org_transaction->proof_image, + submitted_at => $from_org_transaction->submitted_at, + purchase_time => $from_org_transaction->purchase_time, } ); $from_org_transaction->delete; diff --git a/lib/Pear/LocalLoop/Command/dev_transactions.pm b/lib/Pear/LocalLoop/Command/dev_transactions.pm index 4c8001d..ec50fb1 100644 --- a/lib/Pear/LocalLoop/Command/dev_transactions.pm +++ b/lib/Pear/LocalLoop/Command/dev_transactions.pm @@ -73,7 +73,7 @@ sub run { seller_id => $organisations[int(rand($#organisations))]->organisation_id, value => int(rand(9999)) / 100, proof_image => 'a', - submitted_at => $dtf->format_datetime($datetime->clone->add( minutes => int(rand(1440)) )), + purchase_time => $dtf->format_datetime($datetime->clone->add( minutes => int(rand(1440)) )), }); } } diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm b/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm index 4345cf4..05d264d 100644 --- a/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm +++ b/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm @@ -12,7 +12,7 @@ sub search_between { my $dtf = $self->result_source->schema->storage->datetime_parser; return $self->search({ - submitted_at => { + purchase_time => { -between => [ $dtf->format_datetime($from), $dtf->format_datetime($to), diff --git a/t/api/stats.t b/t/api/stats.t index 57ce15a..d12bcbe 100644 --- a/t/api/stats.t +++ b/t/api/stats.t @@ -73,7 +73,7 @@ for ( 11 .. 20 ) { seller_id => $org_result->id, value => $_, proof_image => 'a', - submitted_at => $dtf->format_datetime(DateTime->today()->subtract( days => 5 )), + purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 5 )), }); } @@ -82,7 +82,7 @@ for ( 21 .. 30 ) { seller_id => $org_result->id, value => $_, proof_image => 'a', - submitted_at => $dtf->format_datetime(DateTime->today()->subtract( days => 25 )), + purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 25 )), }); } @@ -91,7 +91,7 @@ for ( 31 .. 40 ) { seller_id => $org_result->id, value => $_, proof_image => 'a', - submitted_at => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), + purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), }); } @@ -100,12 +100,12 @@ for ( 41 .. 50 ) { seller_id => $org_result->id, value => $_, proof_image => 'a', - submitted_at => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), + purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )), }); } is $user_result->transactions->search({ - submitted_at => { + purchase_time => { -between => [ $dtf->format_datetime(DateTime->today()), $dtf->format_datetime(DateTime->today()->add( days => 1 )), diff --git a/t/api/stats_leaderboards.t b/t/api/stats_leaderboards.t index 11f366e..3b494ff 100644 --- a/t/api/stats_leaderboards.t +++ b/t/api/stats_leaderboards.t @@ -87,7 +87,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 9, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -104,7 +104,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 1, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -121,7 +121,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 5, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -138,7 +138,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 3, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -154,7 +154,7 @@ sub test_leaderboard { my $leaderboard_rs = $schema->resultset('Leaderboard'); $leaderboard_rs->create_new( $name, $date ); - + $t->post_ok('/api/stats/leaderboard' => json => { session_key => $session_key, type => $name } ) ->status_is(200) ->or($framework->dump_error) diff --git a/t/schema/leaderboard.t b/t/schema/leaderboard.t index d457f80..9f0e72f 100644 --- a/t/schema/leaderboard.t +++ b/t/schema/leaderboard.t @@ -90,7 +90,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 5 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 5 )), }); } @@ -99,7 +99,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 25 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 25 )), }); } @@ -108,7 +108,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 50 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 50 )), }); } diff --git a/t/schema/leaderboard_trend.t b/t/schema/leaderboard_trend.t index 593b0c2..0674e68 100644 --- a/t/schema/leaderboard_trend.t +++ b/t/schema/leaderboard_trend.t @@ -87,7 +87,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 9, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -104,7 +104,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 1, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -121,7 +121,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 5, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } @@ -138,7 +138,7 @@ my $now = DateTime->today(); seller_id => $org_result->id, value => 3, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 1 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 1 )), }); } diff --git a/t/schema/resultset_leaderboard.t b/t/schema/resultset_leaderboard.t index 77f8c4f..7245283 100644 --- a/t/schema/resultset_leaderboard.t +++ b/t/schema/resultset_leaderboard.t @@ -90,7 +90,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 5 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 5 )), }); } @@ -99,7 +99,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 25 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 25 )), }); } @@ -108,7 +108,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) { seller_id => $org_result->id, value => $_ + $tweak, proof_image => 'a', - submitted_at => $dtf->format_datetime($now->clone->subtract( days => 50 )), + purchase_time => $dtf->format_datetime($now->clone->subtract( days => 50 )), }); } @@ -122,7 +122,7 @@ sub test_leaderboard { my $leaderboard_rs = $schema->resultset('Leaderboard'); $leaderboard_rs->create_new( $name, $date ); - + my $today_board = $leaderboard_rs->get_latest( $name ); is $today_board->values->count, 4, 'correct value count';