Lines 41-55
Koha::ERM::EUsage::SushiCounter - Koha SushiCounter Object class
Link Here
|
41 |
sub new { |
41 |
sub new { |
42 |
my ( $class, $params ) = @_; |
42 |
my ( $class, $params ) = @_; |
43 |
|
43 |
|
44 |
my $self = $class->SUPER::new; |
44 |
my $counter_release; |
45 |
$self->{sushi} = { |
45 |
if ( $params->{response}->{Report_Header}->{Release} eq "5" ) { |
|
|
46 |
require Koha::ERM::EUsage::COUNTER::5; |
47 |
$counter_release = Koha::ERM::EUsage::COUNTER::5->new; |
48 |
} elsif ( $params->{response}->{Report_Header}->{Release} eq "5.1" ) { |
49 |
require Koha::ERM::EUsage::COUNTER::5_1; |
50 |
$counter_release = Koha::ERM::EUsage::COUNTER::5_1->new; |
51 |
} else { |
52 |
|
53 |
#TODO: Throw an exception stating release not found / not supported! |
54 |
} |
55 |
|
56 |
$counter_release->{sushi} = { |
46 |
header => $params->{response}->{Report_Header}, |
57 |
header => $params->{response}->{Report_Header}, |
47 |
body => $params->{response}->{Report_Items} |
58 |
body => $params->{response}->{Report_Items} |
48 |
}; |
59 |
}; |
49 |
|
60 |
|
50 |
#TODO: Handle empty $self->{sushi}->{body} here! |
61 |
#TODO: Handle empty $self->{sushi}->{body} here! |
51 |
|
62 |
|
52 |
return $self; |
63 |
return $counter_release; |
53 |
} |
64 |
} |
54 |
|
65 |
|
55 |
=head3 get_COUNTER_from_SUSHI |
66 |
=head3 get_COUNTER_from_SUSHI |
Lines 92-138
sub _build_COUNTER_report_file {
Link Here
|
92 |
|
103 |
|
93 |
} |
104 |
} |
94 |
|
105 |
|
95 |
=head3 _COUNTER_report_header |
|
|
96 |
|
97 |
Return a COUNTER report header |
98 |
https://cop5.projectcounter.org/en/5.0.2/04-reports/03-title-reports.html |
99 |
|
100 |
=cut |
101 |
|
102 |
sub _COUNTER_report_header { |
103 |
my ($self) = @_; |
104 |
|
105 |
my $header = $self->{sushi}->{header}; |
106 |
|
107 |
my @metric_types_string = $self->_get_SUSHI_Name_Value( $header->{Report_Filters}, "Metric_Type" ); |
108 |
|
109 |
my $begin_date = $self->_get_SUSHI_Name_Value( $header->{Report_Filters}, "Begin_Date" ); |
110 |
my $end_date = $self->_get_SUSHI_Name_Value( $header->{Report_Filters}, "End_Date" ); |
111 |
|
112 |
return ( |
113 |
[ Report_Name => $header->{Report_Name} || "" ], |
114 |
[ Report_ID => $header->{Report_ID} || "" ], |
115 |
[ Release => $header->{Release} || "" ], |
116 |
[ Institution_Name => $header->{Institution_Name} || "" ], |
117 |
[ Institution_ID => join( "; ", map( $_->{Type} . ":" . $_->{Value}, @{ $header->{Institution_ID} } ) ) || "" ], |
118 |
[ Metric_Types => join( "; ", split( /\|/, $metric_types_string[0] ) ) || "" ], |
119 |
[ Report_Filters => join( "; ", map( $_->{Name} . ":" . $_->{Value}, @{ $header->{Report_Filters} } ) ) || "" ], |
120 |
|
121 |
#TODO: Report_Attributes may need parsing, test this with a SUSHI response that provides it |
122 |
[ Report_Attributes => $header->{Report_Attributes} || "" ], |
123 |
[ |
124 |
Exceptions => join( |
125 |
"; ", map( $_->{Code} . ": " . $_->{Message} . " (" . $_->{Data} . ")", @{ $header->{Exceptions} } ) |
126 |
) |
127 |
|| "" |
128 |
], |
129 |
[ Reporting_Period => "Begin_Date=" . $begin_date . "; End_Date=" . $end_date ], |
130 |
[ Created => $header->{Created} || "" ], |
131 |
[ Created_By => $header->{Created_By} || "" ], |
132 |
[""] #empty 13th line (COUNTER 5) |
133 |
); |
134 |
} |
135 |
|
136 |
=head3 _COUNTER_item_report_row |
106 |
=head3 _COUNTER_item_report_row |
137 |
|
107 |
|
138 |
Return a COUNTER item for the COUNTER items report body |
108 |
Return a COUNTER item for the COUNTER items report body |
Lines 274-344
sub _COUNTER_platform_report_row {
Link Here
|
274 |
); |
244 |
); |
275 |
} |
245 |
} |
276 |
|
246 |
|
277 |
=head3 _COUNTER_title_report_row |
|
|
278 |
|
279 |
Return a COUNTER title for the COUNTER titles report body |
280 |
https://cop5.projectcounter.org/en/5.0.2/04-reports/03-title-reports.html#column-headings-elements |
281 |
|
282 |
=cut |
283 |
|
284 |
sub _COUNTER_title_report_row { |
285 |
my ( $self, $title_row, $metric_type, $total_usage, $monthly_usages ) = @_; |
286 |
|
287 |
my $header = $self->{sushi}->{header}; |
288 |
my $specific_fields = $self->get_report_type_specific_fields( $header->{Report_ID} ); |
289 |
|
290 |
return ( |
291 |
[ |
292 |
# Title |
293 |
$title_row->{Title} || "", |
294 |
|
295 |
# Publisher |
296 |
$title_row->{Publisher} || "", |
297 |
|
298 |
# Publisher_ID |
299 |
$self->_get_SUSHI_Type_Value( $title_row->{Publisher_ID}, "ISNI" ) || "", |
300 |
|
301 |
# Platform |
302 |
$title_row->{Platform} || "", |
303 |
|
304 |
# DOI |
305 |
$self->_get_SUSHI_Type_Value( $title_row->{Item_ID}, "DOI" ) || "", |
306 |
|
307 |
# Proprietary_ID |
308 |
$self->_get_SUSHI_Type_Value( $title_row->{Item_ID}, "Proprietary" ) || "", |
309 |
|
310 |
# ISBN |
311 |
grep ( /ISBN/, @{$specific_fields} ) |
312 |
? ( $self->_get_SUSHI_Type_Value( $title_row->{Item_ID}, "ISBN" ) || "" ) |
313 |
: (), |
314 |
|
315 |
# Print_ISSN |
316 |
$self->_get_SUSHI_Type_Value( $title_row->{Item_ID}, "Print_ISSN" ) || "", |
317 |
|
318 |
# Online_ISSN |
319 |
$self->_get_SUSHI_Type_Value( $title_row->{Item_ID}, "Online_ISSN" ) || "", |
320 |
|
321 |
# URI - FIXME: What goes in URI? |
322 |
"", |
323 |
|
324 |
# YOP |
325 |
grep ( /YOP/, @{$specific_fields} ) ? ( $title_row->{YOP} || "" ) : (), |
326 |
|
327 |
# Access_Type |
328 |
grep ( /Access_Type/, @{$specific_fields} ) ? ( $title_row->{Access_Type} || "" ) : (), |
329 |
|
330 |
# Metric_Type |
331 |
$metric_type, |
332 |
|
333 |
# Report_Period_Total |
334 |
$total_usage, |
335 |
|
336 |
# Monthly usage entries |
337 |
@{$monthly_usages} |
338 |
] |
339 |
); |
340 |
} |
341 |
|
342 |
=head3 _COUNTER_report_row |
247 |
=head3 _COUNTER_report_row |
343 |
|
248 |
|
344 |
Return a COUNTER row for the COUNTER report body |
249 |
Return a COUNTER row for the COUNTER report body |
Lines 346-356
Return a COUNTER row for the COUNTER report body
Link Here
|
346 |
=cut |
251 |
=cut |
347 |
|
252 |
|
348 |
sub _COUNTER_report_row { |
253 |
sub _COUNTER_report_row { |
349 |
my ( $self, $report_row, $metric_type ) = @_; |
254 |
my ( $self, $report_row, $metric_type, $access_type, $yop, $data_type ) = @_; |
350 |
|
255 |
|
351 |
my $header = $self->{sushi}->{header}; |
256 |
my $header = $self->{sushi}->{header}; |
352 |
|
257 |
|
353 |
my ( $total_usage, @monthly_usages ) = $self->_get_COUNTER_row_usages( $report_row, $metric_type ); |
258 |
my ( $total_usage, @monthly_usages ) = $self->_get_COUNTER_row_usages( $report_row, $metric_type, $access_type ); |
354 |
|
259 |
|
355 |
if ( $header->{Report_ID} =~ /PR/i ) { |
260 |
if ( $header->{Report_ID} =~ /PR/i ) { |
356 |
return $self->_COUNTER_platform_report_row( |
261 |
return $self->_COUNTER_platform_report_row( |
Lines 360-474
sub _COUNTER_report_row {
Link Here
|
360 |
} elsif ( $header->{Report_ID} =~ /DR/i ) { |
265 |
} elsif ( $header->{Report_ID} =~ /DR/i ) { |
361 |
return $self->_COUNTER_database_report_row( $report_row, $metric_type, $total_usage, \@monthly_usages ); |
266 |
return $self->_COUNTER_database_report_row( $report_row, $metric_type, $total_usage, \@monthly_usages ); |
362 |
} elsif ( $header->{Report_ID} =~ /IR/i ) { |
267 |
} elsif ( $header->{Report_ID} =~ /IR/i ) { |
|
|
268 |
|
269 |
#TODO: Send $access_type to _COUNTER_item_report_row like we're doing with _COUNTER_title_report_row |
363 |
return $self->_COUNTER_item_report_row( $report_row, $metric_type, $total_usage, \@monthly_usages ); |
270 |
return $self->_COUNTER_item_report_row( $report_row, $metric_type, $total_usage, \@monthly_usages ); |
364 |
} elsif ( $header->{Report_ID} =~ /TR/i ) { |
271 |
} elsif ( $header->{Report_ID} =~ /TR/i ) { |
365 |
return $self->_COUNTER_title_report_row( $report_row, $metric_type, $total_usage, \@monthly_usages ); |
272 |
return $self->_COUNTER_title_report_row( |
366 |
} |
273 |
$report_row, $metric_type, $total_usage, \@monthly_usages, |
367 |
} |
274 |
$access_type, $yop, $data_type |
368 |
|
275 |
); |
369 |
=head3 _get_COUNTER_row_usages |
|
|
370 |
|
371 |
Returns the total and monthly usages for a row |
372 |
|
373 |
=cut |
374 |
|
375 |
sub _get_COUNTER_row_usages { |
376 |
my ( $self, $row, $metric_type ) = @_; |
377 |
|
378 |
my @usage_months = $self->_get_usage_months( $self->{sushi}->{header} ); |
379 |
|
380 |
my @usage_months_fields = (); |
381 |
my $count_total = 0; |
382 |
|
383 |
foreach my $usage_month (@usage_months) { |
384 |
my $month_is_empty = 1; |
385 |
|
386 |
foreach my $performance ( @{ $row->{Performance} } ) { |
387 |
my $period = $performance->{Period}; |
388 |
my $period_usage_month = substr( $period->{Begin_Date}, 0, 7 ); |
389 |
|
390 |
my $instances = $performance->{Instance}; |
391 |
my @metric_type_count = |
392 |
map( $_->{Metric_Type} eq $metric_type ? $_->{Count} : (), |
393 |
@{$instances} ); |
394 |
|
395 |
if ( $period_usage_month eq $usage_month && $metric_type_count[0] ) { |
396 |
push( @usage_months_fields, $metric_type_count[0] ); |
397 |
$count_total += $metric_type_count[0]; |
398 |
$month_is_empty = 0; |
399 |
} |
400 |
} |
401 |
|
402 |
if ($month_is_empty) { |
403 |
push( @usage_months_fields, 0 ); |
404 |
} |
405 |
} |
406 |
return ( $count_total, @usage_months_fields ); |
407 |
} |
408 |
|
409 |
=head3 _COUNTER_report_body |
410 |
|
411 |
Return the COUNTER report body as an array |
412 |
|
413 |
=cut |
414 |
|
415 |
sub _COUNTER_report_body { |
416 |
my ($self) = @_; |
417 |
|
418 |
my $header = $self->{sushi}->{header}; |
419 |
my $body = $self->{sushi}->{body}; |
420 |
|
421 |
my @report_body = (); |
422 |
|
423 |
foreach my $report_row ( @{$body} ) { |
424 |
|
425 |
my @metric_types = (); |
426 |
|
427 |
# Grab all metric_types this SUSHI result has statistics for |
428 |
foreach my $performance ( @{ $report_row->{Performance} } ) { |
429 |
my @SUSHI_metric_types = |
430 |
map( $_->{Metric_Type}, @{ $performance->{Instance} } ); |
431 |
|
432 |
foreach my $sushi_metric_type (@SUSHI_metric_types) { |
433 |
push( @metric_types, $sushi_metric_type ) unless grep { $_ eq $sushi_metric_type } @metric_types; |
434 |
} |
435 |
} |
436 |
|
437 |
# Add one report row for each metric_type we're working with |
438 |
foreach my $metric_type (@metric_types) { |
439 |
push( @report_body, $self->_COUNTER_report_row( $report_row, $metric_type ) ); |
440 |
} |
441 |
} |
276 |
} |
442 |
|
|
|
443 |
return @report_body; |
444 |
} |
445 |
|
446 |
=head3 _get_SUSHI_Name_Value |
447 |
|
448 |
Returns "Value" of a given "Name" |
449 |
|
450 |
=cut |
451 |
|
452 |
sub _get_SUSHI_Name_Value { |
453 |
my ( $self, $item, $name ) = @_; |
454 |
|
455 |
my @value = map( $_->{Name} eq $name ? $_->{Value} : (), @{$item} ); |
456 |
|
457 |
return $value[0]; |
458 |
} |
459 |
|
460 |
=head3 _get_SUSHI_Type_Value |
461 |
|
462 |
Returns "Value" of a given "Type" |
463 |
|
464 |
=cut |
465 |
|
466 |
sub _get_SUSHI_Type_Value { |
467 |
my ( $self, $item, $type ) = @_; |
468 |
|
469 |
my @value = map( $_->{Type} eq $type ? $_->{Value} : (), @{$item} ); |
470 |
|
471 |
return $value[0]; |
472 |
} |
277 |
} |
473 |
|
278 |
|
474 |
=head3 _COUNTER_report_column_headings |
279 |
=head3 _COUNTER_report_column_headings |
Lines 617-661
sub _COUNTER_platforms_report_column_headings {
Link Here
|
617 |
); |
422 |
); |
618 |
} |
423 |
} |
619 |
|
424 |
|
620 |
=head3 _COUNTER_titles_report_column_headings |
425 |
=head3 get_report_type_specific_fields_by_release |
621 |
|
426 |
|
622 |
Return titles report column headings |
427 |
Returns the specific fields for a given report_type |
623 |
|
428 |
|
624 |
=cut |
429 |
=cut |
625 |
|
430 |
|
626 |
sub _COUNTER_titles_report_column_headings { |
431 |
sub get_report_type_specific_fields_by_release { |
627 |
my ($self) = @_; |
432 |
my ( $self, $report_type, $counter_release ) = @_; |
628 |
|
|
|
629 |
my $header = $self->{sushi}->{header}; |
630 |
my @month_headings = $self->_get_usage_months( $header, 1 ); |
631 |
my $specific_fields = $self->get_report_type_specific_fields( $header->{Report_ID} ); |
632 |
|
633 |
return ( |
634 |
[ |
635 |
"Title", |
636 |
"Publisher", |
637 |
"Publisher_ID", |
638 |
"Platform", |
639 |
"DOI", |
640 |
"Proprietary_ID", |
641 |
grep ( /ISBN/, @{$specific_fields} ) ? ("ISBN") : (), |
642 |
"Print_ISSN", |
643 |
"Online_ISSN", |
644 |
"URI", |
645 |
|
646 |
#"Data_Type", #TODO: Only if requested (?) |
647 |
#"Section_Type", #TODO: Only if requested (?) |
648 |
grep ( /YOP/, @{$specific_fields} ) ? ("YOP") : (), |
649 |
grep ( /Access_Type/, @{$specific_fields} ) ? ("Access_Type") : (), |
650 |
|
433 |
|
651 |
#"Access_Method", #TODO: Only if requested (?) |
434 |
if ( $counter_release eq "5" ) { |
652 |
"Metric_Type", |
435 |
require Koha::ERM::EUsage::COUNTER::5; |
653 |
"Reporting_Period_Total", |
436 |
return Koha::ERM::EUsage::COUNTER::5->get_report_type_specific_fields($report_type); |
654 |
|
437 |
} elsif ( $counter_release eq "5.1" ) { |
655 |
# @month_headings in "Mmm-yyyy" format. TODO: Show unless Exclude_Monthly_Details=true |
438 |
require Koha::ERM::EUsage::COUNTER::5_1; |
656 |
@month_headings |
439 |
return Koha::ERM::EUsage::COUNTER::5_1->get_report_type_specific_fields($report_type); |
657 |
] |
440 |
} |
658 |
); |
|
|
659 |
} |
441 |
} |
660 |
|
442 |
|
661 |
=head3 _get_usage_months |
443 |
=head3 _get_usage_months |
Lines 672-682
sub _get_usage_months {
Link Here
|
672 |
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
454 |
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
673 |
); |
455 |
); |
674 |
|
456 |
|
675 |
my @begin_date = map( $_->{Name} eq "Begin_Date" ? $_->{Value} : (), @{ $header->{Report_Filters} } ); |
457 |
my @begin_date = $self->_get_SUSHI_Name_Value( $header->{Report_Filters}, 'Begin_Date' ); |
676 |
my $begin_month = substr( $begin_date[0], 5, 2 ); |
458 |
my $begin_month = substr( $begin_date[0], 5, 2 ); |
677 |
my $begin_year = substr( $begin_date[0], 0, 4 ); |
459 |
my $begin_year = substr( $begin_date[0], 0, 4 ); |
678 |
|
460 |
|
679 |
my @end_date = map( $_->{Name} eq "End_Date" ? $_->{Value} : (), @{ $header->{Report_Filters} } ); |
461 |
my @end_date = $self->_get_SUSHI_Name_Value( $header->{Report_Filters}, 'End_Date' ); |
680 |
my $end_month = substr( $end_date[0], 5, 2 ); |
462 |
my $end_month = substr( $end_date[0], 5, 2 ); |
681 |
my $end_year = substr( $end_date[0], 0, 4 ); |
463 |
my $end_year = substr( $end_date[0], 0, 4 ); |
682 |
|
464 |
|
Lines 699-730
sub _get_usage_months {
Link Here
|
699 |
return @month_headings; |
481 |
return @month_headings; |
700 |
} |
482 |
} |
701 |
|
483 |
|
702 |
=head3 get_report_type_specific_fields |
|
|
703 |
|
704 |
Returns the specific fields for a given report_type |
705 |
|
706 |
=cut |
707 |
|
708 |
sub get_report_type_specific_fields { |
709 |
my ( $self, $report_type ) = @_; |
710 |
|
711 |
my %report_type_map = ( |
712 |
"TR_B1" => [ 'YOP', 'ISBN' ], |
713 |
"TR_B2" => [ 'YOP', 'ISBN' ], |
714 |
"TR_B3" => [ 'YOP', 'Access_Type', 'ISBN' ], |
715 |
"TR_J3" => ['Access_Type'], |
716 |
"TR_J4" => ['YOP'], |
717 |
"IR_A1" => [ |
718 |
'Authors', 'Publication_Date', 'Article_Version', 'Print_ISSN', 'Online_ISSN', 'Parent_Title', |
719 |
'Parent_Authors', 'Parent_Article_Version', 'Parent_DOI', 'Parent_Proprietary_ID', 'Parent_Print_ISSN', |
720 |
'Parent_Online_ISSN', 'Parent_URI', 'Access_Type' |
721 |
], |
722 |
); |
723 |
|
724 |
return $report_type_map{$report_type}; |
725 |
|
726 |
} |
727 |
|
728 |
=head3 _type |
484 |
=head3 _type |
729 |
|
485 |
|
730 |
=cut |
486 |
=cut |
731 |
- |
|
|