Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tools for technical analysts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
tools for technical analysts
Commits
2801405f
Commit
2801405f
authored
1 year ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- init
- added date ranges
parent
01c28b78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SLUB/LZA/TA/Command/report.pm
+123
-0
123 additions, 0 deletions
lib/SLUB/LZA/TA/Command/report.pm
with
123 additions
and
0 deletions
lib/SLUB/LZA/TA/Command/report.pm
0 → 100644
+
123
−
0
View file @
2801405f
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
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment