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… #119

Merged
merged 1 commit into from
Nov 30, 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
60 changes: 9 additions & 51 deletions bin/bib_newyear.pl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ BEGIN
use Encode;
use Getopt::Long qw(:config no_ignore_case bundling);
use MARC::File::XML(BinaryEncoding => 'utf8');
use Term::ANSIColor qw(:constants colored);

use CRMS;
use bib_rights;

$Term::ANSIColor::AUTORESET = 1;
binmode(STDOUT, ':encoding(UTF-8)');
my $usage = <<END;
USAGE: $0 [-hpv] [-o FILE] [-y YEAR]
Expand All @@ -30,7 +28,7 @@ BEGIN
NOTE: this is a long-running script -- should be invoked in a screen(1) session.

-h Print this help message.
-o FILE Write or append report on new determinations to FILE.
-o FILE Write report on new determinations to FILE.
-p Run in production.
-v Emit verbose debugging information. May be repeated.
-y YEAR Use this year instead of the current one.
Expand All @@ -39,7 +37,6 @@ END

my $help;
my $instance;
my $noop;
my $outfile;
my $production;
my $verbose;
Expand All @@ -56,9 +53,8 @@ END
if ($help) { print $usage. "\n"; exit(0); }

my $crms = CRMS->new(
sys => 'crmsworld',
verbose => $verbose,
instance => $instance
verbose => $verbose,
instance => $instance
);

$verbose = 0 unless defined $verbose;
Expand All @@ -78,66 +74,28 @@ END
' ORDER BY a.name,rs.name';
my $ref = $crms->SelectAllSDR($sql);
my $n = scalar @{$ref};
my $last_processed;
my $last_processed_seen;

my @cols = ('HTID', 'Current rights/reason', "$year bib rights", 'date_used',
'pub place', 'us fed doc?', 'bib rights determination reason');

my $fh;
my $exists;
my $changed = 0;
if ($outfile && -f $outfile) {
$exists = -f $outfile;
unless (open $fh, '<:encoding(UTF-8)', $outfile) {
die ("failed to read file at $outfile: ". $!);
}
read $fh, my $buff, -s $outfile;
close $fh;
my @lines = split "\n", $buff;
shift @lines;
foreach my $line (@lines) {
my @fields = split "\t", $line;
if (scalar @fields == scalar @cols) {
#printf "Marking %s as last processed.\n", $fields[0];
$last_processed = $fields[0];
}
else {
printf "NOT MARKING %s SINCE %s != %s\n", $fields[0], scalar @fields, scalar @cols;
}
$changed++;
}
}

print "LAST PROCESSED: $last_processed\n" if $last_processed;

if ($outfile) {
unless (open $fh, '>>:encoding(UTF-8)', $outfile) {
die ("failed to read file at $outfile: ". $!);
unless (open $fh, '>:encoding(UTF-8)', $outfile) {
die ("failed to create file at $outfile: ". $!);
}
printf $fh "%s\n", join("\t", @cols) unless $exists;
printf $fh "%s\n", join("\t", @cols);
flush $fh;
}

my $i = 0;
my $changed = 0;

my $br = bib_rights->new();
my $of = scalar @$ref;
print "Checking $of items\n";
print "Checking $of items\n" if $verbose;
foreach my $row (@{$ref}) {
$i++;
print "$i/$of ($changed)\n" if $i % 1000 == 0;
print "$i/$of ($changed)\n" if $i % 1000 == 0 && $verbose;
my $id = $row->[0]. '.'. $row->[1];
if ($last_processed) {
if ($last_processed eq $id) {
print "=== LAST PROCEDDED $id ===\n";
$last_processed_seen = 1;
next;
}
unless ($last_processed_seen) {
next;
}
}
my $attr = $row->[2];
my $reason = $row->[3];
my $record = $crms->GetMetadata($id);
Expand Down