-
Notifications
You must be signed in to change notification settings - Fork 0
ETT-61 Exclude */man items from newyear.pl #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
01d6abb
ETT-61 Exclude */man items from newyear.pl
moseshll a97b06f
Add `CRMS::NewYear` method `choose_rights_prediction`
moseshll aba30cf
Flag two unused variables
moseshll 07d09af
Clarify comment
moseshll eb42f69
Use standard GetMetadata block for all projects
moseshll 9ebe441
- Swap in CRMS::NewYear::choose_rights_prediction for existing code a…
moseshll e613e1c
Add note about random choice between competing pd/add and pd/exp pred…
moseshll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package CRMS::NewYear; | ||
|
|
||
| # A utility package containing logic that relates to the new year Public Domain Day | ||
| # rollover of rights. | ||
|
|
||
| use strict; | ||
| use warnings; | ||
| use utf8; | ||
|
|
||
| use Data::Dumper; | ||
| use List::Util qw(); | ||
|
|
||
| sub new { | ||
| my $class = shift; | ||
|
|
||
| my $self = { @_ }; | ||
| bless($self, $class); | ||
| return $self; | ||
| } | ||
|
|
||
| # Are the passed-in current rights "attribute" and "reason" names in scope for | ||
| # PDD rollover? This excludes pd and CC items, because there's nothing more to be done. | ||
| # It also excludes */{con, del, man, pvt, supp} items, because CRMS can't override them | ||
| # and there is no point in reporting them. | ||
| sub are_rights_in_scope { | ||
| my $self = shift; | ||
| my $attribute = shift; | ||
| my $reason = shift; | ||
|
|
||
| if ( | ||
| $attribute eq 'pd' || | ||
| $attribute =~ m/^cc/ || | ||
| $reason eq 'con' || | ||
| $reason eq 'del' || | ||
| $reason eq 'man' || | ||
| $reason eq 'pvt' || | ||
| $reason eq 'supp' | ||
| ) { | ||
| return; | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| # Given a set of rights predictions that might reasonably be made based on reviewer data, | ||
| # in the form of a hashref of { "pd/add" => 1, "ic/add" => 1, ... } and the current attribute | ||
| # name, calculate the most restrictive attribute among the predictions, provided that attribute | ||
| # would be a "step up" from the current one (in terms of permissiveness). | ||
| # For example, if there is a "pdus" and an "icus" prediction, only consider "icus". | ||
| # And then only return it as the new rights if it would make the current rights less restrictive. | ||
| # | ||
| # Scenario where no prediction is allowed: | ||
| # |-----------| | ||
| # | 3 pd | <----- PREDICTION (cannot use, it is not the most restrictive) | ||
| # |-----------| | ||
| # | 2 pdus | <----- CURRENT RIGHTS | ||
| # |-----------| | ||
| # | 1 icus | <----- PREDICTION (cannot use, would be a downgrade) | ||
| # |-----------| | ||
| # | 0 ic | | ||
| # |-----------| | ||
| # | ||
| # Scenario where we do want a new prediction: | ||
| # |-----------| | ||
| # | 3 pd | <----- PREDICTION (cannot use, it is not the most restrictive) | ||
| # |-----------| | ||
| # | 2 pdus | <----- PREDICTION (USE THIS -- it is the most restrictive prediction, and better than icus) | ||
| # |-----------| | ||
| # | 1 icus | <----- CURRENT RIGHTS | ||
| # |-----------| | ||
| # | 0 ic | | ||
| # |-----------| | ||
| # | ||
| # In a nutshell: choose minimum prediction and return it if it is greater than current rights | ||
| # | ||
| # Note: there are rare but attested cases where we have legit pd/add and pd/exp predictions | ||
| # and the unordered hash implementation will, if pd is chosen, choose one at random. | ||
| # The old implementation did the same thing. KH has signed off on this as "don't care." | ||
| sub choose_rights_prediction { | ||
| my $self = shift; | ||
| my $attribute = shift; # current rights attr string | ||
| my $predictions = shift; | ||
|
|
||
| # This map allows us to grade the current rights and the predictions into 0-3 as above. | ||
| my $attr_values = {'pd' => 3, 'pdus' => 2, 'icus' => 1, 'ic' => 0}; | ||
|
|
||
| # Get the value for current rights. | ||
| # It should not be terribly unusual to find current rights outside the pd/pdus/icus/ic contionuum | ||
| # although we will filter many of these out with `are_rights_in_scope` above. | ||
| # However, that does allow through rights like und/nfi (at least historically, we no longer export | ||
| # these to the rights DB by default). | ||
| # We can bail out if we get something outside the expected main four attributes. | ||
| my $current_value = $attr_values->{$attribute}; | ||
| return unless defined $current_value; | ||
|
|
||
| # Expand predictions into array of { prediction => "attr/reason", value => value } | ||
| my @values = map { | ||
| my ($a, $r) = split('/', $_); | ||
| { prediction => $_, value => $attr_values->{$a} }; | ||
| } keys %$predictions; | ||
|
|
||
| # Extract out the "minimum" prediction, conflating undefs (unknown prediction) with ic, | ||
| # neither of which we can return as a viable choice. | ||
| my $min = List::Util::reduce { | ||
| ($a->{value} || 0) < ($b->{value} || 0) ? $a : $b; | ||
| } @values; | ||
|
|
||
| # Bail out if there were no predictions, or if the best we can do is ic or "anything else" | ||
| if (!$min || !$min->{value}) { | ||
| return; | ||
| } | ||
|
|
||
| # Compare the values. If the predicted is greater than current, return that. | ||
| # This will be the benefit of the new year rollover in terms of less restrictive rights. | ||
| if ($min->{value} > $current_value) { | ||
| return $min->{prediction}; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| 1; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.