Lines 50-56
sub monthly_report {
Link Here
|
50 |
return try { |
50 |
return try { |
51 |
|
51 |
|
52 |
my $json = JSON->new; |
52 |
my $json = JSON->new; |
53 |
my $args = $json->decode($c->param('q')); |
53 |
my $args = $json->decode( $c->param('q') ); |
54 |
my @query_params_array; |
54 |
my @query_params_array; |
55 |
|
55 |
|
56 |
if ( ref($args) eq 'ARRAY' ) { |
56 |
if ( ref($args) eq 'ARRAY' ) { |
Lines 66-73
sub monthly_report {
Link Here
|
66 |
|
66 |
|
67 |
my $usage_data_providers = |
67 |
my $usage_data_providers = |
68 |
Koha::ERM::EUsage::UsageDataProviders->search( {}, {} )->unblessed; |
68 |
Koha::ERM::EUsage::UsageDataProviders->search( {}, {} )->unblessed; |
69 |
my $metric_types = |
69 |
my $metric_types = $query_params_array[0]->{'erm_usage_muses.metric_type'}; |
70 |
$query_params_array[0]->{'erm_usage_muses.metric_type'}; |
|
|
71 |
my $access_types = |
70 |
my $access_types = |
72 |
$query_params_array[0]->{'erm_usage_muses.access_type'} |
71 |
$query_params_array[0]->{'erm_usage_muses.access_type'} |
73 |
? $query_params_array[0]->{'erm_usage_muses.access_type'} |
72 |
? $query_params_array[0]->{'erm_usage_muses.access_type'} |
Lines 213-220
sub metric_types_report {
Link Here
|
213 |
push @{$data}, $missing_result if $missing_result; |
212 |
push @{$data}, $missing_result if $missing_result; |
214 |
} |
213 |
} |
215 |
|
214 |
|
216 |
my @metric_types = ('metric_types_report'); # Dummy value to ensure the loop triggers at least once in _create_report_rows |
215 |
my @metric_types = |
217 |
my $report_data = _get_report_data( |
216 |
('metric_types_report'); # Dummy value to ensure the loop triggers at least once in _create_report_rows |
|
|
217 |
my $report_data = _get_report_data( |
218 |
{ |
218 |
{ |
219 |
data_type => $data_type, |
219 |
data_type => $data_type, |
220 |
data => $data, |
220 |
data => $data, |
Lines 257-267
sub provider_rollup_report {
Link Here
|
257 |
my $usage_data_providers_set = Koha::ERM::EUsage::UsageDataProviders->new; |
257 |
my $usage_data_providers_set = Koha::ERM::EUsage::UsageDataProviders->new; |
258 |
my $usage_data_providers = $c->objects->search($usage_data_providers_set); |
258 |
my $usage_data_providers = $c->objects->search($usage_data_providers_set); |
259 |
|
259 |
|
260 |
my $data_type = $c->param('data_type'); |
260 |
my $data_type = $c->param('data_type'); |
261 |
my $key = 'erm_usage_' . $data_type . 's'; |
261 |
my $key = 'erm_usage_' . $data_type . 's'; |
262 |
my $metric_types = |
262 |
my $metric_types = $query_params_array[0]->{ $key . '.erm_usage_muses.metric_type' }; |
263 |
$query_params_array[0]->{ $key . '.erm_usage_muses.metric_type' }; |
263 |
|
264 |
|
|
|
265 |
my @usage_data_provider_report_data; |
264 |
my @usage_data_provider_report_data; |
266 |
|
265 |
|
267 |
for my $usage_data_provider ( @{$usage_data_providers} ) { |
266 |
for my $usage_data_provider ( @{$usage_data_providers} ) { |
Lines 276-282
sub provider_rollup_report {
Link Here
|
276 |
grep { $metric_type eq $_->{metric_type} } @$statistics; |
275 |
grep { $metric_type eq $_->{metric_type} } @$statistics; |
277 |
my @usage_counts = |
276 |
my @usage_counts = |
278 |
map { $_->{usage_count} } @filtered_statistics; |
277 |
map { $_->{usage_count} } @filtered_statistics; |
279 |
my $sum = scalar(@usage_counts) > 0 |
278 |
my $sum = |
|
|
279 |
scalar(@usage_counts) > 0 |
280 |
? _get_usage_total( \@usage_counts ) |
280 |
? _get_usage_total( \@usage_counts ) |
281 |
: 0; |
281 |
: 0; |
282 |
|
282 |
|
Lines 299-305
sub provider_rollup_report {
Link Here
|
299 |
map { $_->{usage_total} } @filtered_object_data; |
299 |
map { $_->{usage_total} } @filtered_object_data; |
300 |
my $provider_rollup_total = |
300 |
my $provider_rollup_total = |
301 |
scalar(@data_object_usage_totals) > 0 |
301 |
scalar(@data_object_usage_totals) > 0 |
302 |
? _get_usage_total(\@data_object_usage_totals) |
302 |
? _get_usage_total( \@data_object_usage_totals ) |
303 |
: 0; |
303 |
: 0; |
304 |
|
304 |
|
305 |
my %usage_data_provider_hash = ( |
305 |
my %usage_data_provider_hash = ( |
Lines 405-417
sub _get_result_with_no_statistics {
Link Here
|
405 |
if ( !$check_result ) { |
405 |
if ( !$check_result ) { |
406 |
my $missing_result = _get_missing_data( $data_type, $id ); |
406 |
my $missing_result = _get_missing_data( $data_type, $id ); |
407 |
my @blank_statistics = (); |
407 |
my @blank_statistics = (); |
408 |
return _get_object_hash({ |
408 |
return _get_object_hash( |
409 |
data_type => $data_type, |
409 |
{ |
410 |
data_object => $missing_result, |
410 |
data_type => $data_type, |
411 |
statistics => \@blank_statistics, |
411 |
data_object => $missing_result, |
412 |
provider => '', |
412 |
statistics => \@blank_statistics, |
413 |
metric_type => '', |
413 |
provider => '', |
414 |
}); |
414 |
metric_type => '', |
|
|
415 |
} |
416 |
); |
415 |
} |
417 |
} |
416 |
return 0; |
418 |
return 0; |
417 |
} |
419 |
} |
Lines 623-629
sub _create_report_rows {
Link Here
|
623 |
grep { $metric_type eq $_->{metric_type} } @stats_by_access_type; |
625 |
grep { $metric_type eq $_->{metric_type} } @stats_by_access_type; |
624 |
my @usage_counts = |
626 |
my @usage_counts = |
625 |
map { $_->{usage_count} } @stats_by_metric_type; |
627 |
map { $_->{usage_count} } @stats_by_metric_type; |
626 |
my $sum = $period eq 'monthly' && scalar(@usage_counts) > 0 |
628 |
my $sum = |
|
|
629 |
$period eq 'monthly' && scalar(@usage_counts) > 0 |
627 |
? _get_usage_total( \@usage_counts ) |
630 |
? _get_usage_total( \@usage_counts ) |
628 |
: 0; |
631 |
: 0; |
629 |
|
632 |
|
Lines 652-659
sub _create_report_rows {
Link Here
|
652 |
: @usage_stats; |
655 |
: @usage_stats; |
653 |
my @usage_counts = |
656 |
my @usage_counts = |
654 |
map { $_->{usage_count} } @stats_by_metric_type; |
657 |
map { $_->{usage_count} } @stats_by_metric_type; |
655 |
my $sum = $period eq 'monthly' && scalar(@usage_counts) > 0 |
658 |
my $sum = |
656 |
? _get_usage_total(\@usage_counts) |
659 |
$period eq 'monthly' && scalar(@usage_counts) > 0 |
|
|
660 |
? _get_usage_total( \@usage_counts ) |
657 |
: 0; |
661 |
: 0; |
658 |
|
662 |
|
659 |
my $data_object_hash = _get_object_hash( |
663 |
my $data_object_hash = _get_object_hash( |
Lines 681-694
A method for summing the usage counts for a data object
Link Here
|
681 |
=cut |
685 |
=cut |
682 |
|
686 |
|
683 |
sub _get_usage_total { |
687 |
sub _get_usage_total { |
684 |
my ( $statistics ) = @_; |
688 |
my ($statistics) = @_; |
685 |
|
689 |
|
686 |
my $sum = 0; |
690 |
my $sum = 0; |
687 |
foreach my $statistic (@$statistics) { |
691 |
foreach my $statistic (@$statistics) { |
688 |
$sum += $statistic; |
692 |
$sum += $statistic; |
689 |
} |
693 |
} |
690 |
|
694 |
|
691 |
return $sum |
695 |
return $sum; |
692 |
} |
696 |
} |
693 |
|
697 |
|
694 |
1; |
698 |
1; |