Skip to content
Snippets Groups Projects
Commit 2801405f authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- init

- added date ranges
parent 01c28b78
No related branches found
No related tags found
No related merge requests found
package SLUB::LZA::TA::Command::report;
use SLUB::LZA::TA -command;
use v5.36;
use SLUB::LZA::TA::Archivematica::Elasticsearch;
use SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery;
use SLUB::LZA::TA::Output;
use Date::Calc qw(Date_to_Time Today Add_Delta_YM Add_Delta_YMD Day_of_Week);
use namespace::autoclean -except => qr{SLUB::LZA::TA::.*};
# VERSION
# ABSTRACT: search IEs module for ta-tool
sub abstract {"print AIP reports about Archival Information System (AIS)";}
my $description=<<"DESCR";
Ask an AIS for some statistics about AIPs.
Examples:
* Report statistics of AIPs last month for workflow Kitodo
'$0 report --monthly --workflow Kitodo'
* Report statistics of AIPs last year as RSV
'$0 report --yearly --output-as-rsv'
DESCR
sub description {
"$description"
}
sub opt_spec {
return (
[ 'debug' => 'enable user agent debug output' ],
[ 'output-format' => hidden => {
one_of => [
[ 'output-as-csv|C' => 'prints output as Comma Separated Values (CSV)' ],
[ 'output-as-raw|R' => 'enable full elasticsearch response' ],
[ 'output-as-rsv|r' => 'prints output as Raw Strings Values (RSV) [default]' ],
],
}
],
[],
[ 'datemode' => hidden => {
one_of => [
['daily|d' => 'report based on last day'],
[ 'weekly|W' => 'report based on last week'],
[ 'monthly|m' => 'report based on last month' ],
[ 'yearly|y' => 'report based on last year' ],
]
}
],
[ 'workflow|w=s' => 'LZA internal workflow name'],
[],
[],
[ 'help|h', 'print usage message and exit', { shortcircuit => 1 } ],
[ 'version|v', 'print version information', { shortcircuit => 1 } ],
);
}
sub validate_args {
my ($self, $opt, $args) = @_;
# no args allowed but options!
$self->usage_error("No args allowed") if @$args;
my ($cyear, $cmonth, $cday) = Today();
my ($from_year, $from_month, $from_day);
my ($to_year, $to_month, $to_day);
if (exists $opt->{daily}) {
($from_year, $from_month, $from_day) = Add_Delta_YMD($cyear, $cmonth, $cday, 0, 0, -1);
($to_year, $to_month, $to_day) = ($from_year, $from_month, $from_day);
} elsif (exists $opt->{weekly}) {
($from_year, $from_month, $from_day) = Add_Delta_YMD($cyear, $cmonth, $cday, 0, 0, -Day_of_Week($cyear, $cmonth, $cday)-6);
($to_year, $to_month, $to_day) = Add_Delta_YMD($from_year, $from_month, $from_day, 0, 0, 6);
} elsif (exists $opt->{monthly}) {
($from_year, $from_month, $from_day) = Add_Delta_YM($cyear, $cmonth, 1, 0, -1);
($to_year, $to_month, $to_day) = Add_Delta_YMD($from_year, $from_month, $from_day, 0, 1, -1);
}
elsif (exists $opt->{yearly}) {
($from_year, $from_month, $from_day) = Add_Delta_YM($cyear, 1, 1, -1, 0);
($to_year, $to_month, $to_day) = Add_Delta_YMD($from_year, $from_month, $from_day, 1, 0, -1);
}
printf STDERR "reporting for period %04u-%02u-%02u … %04u-%02u-%02u\n", $from_year, $from_month, $from_day, $to_year, $to_month, $to_day;
my $from_epoch = Date_to_Time($from_year, $from_month, $from_day, 0, 0, 0);
my $to_epoch = Date_to_Time($to_year, $to_month, $to_day, 0, 0, 0);
$opt->{creationdate_epochs}->{from} = $from_epoch;
$opt->{creationdate_epochs}->{to} = $to_epoch;
1;
}
sub execute {
my ($self, $opt, $args) = @_;
my $aips_query;
my $aips_response;
#p($opt);
if (exists $opt->{format} and $opt->{format} eq 'pronom_id') {
$aips_query = SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::prepare_aip_query($opt);
# replace AIP query with all match
my @aips = find_aips_by_file_pronom_id(@_);
$aips_query->{query}->{bool}->{must}->{terms}->{uuid} = \@aips;
} else {
# only index aips needed
$aips_query = SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::prepare_aip_query($opt);
}
if (exists $opt->{debug}) {
use Data::Printer;
say STDERR "query:";
say STDERR "------------------------";
say STDERR np( $aips_query);
say STDERR "------------------------";
}
#p($aips_query);
$aips_response = SLUB::LZA::TA::Archivematica::Elasticsearch::query_elasticsearch(
$SLUB::LZA::TA::config{elasticsearchprotocol},
$SLUB::LZA::TA::config{elasticsearchhost},
$SLUB::LZA::TA::config{elasticsearchport},
'aips', # indexname
$aips_query, # query_hash ref
);
#p($aips_response);
SLUB::LZA::TA::Output::print_results($aips_response, $opt);
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment