sectors code added
This commit is contained in:
parent
229c2bb801
commit
74a1b3d238
4 changed files with 26 additions and 3 deletions
|
@ -15,7 +15,7 @@ has error_messages => sub {
|
|||
sub post_index {
|
||||
my $c = shift;
|
||||
|
||||
my $user = $c->stash->{api_user}->entity;
|
||||
my $entity = $c->stash->{api_user}->entity;
|
||||
|
||||
my $duration = DateTime::Duration->new( weeks => 7 );
|
||||
my $end = DateTime->today;
|
||||
|
@ -26,7 +26,7 @@ sub post_index {
|
|||
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||
my $transaction_rs = $c->schema->resultset('ViewQuantisedTransaction' . $driver)->search(
|
||||
my $week_transaction_rs = $c->schema->resultset('ViewQuantisedTransaction' . $driver)->search(
|
||||
{
|
||||
purchase_time => {
|
||||
-between => [
|
||||
|
@ -34,6 +34,7 @@ sub post_index {
|
|||
$dtf->format_datetime($end),
|
||||
],
|
||||
},
|
||||
buyer_id => $entity->id,
|
||||
},
|
||||
{
|
||||
columns => [
|
||||
|
@ -47,10 +48,27 @@ sub post_index {
|
|||
}
|
||||
);
|
||||
|
||||
for ( $transaction_rs->all ) {
|
||||
for ( $week_transaction_rs->all ) {
|
||||
push @{ $weeks->{ purchases } }, ($_->get_column('count') || 0);
|
||||
}
|
||||
|
||||
my $sector_purchase_rs = $entity->purchases->search({},
|
||||
{
|
||||
join => { 'seller' => 'organisation' },
|
||||
columns => {
|
||||
sector => "organisation.sector",
|
||||
count => \"COUNT(*)",
|
||||
},
|
||||
group_by => "organisation.sector",
|
||||
order_by => { '-desc' => "COUNT(*)" },
|
||||
}
|
||||
);
|
||||
|
||||
for ( $sector_purchase_rs->all ) {
|
||||
push @{ $sectors->{ sectors } }, $_->get_column('sector');
|
||||
push @{ $sectors->{ purchases } }, ($_->get_column('count') || 0);
|
||||
}
|
||||
|
||||
return $c->render( json => {
|
||||
success => Mojo::JSON->true,
|
||||
weeks => $weeks,
|
||||
|
|
|
@ -106,6 +106,7 @@ sub _purchases_avg_spend_duration {
|
|||
$dtf->format_datetime($end),
|
||||
],
|
||||
},
|
||||
buyer_id => $entity->id,
|
||||
},
|
||||
{
|
||||
columns => [
|
||||
|
|
|
@ -13,6 +13,8 @@ __PACKAGE__->result_source_instance->view_definition( qq/
|
|||
SELECT "value",
|
||||
"distance",
|
||||
"purchase_time",
|
||||
"buyer_id",
|
||||
"seller_id",
|
||||
DATE_TRUNC('hour', "purchase_time") AS "quantised_hours",
|
||||
DATE_TRUNC('day', "purchase_time") AS "quantised_days",
|
||||
DATE_TRUNC('week', "purchase_time") AS "quantised_weeks"
|
||||
|
|
|
@ -13,6 +13,8 @@ __PACKAGE__->result_source_instance->view_definition( qq/
|
|||
SELECT "value",
|
||||
"distance",
|
||||
"purchase_time",
|
||||
"buyer_id",
|
||||
"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"
|
||||
|
|
Reference in a new issue