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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
tools for technical analysts
Commits
3ddbc117
Verified
Commit
3ddbc117
authored
1 year ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- refactoring, minimized complexity by reordering and postfix evaluation
parent
84c0715b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SLUB/LZA/TA/Command/report.pm
+99
-76
99 additions, 76 deletions
lib/SLUB/LZA/TA/Command/report.pm
with
99 additions
and
76 deletions
lib/SLUB/LZA/TA/Command/report.pm
+
99
−
76
View file @
3ddbc117
...
...
@@ -125,47 +125,59 @@ sub validate_args { ## no critic CognitiveComplexity::ProhibitExcessCognitiveCom
my
(
$cyear
,
$cmonth
,
$cday
)
=
Today
();
my
(
$from_year
,
$from_month
,
$from_day
);
my
(
$to_year
,
$to_month
,
$to_day
);
if
(
!
exists
$opt
->
{
datemode
})
{
$opt
->
{
datemode
}
=
"
monthly
";
$opt
->
{
monthly
}
=
1
;}
if
(
exists
$opt
->
{
daily
})
{
unless
(
exists
$opt
->
{
datemode
})
{
$opt
->
{
datemode
}
=
"
monthly
";
$opt
->
{
monthly
}
=
1
;
}
my
%date_recipe
;
$date_recipe
{
daily
}
=
sub
{
(
$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
})
{
};
$date_recipe
{
weekly
}
=
sub
{
(
$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
})
{
};
$date_recipe
{
monthly
}
=
sub
{
(
$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
})
{
};
$date_recipe
{
yearly
}
=
sub
{
(
$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
);
}
elsif
(
exists
$opt
->
{
complete
})
{
$from_year
=
2015
;
$from_month
=
1
;
$from_day
=
1
;
$to_year
=
$cyear
;
$to_month
=
$cmonth
;
$to_day
=
$cday
;
}
elsif
(
exists
$opt
->
{
ldpyearly
})
{
};
$date_recipe
{
complete
}
=
sub
{
$from_year
=
2015
;
$from_month
=
1
;
$from_day
=
1
;
$to_year
=
$cyear
;
$to_month
=
$cmonth
;
$to_day
=
$cday
;
};
$date_recipe
{
ldpyearly
}
=
sub
{
(
$from_year
,
$from_month
,
$from_day
)
=
Add_Delta_YM
(
$cyear
,
1
,
1
,
-
1
,
-
2
);
(
$to_year
,
$to_month
,
$to_day
)
=
Add_Delta_YMD
(
$from_year
,
$from_month
,
$from_day
,
1
,
0
,
-
1
);
}
if
(
exists
$opt
->
{
date_from
}
)
{
}
;
$date_recipe
{
date_from
}
=
sub
{
$self
->
usage_error
('
--date-from implies --date-to"
')
unless
exists
$opt
->
{
date_to
};
if
(
$opt
->
{
date_from
}
=~
m/^(\d{4})-(\d{2})-(\d{2})$/
)
{
(
$from_year
,
$from_month
,
$from_day
)
=
(
$
1
,
$
2
,
$
3
);
}
else
{
$self
->
usage_error
('
--date-from expects date in format "YYYY-MM-DD", got "
'
.
$opt
->
{
date_from
}
.
'
"
');
}
}
if
(
exists
$opt
->
{
date_to
}
)
{
}
;
$date_recipe
{
date_to
}
=
sub
{
$self
->
usage_error
('
--date-to implies --date-from"
')
unless
exists
$opt
->
{
date_from
};
if
(
$opt
->
{
date_to
}
=~
m/^(\d{4})-(\d{2})-(\d{2})$/
)
{
(
$to_year
,
$to_month
,
$to_day
)
=
(
$
1
,
$
2
,
$
3
);
}
else
{
$self
->
usage_error
('
--date-to expects date in format "YYYY-MM-DD", got "
',
$opt
->
{
date_to
}
.
'
"
');
}
};
foreach
my
$key
(
keys
%
{
$opt
}
)
{
$date_recipe
{
$key
}
->
()
if
(
defined
$date_recipe
{
$key
}
and
ref
$date_recipe
{
$key
}
eq
'
CODE
');
}
if
(
!
exists
$opt
->
{
output_format
})
{
$opt
->
{
output_format
}
=
'
output_as_asciidoc
';
}
$opt
->
{
output_format
}
=
'
output_as_asciidoc
'
unless
(
exists
$opt
->
{
output_format
});
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
);
$self
->
usage_error
('
--date-to should have a date newer than --date-from
')
if
(
$from_epoch
>
$to_epoch
);
...
...
@@ -259,7 +271,7 @@ PAINLESS
return
$aips_response
;
}
sub
get_ldp_projects
{
sub
get_ldp_projects
{
## no critic CognitiveComplexity::ProhibitExcessCognitiveComplexity
my
(
$self
,
$opt
,
$args
)
=
@_
;
my
$query
=
SLUB::LZA::TA::Archivematica::Elasticsearch::PrepareQuery::
prepare_ldpprojects_query
(
@
_
);
my
$response
=
SLUB::LZA::TA::Archivematica::Elasticsearch::
query_elasticsearch
(
...
...
@@ -406,6 +418,52 @@ sub get_filestypes_by_aips {
return
\
%results
;
}
sub
filtered_set_for_ldp
($set, $newhashref) {
delete
$newhashref
->
{
only_ldp
};
delete
$newhashref
->
{
no_ldp
};
if
(
$set
eq
(
SETS
)[
LDP
])
{
$newhashref
->
{
only_ldp
}
=
1
}
elsif
(
$set
eq
(
SETS
)[
NO_LDP
])
{
$newhashref
->
{
no_ldp
}
=
1
;}
else
{
# full, do not filter for ldp
}
return
1
;
}
sub
filtered_set_for_aipstate
($aip_state, $newhashref) {
if
(
$aip_state
eq
(
AIPSTATE
)[
NEW
])
{
$newhashref
->
{
only_new
}
=
1
;}
elsif
(
$aip_state
eq
(
AIPSTATE
)[
UPDATE
])
{
$newhashref
->
{
only_updated
}
=
1
;}
return
1
;
}
sub
set_flavour_results_for_filetypes
($self, $opt, $args, $results_ref, $newhash_ref, $aip_state, $set) {
if
(
exists
(
$opt
->
{
with_filetypes
}))
{
my
$filetypes_hashref
=
get_filestypes_by_aips
(
$self
,
$newhash_ref
,
$args
);
foreach
my
$file_extension
(
sort
keys
%
{
$filetypes_hashref
->
{
file_extension
}})
{
$results_ref
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
FILES
]};
$results_ref
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
SIZE
]};
}
foreach
my
$pronom_id
(
sort
keys
%
{
$filetypes_hashref
->
{
pronom_id
}})
{
$results_ref
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
FILES
]};
$results_ref
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
SIZE
]};
}
}
return
1
;
}
sub
set_ldpflavour_results_for_filetype
($self, $opt, $args, $results_ref, $newhash_ref, $ldp_project, $aip_state) {
if
(
exists
(
$opt
->
{
with_filetypes
}))
{
my
$filetypes_hashref
=
get_filestypes_by_aips
(
$self
,
$newhash_ref
,
$args
);
foreach
my
$file_extension
(
sort
keys
%
{
$filetypes_hashref
->
{
file_extension
}})
{
$results_ref
->
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
FILES
]};
$results_ref
->
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
SIZE
]};
}
foreach
my
$pronom_id
(
sort
keys
%
{
$filetypes_hashref
->
{
pronom_id
}})
{
$results_ref
->
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
FILES
]};
$results_ref
->
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
SIZE
]};
}
}
return
1
;
}
sub
execute
{
my
(
$self
,
$opt
,
$args
)
=
@_
;
my
%results
;
...
...
@@ -413,75 +471,40 @@ sub execute {
$results
{
package
}
=
__PACKAGE__
;
$results
{
from
}
=
$opt
->
{
creationdate_epochs
}
->
{
from_string
};
$results
{
to
}
=
$opt
->
{
creationdate_epochs
}
->
{
to_string
};
my
@ldp_projects
;
if
(
$opt
->
{
with_ldp
})
{
@ldp_projects
=
get_ldp_projects
(
@
_
);
}
my
@ldp_projects
=
(
$opt
->
{
with_ldp
})
?
get_ldp_projects
(
@
_
)
:
();
foreach
my
$aip_state
(
AIPSTATE
)
{
my
%newhash
=
%
{
$opt
};
if
(
$aip_state
eq
(
AIPSTATE
)[
NEW
])
{
$newhash
{
only_new
}
=
1
;}
elsif
(
$aip_state
eq
(
AIPSTATE
)[
UPDATE
])
{
$newhash
{
only_updated
}
=
1
;}
filtered_set_for_aipstate
(
$aip_state
,
\
%newhash
);
foreach
my
$set
(
SETS
)
{
delete
$newhash
{
only_ldp
};
delete
$newhash
{
no_ldp
};
if
(
$set
eq
(
SETS
)[
LDP
])
{
$newhash
{
only_ldp
}
=
1
}
elsif
(
$set
eq
(
SETS
)[
NO_LDP
])
{
$newhash
{
no_ldp
}
=
1
;}
else
{
# full, do not filter for ldp
}
filtered_set_for_ldp
(
$set
,
\
%newhash
);
my
$res
=
_execute
(
$self
,
\
%newhash
,
$args
);
$results
{
flavour
}
->
{(
FLAVOURS
)[
COUNT
]}
->
{
$aip_state
}
->
{
$set
}
->
{""}
=
$res
->
{
hits
}
->
{
total
};
$results
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_aip_size
}
->
{
value
}
*
1024
*
1024
;
$results
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_file_count
}
->
{
value
};
$results
{
flavour
}
->
{(
FLAVOURS
)[
PAYLOAD_SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_payload_size
}
->
{
value
};
$results
{
flavour
}
->
{(
FLAVOURS
)[
PAYLOAD_FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_payload_filecount
}
->
{
value
};
if
(
exists
(
$opt
->
{
with_filetypes
}))
{
my
$filetypes_hashref
=
get_filestypes_by_aips
(
$self
,
\
%newhash
,
$args
);
foreach
my
$file_extension
(
sort
keys
%
{
$filetypes_hashref
->
{
file_extension
}})
{
$results
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
FILES
]};
$results
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
SIZE
]};
}
foreach
my
$pronom_id
(
sort
keys
%
{
$filetypes_hashref
->
{
pronom_id
}})
{
$results
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
FILES
]};
$results
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
$set
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
SIZE
]};
}
}
set_flavour_results_for_filetypes
(
$self
,
$opt
,
$args
,
\
%results
,
\
%newhash
,
$aip_state
,
$set
);
}
undef
%newhash
;
foreach
my
$ldp_project
(
@ldp_projects
)
{
# only if @ldp_projects have size > 1
foreach
my
$ldp_project
(
@ldp_projects
)
{
# only if @ldp_projects have size > 1
%newhash
=
%
{
$opt
};
if
(
$aip_state
eq
(
AIPSTATE
)[
NEW
])
{
$newhash
{
only_new
}
=
1
;}
elsif
(
$aip_state
eq
(
AIPSTATE
)[
UPDATE
])
{
$newhash
{
only_updated
}
=
1
;}
filtered_set_for_aipstate
(
$aip_state
,
\
%newhash
);
$newhash
{
only_ldp_project
}
=
$ldp_project
;
my
$res
=
_execute
(
$self
,
\
%newhash
,
$args
);
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
COUNT
]}
->
{
$aip_state
}
->
{""}
=
$res
->
{
hits
}
->
{
total
};
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_aip_size
}
->
{
value
}
*
1024
*
1024
;
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_file_count
}
->
{
value
};
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
PAYLOAD_SIZE
]}
->
{
$aip_state
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_payload_size
}
->
{
value
};
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
PAYLOAD_FILES
]}
->
{
$aip_state
}
->
{""}
=
$res
->
{
aggregations
}
->
{
total_payload_filecount
}
->
{
value
};
if
(
exists
(
$opt
->
{
with_filetypes
}))
{
my
$filetypes_hashref
=
get_filestypes_by_aips
(
$self
,
\
%newhash
,
$args
);
foreach
my
$file_extension
(
sort
keys
%
{
$filetypes_hashref
->
{
file_extension
}})
{
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
FILES
]};
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
file extension
",
$file_extension
}
=
$filetypes_hashref
->
{
file_extension
}
->
{
$file_extension
}
->
{(
FLAVOURS
)[
SIZE
]};
}
foreach
my
$pronom_id
(
sort
keys
%
{
$filetypes_hashref
->
{
pronom_id
}})
{
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
FILES
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
FILES
]};
$results
{
ldp_project
}
->
{
$ldp_project
}
->
{
flavour
}
->
{(
FLAVOURS
)[
SIZE
]}
->
{
$aip_state
}
->
{
sprintf
"
%20s %10s
",
"
pronom id
",
$pronom_id
}
=
$filetypes_hashref
->
{
pronom_id
}
->
{
$pronom_id
}
->
{(
FLAVOURS
)[
SIZE
]};
}
set_ldpflavour_results_for_filetype
(
$self
,
$opt
,
$args
,
\
%results
,
\
%newhash
,
$ldp_project
,
$aip_state
)
}
}
}
if
(
$opt
->
{
output_format
}
eq
'
output_as_asciidoc
')
{
print_humanreadable_report
(
\
%results
);
}
else
{
my
(
$headers
,
$table
)
=
prepare_for_table
(
\
%results
,
\
@ldp_projects
);
if
(
$opt
->
{
output_format
}
eq
'
output_as_rsv
')
{
SLUB::LZA::TA::Output::RSV::
print_results
(
$table
);
}
elsif
(
$opt
->
{
output_format
}
eq
'
output_as_csv
')
{
SLUB::LZA::TA::Output::
C
SV::
print_results
(
$table
);
}
els
if
(
$opt
->
{
output_format
}
eq
'
output_as_
raw
')
{
SLUB::LZA::TA::Output::Raw::
print_results
(
\
%results
);
}
}
print_humanreadable_report
(
\
%results
)
if
(
$opt
->
{
output_format
}
eq
'
output_as_asciidoc
'
);
SLUB::LZA::TA::Output::
R
SV::
print_results
(
$table
)
if
(
$opt
->
{
output_format
}
eq
'
output_as_rsv
')
;
SLUB::LZA::TA::Output::CSV::
print_results
(
$table
)
if
(
$opt
->
{
output_format
}
eq
'
output_as_
csv
'
);
SLUB::LZA::TA::Output::Raw::
print_results
(
\
%results
)
if
(
$opt
->
{
output_format
}
eq
'
output_as_raw
');
say
STDERR
"
report is already sent to STDOUT.
";
return
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