Skip to content
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

DEV-616 Prediction report of non-bib items that should move back to a… #122

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions bin/bib_newyear.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BEGIN
use Data::Dumper;
use Encode;
use Getopt::Long qw(:config no_ignore_case bundling);
use JSON::XS;
use MARC::File::XML(BinaryEncoding => 'utf8');

use CRMS;
Expand Down Expand Up @@ -62,6 +63,7 @@ END
$year = $crms->GetTheYear() unless $year;

$ENV{BIB_RIGHTS_DATE} = $year if defined $year;
my $jsonxs = JSON::XS->new->utf8;

my $sql = 'SELECT r.namespace,r.id,a.name,rs.name FROM rights_current r'.
' INNER JOIN attributes a ON r.attr=a.id'.
Expand All @@ -72,11 +74,12 @@ END
"pdus/crms","pdus/gfv","pdus/ncn","pdus/ren","und/crms",
"und/nfi","und/ren")'.
' ORDER BY a.name,rs.name';

my $ref = $crms->SelectAllSDR($sql);
my $n = scalar @{$ref};

my @cols = ('HTID', 'Current rights/reason', "$year bib rights", 'date_used',
'pub place', 'us fed doc?', 'bib rights determination reason');
'pub place', 'us fed doc?', 'bib rights reason', 'ic/ren data');
my $fh;
if ($outfile) {
unless (open $fh, '>:encoding(UTF-8)', $outfile) {
Expand Down Expand Up @@ -120,9 +123,14 @@ END
($bri->{'attr'} eq 'pd' || ($bri->{'attr'} eq 'pdus' && $attr ne 'pd'))) {
my $bri_attr = $bri->{'attr'};
my $bri_reason = $bri->{'reason'};
my $ic_ren_data = '';
if ($attr eq 'ic' && $reason eq 'ren') {
$ic_ren_data = get_ic_ren_data($id);
}
my $line = join "\t", ($id, $attr. '/'. $reason, $bri->{'attr'},
$bri->{'date_used'}, $bri->{'pub_place'},
$bri->{'us_fed_doc'}, $bri->{'reason'});
$bri->{'us_fed_doc'}, $bri->{'reason'},
$ic_ren_data);
print $fh $line. "\n" if $fh;
flush $fh;
$changed++;
Expand All @@ -133,3 +141,34 @@ END

print "Warning: $_\n" for @{$crms->GetErrors()};

# Returns semicolon-delimited string of unique renDate values for all ic/ren determinations
sub get_ic_ren_data {
my $htid = shift;

my %data = ();
my $sql = 'SELECT gid FROM exportdata WHERE id=? AND attr="ic" AND reason="ren"' .
' ORDER BY time ASC';
my $determination_ref = $crms->SelectAll($sql, $htid);
foreach my $determination_row (@$determination_ref) {
my $gid = $determination_row->[0];
$sql = 'SELECT r.data FROM historicalreviews r' .
' INNER JOIN attributes a ON r.attr=a.id' .
' INNER JOIN reasons rs ON r.reason=rs.id '.
' WHERE a.name="ic"' .
' AND rs.name="ren"' .
' AND r.gid=?' .
' AND r.data IS NOT NULL' .
' AND r.validated!=0' .
' ORDER BY time ASC';
my $review_ref = $crms->SelectAll($sql, $gid);
foreach my $review_row (@$review_ref) {
my $reviewdata_id = $review_row->[0];
my $reviewdata_json = $crms->SimpleSqlGet('SELECT data FROM reviewdata WHERE id=?', $reviewdata_id);
my $reviewdata = $jsonxs->decode($reviewdata_json);
if ($reviewdata->{renDate}) {
$data{$reviewdata->{renDate}} = 1;
}
}
}
return join '; ', sort keys %data;
}
Loading