From fb60ba4c0fe2c106e227c3399d37081d450835e6 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 20 Mar 2018 19:24:04 +0000 Subject: [PATCH 1/4] Amended changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f712caa..64eafb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ # Next Release +# v0.10.6 + +* Fixed organisation submission +* Changed category listing code +* Made transaction upload code more lenient +* Added API ability to edit and delete transactions +* Added test for above +* Made test dumping more sane + # v0.10.5 * **Admin Feature** Removed generic Transaction List, replaced with a new From 6527d1e36c36581eef2a12900694a36c3faeecbe Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 21 Mar 2018 15:52:00 +0000 Subject: [PATCH 2/4] fixed category list on postgres --- CHANGELOG.md | 1 + .../LocalLoop/Controller/Api/Categories.pm | 4 ++-- .../ViewQuantisedTransactionCategoryPg.pm | 22 +++++++++--------- .../ViewQuantisedTransactionCategorySQLite.pm | 2 +- t/api/categories.t | 23 +++++++++---------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64eafb4..f51a1fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Added API ability to edit and delete transactions * Added test for above * Made test dumping more sane +* Fixed category view on postgres # v0.10.5 diff --git a/lib/Pear/LocalLoop/Controller/Api/Categories.pm b/lib/Pear/LocalLoop/Controller/Api/Categories.pm index 95f9db5..ed5b0c1 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Categories.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Categories.pm @@ -31,9 +31,9 @@ sub post_category_list { value => { sum => 'value' }, category_id => 'category_id', essential => 'essential', - } + }, ], - group_by => [ qw/ category_id quantised_weeks / ], + group_by => [ qw/ category_id quantised_weeks essential value / ], order_by => { '-desc' => 'value' }, } ); diff --git a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategoryPg.pm b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategoryPg.pm index b288c65..0d2739b 100644 --- a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategoryPg.pm +++ b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategoryPg.pm @@ -10,18 +10,18 @@ __PACKAGE__->table('view_quantised_transactions'); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition( qq/ -SELECT "transactions.value", - "transactions.distance", - "transactions.purchase_time", - "transactions.buyer_id", - "transactions.seller_id", - "transactions.essential", - "transaction_category.category_id", - DATE_TRUNC('hour', "transactions.purchase_time") AS "quantised_hours", - DATE_TRUNC('day', "transactions.purchase_time") AS "quantised_days", - DATE_TRUNC('week', "transactions.purchase_time") AS "quantised_weeks" +SELECT "transactions"."value", + "transactions"."distance", + "transactions"."purchase_time", + "transactions"."buyer_id", + "transactions"."seller_id", + "transactions"."essential", + "transaction_category"."category_id", + DATE_TRUNC('hour', "transactions"."purchase_time") AS "quantised_hours", + DATE_TRUNC('day', "transactions"."purchase_time") AS "quantised_days", + DATE_TRUNC('week', "transactions"."purchase_time") AS "quantised_weeks" FROM "transactions" -LEFT JOIN "transaction_category" ON "transactions.id" = "transaction_category.transaction_id" +LEFT JOIN "transaction_category" ON "transactions"."id" = "transaction_category"."transaction_id" /); 1; diff --git a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategorySQLite.pm b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategorySQLite.pm index 7992458..958ea59 100644 --- a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategorySQLite.pm +++ b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionCategorySQLite.pm @@ -19,7 +19,7 @@ SELECT "transactions"."value", "transaction_category"."category_id", DATETIME(STRFTIME('%Y-%m-%d %H:00:00',"transactions"."purchase_time")) AS "quantised_hours", DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time")) AS "quantised_days", - DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time", 'weekday 1')) AS "quantised_weeks" + DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time", 'weekday 0','-6 days')) AS "quantised_weeks" FROM "transactions" LEFT JOIN "transaction_category" ON "transactions"."id" = "transaction_category"."transaction_id" /); diff --git a/t/api/categories.t b/t/api/categories.t index 0f48620..10d11ab 100644 --- a/t/api/categories.t +++ b/t/api/categories.t @@ -19,6 +19,11 @@ $framework->install_fixtures('users'); my $t = $framework->framework; my $schema = $t->app->schema; +$schema->resultset('Category')->create({ + id => 1, + name => 'test', +}); + set_absolute_time('2017-01-02T00:00:00Z'); my $start = DateTime->today->subtract( hours => 12 ); @@ -52,7 +57,7 @@ $t->post_ok('/api/stats/category' => json => { categories => { "2016-12-05" => [{ days => "2016-12-05", - value => 30, + value => 210, category => 1, }], "2016-12-12" => [{ @@ -62,7 +67,7 @@ $t->post_ok('/api/stats/category' => json => { }], "2016-12-19" => [{ days => "2016-12-19", - value => 220, + value => 210, category => 1, }], "2016-12-26" => [{ @@ -70,28 +75,20 @@ $t->post_ok('/api/stats/category' => json => { value => 190, category => 1, }], - "2017-01-02" => [{ - days => "2017-01-02", - value => 170, - category => 1, - }], }, essentials => { "2016-12-05" => { - value => 30, + value => 210, }, "2016-12-12" => { value => 200, }, "2016-12-19" => { - value => 220, + value => 210, }, "2016-12-26" => { value => 190, }, - "2017-01-02" => { - value => 170, - }, } })->or($framework->dump_error); @@ -99,6 +96,7 @@ sub create_random_transaction { my $buyer = shift; my $time = shift; + my $buyer_result = $schema->resultset('User')->find({ email => $buyer })->entity; my $seller_result = $schema->resultset('Organisation')->find({ name => 'Test Org' })->entity; my $test_transaction = $schema->resultset('Transaction')->create({ @@ -109,6 +107,7 @@ sub create_random_transaction { purchase_time => $time, essential => 1, }); + $schema->resultset('TransactionCategory')->create({ category_id => 1, transaction_id => $test_transaction->id, From c5341af3e756416fcfcbdea0bb2acaddbf860484 Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 21 Mar 2018 16:01:46 +0000 Subject: [PATCH 3/4] customer stats test fixed --- .../Schema/Result/ViewQuantisedTransactionSQLite.pm | 2 +- t/api/stats.t | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm index abf95dd..1c908fd 100644 --- a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm +++ b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm @@ -17,7 +17,7 @@ SELECT "value", "seller_id", DATETIME(STRFTIME('%Y-%m-%d %H:00:00',"purchase_time")) AS "quantised_hours", DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"purchase_time")) AS "quantised_days", - DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"purchase_time", 'weekday 1')) AS "quantised_weeks" + DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"purchase_time",'weekday 0','-6 days')) AS "quantised_weeks" FROM "transactions" /); diff --git a/t/api/stats.t b/t/api/stats.t index 67e8705..2fa8a9a 100644 --- a/t/api/stats.t +++ b/t/api/stats.t @@ -49,11 +49,11 @@ $t->post_ok('/api/stats/customer' => json => { }) ->status_is(200)->or($framework->dump_error) ->json_is('/weeks', { - first => 2, - second => 21, + first => 20, + second => 20, max => 22, sum => 118, - count => 7, + count => 6, }) ->or($framework->dump_error) ->json_is('/sectors', { From 055b95e2fcc17a3cb8fde5a4deae48485eec8dfc Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 21 Mar 2018 16:37:40 +0000 Subject: [PATCH 4/4] customer snippet test amended --- CHANGELOG.md | 3 ++- t/api/v1/customer/snippets.t | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f51a1fa..fb8bb99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ * Added API ability to edit and delete transactions * Added test for above * Made test dumping more sane -* Fixed category view on postgres +* Fixed quantised transaction calcuations for weeks on sqlite +* Amended customer snippet, category list and customer stats tests # v0.10.5 diff --git a/t/api/v1/customer/snippets.t b/t/api/v1/customer/snippets.t index 4a3ae8c..07c3e9a 100644 --- a/t/api/v1/customer/snippets.t +++ b/t/api/v1/customer/snippets.t @@ -1,5 +1,9 @@ use Mojo::Base -strict; +BEGIN { + use Test::MockTime qw/ set_absolute_time /; +} + use FindBin qw/ $Bin /; use Test::More; @@ -15,7 +19,7 @@ $framework->install_fixtures('users'); my $t = $framework->framework; my $schema = $t->app->schema; -$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) ); +set_absolute_time('2017-01-02T00:00:00Z'); my $start = DateTime->today->subtract( hours => 12 ); @@ -25,15 +29,19 @@ for my $count ( 0 .. 60 ) { create_random_transaction( 'test1@example.com', $trans_day ); if ( $count % 2 ) { - create_random_transaction( 'test2@example.com', $trans_day ); + create_random_transaction( 'test1@example.com', $trans_day ); } if ( $count % 3 ) { - create_random_transaction( 'test3@example.com', $trans_day ); + create_random_transaction( 'test1@example.com', $trans_day ); } if ( $count % 4 ) { - create_random_transaction( 'test4@example.com', $trans_day ); + create_random_transaction( 'test1@example.com', $trans_day ); } } +my $lb_start = $start->clone->truncate( to => 'month' )->subtract( months => 1); + +#use Devel::Dwarn; Dwarn({ $_->get_columns }) for $schema->resultset('Transaction')->all; +$schema->resultset('Leaderboard')->create_new( 'monthly_total', $lb_start ); my $session_key = $framework->login({ email => 'test1@example.com', @@ -45,7 +53,7 @@ $t->post_ok('/api/v1/customer/snippets' => json => { }) ->status_is(200)->or($framework->dump_error) ->json_is('/snippets', { - user_sum => 610, + user_sum => 1760, user_position => 1, });