[open-ils-commits] [GIT] Evergreen ILS branch rel_2_3 updated. c0a79af1509d3b770c3a919020a515dbc1e2caa0

Evergreen Git git at git.evergreen-ils.org
Fri Aug 9 11:22:37 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_3 has been updated
       via  c0a79af1509d3b770c3a919020a515dbc1e2caa0 (commit)
       via  68c1bf0152750e3d085d24bea7c9a47b80e5189a (commit)
       via  12d88a006c06015e9bba5de483af6b987722ee7f (commit)
       via  df0d0704534db44eab4cb7a4b414510c61b21c40 (commit)
      from  9717addcd5221e594df9c9025e9c3e51475b6db3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c0a79af1509d3b770c3a919020a515dbc1e2caa0
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue Jul 2 11:55:21 2013 -0400

    Solidify caption/holding relationship, improve MFHD::Holding comparisons
    
    [This commit has been squashed for merging. LFW]
    
      * This commit:
        - Makes sure that holding data is valid for the given caption
          for new holding objects
        - Teaches field_values() to fall back to '*' (unknown marker)
          when a holding is missing data
        - Allows the caption() method to be a setter
    
      * This commit:
        - Makes the comparison operator consider chron data, not just
          enumeration data
        - Teaches the comparison operator a way to handle 'unsure' data
          (that is, data presented in brackets [])
    
      * The code was assuming the $end_holding param would be uncompressed,
        but this was not stated anywhere, nor enforced.  Let's allow the
        method to take both compressed and uncompressed holdings as the "end"
        (and handle it appropriately).
    
      * Add some holdings with missing and unsure data to test the new
        comparison operators handling of such data.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm
index 920bfd2..37f985a 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm
@@ -42,6 +42,9 @@ sub new {
             if (exists($self->{_mfhdh_FIELDS}->{$key})) {
                 carp("Duplicate, non-repeatable subfield '$key' found, ignoring");
                 next;
+            } elsif (!$caption->capfield($key)) {
+                carp("Subfield '$key' has no corresponding caption, ignoring");
+                next;
             }
             if ($self->{_mfhdh_COMPRESSED}) {
                 $self->{_mfhdh_FIELDS}->{$key}{HOLDINGS} = [split(/\-/, $val, -1)];
@@ -116,8 +119,15 @@ sub field_values {
     if (exists $self->fields->{$key}) {
         my @values = @{$self->fields->{$key}{HOLDINGS}};
         return \@values;
+    } elsif ($self->caption->capfield($key)) {
+        carp("No values found for existing caption subfield '$key', returning '*' (unknown value indicator)");
+        if ($self->is_compressed) {
+            return ['*', '*'];
+        } else {
+            return ['*'];
+        }
     } else {
-        return undef;
+        return;
     }
 }
 
@@ -161,6 +171,11 @@ sub is_open_ended {
 
 sub caption {
     my $self = shift;
+    my $caption = shift;
+
+    if ($caption) {
+        $self->{_mfhdh_CAPTION} = $caption;
+    }
 
     return $self->{_mfhdh_CAPTION};
 }
@@ -625,12 +640,18 @@ sub compressed_to_last {
 #
 # Creates or replaces an end of a compressed holding
 #
+# If $end_holding does not share caption data with $self, results
+# will be unpredicable
+#
 sub compressed_end {
     my $self = shift;
     my $end_holding = shift;
 
     my %changes;
-    if ($end_holding) {
+    if ($end_holding and !$end_holding->is_open_ended) {
+        if ($end_holding->is_compressed) {
+            $end_holding = $end_holding->clone->compressed_to_last;
+        }
         foreach my $key (keys %{$self->fields}) {
             my @values = @{$self->field_values($key)};
             my @end_values = @{$end_holding->field_values($key)};
@@ -638,7 +659,7 @@ sub compressed_end {
             $self->fields->{$key}{HOLDINGS} = \@values;
             $changes{$key} = join('-', @values);
         }
-    } elsif (!$self->is_open_ended) { # make open-ended if no $end_holding
+    } elsif (!$self->is_open_ended) { # make open-ended if no $end_holding (or $end_holding was open ended)
         foreach my $key (keys %{$self->fields}) {
             my @values = @{$self->field_values($key)};
             $self->fields->{$key}{HOLDINGS} = [$values[0]];
@@ -883,12 +904,19 @@ sub _compare {
 
     # start doing the actual comparison
     my $result;
-    foreach my $key ('a'..'f') {
+    foreach my $key ('a'..'f', 'i'..'m') {
         if (defined($holding_1->field_values($key))) {
             if (!defined($holding_2->field_values($key))) {
                 return 1; # more details equals 'greater' (?)
             } else {
-                $result = $holding_1->field_values($key)->[0] <=> $holding_2->field_values($key)->[0];
+                my $holding_1_value = $holding_1->field_values($key)->[0];
+                my $holding_1_unsure = ($holding_1_value =~ s/\[|\]//g);
+                my $holding_2_value = $holding_2->field_values($key)->[0];
+                my $holding_2_unsure = ($holding_2_value =~ s/\[|\]//g);
+                $result = $holding_1_value <=> $holding_2_value;
+                if (!$result) { # they are 'equal' but we will sort 'maybe' values before 'sure' values (TODO: rethink this is it complicates some algorithms)
+                    $result = $holding_2_unsure <=> $holding_1_unsure;
+                }
             }
         } elsif (defined($holding_2->field_values($key))) {
             return -1; # more details equals 'greater' (?)
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
index 65a6fe8..41560c2 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
@@ -50,25 +50,29 @@
 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
 863 40 $81.1$a1$b4-7$i1990$j04-07
 863 40 $81.2$a1$b4-7$i1990$j04-07
-863 41 $81.3$a1$b4$i1990$j04
+863 41 $81.3$a1$b4$i1990$j[04]
 863 41 $81.4$a1$b4$i1990$j04
-863 40 $81.5$a1-$b3-$i1990-$j03-
-863 40 $81.6$a1$b3-6$i1990$j03-06
-863 40 $81.7$a1$b3-5$i1990$j03-05
-863 41 $81.8$a1$b3$i1990$j03
-863 41 $81.9$a1$b2$i1990$j02
+863 41 $81.5$a1$b4$i1990$j[04]
+863 40 $81.6$a1-$b3-$i1990-$j03-
+863 40 $81.7$a1$b3-6$i1990$j03-06
+863 40 $81.8$a1$b3-5$i1990$j03-05
+863 41 $81.9$a1$b3$i1990$j03
+863 41 $81.10$a1$b2$i1990$j02
+863 41 $81.11$a1$b2$i1990
 
 245 00 $aComparison test, sorted
 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
-863 41 $81.1$a1$b2$i1990$j02
-863 41 $81.2$a1$b3$i1990$j03
-863 40 $81.3$a1$b3-5$i1990$j03-05
-863 40 $81.4$a1$b3-6$i1990$j03-06
-863 40 $81.5$a1-$b3-$i1990-$j03-
-863 41 $81.6$a1$b4$i1990$j04
-863 41 $81.7$a1$b4$i1990$j04
-863 40 $81.8$a1$b4-7$i1990$j04-07
-863 40 $81.9$a1$b4-7$i1990$j04-07
+863 41 $81.1$a1$b2$i1990$j*
+863 41 $81.2$a1$b2$i1990$j02
+863 41 $81.3$a1$b3$i1990$j03
+863 40 $81.4$a1$b3-5$i1990$j03-05
+863 40 $81.5$a1$b3-6$i1990$j03-06
+863 40 $81.6$a1-$b3-$i1990-$j03-
+863 41 $81.7$a1$b4$i1990$j[04]
+863 41 $81.8$a1$b4$i1990$j[04]
+863 41 $81.9$a1$b4$i1990$j04
+863 40 $81.10$a1$b4-7$i1990$j04-07
+863 40 $81.11$a1$b4-7$i1990$j04-07
 
 245 00 $aGet combined holdings
 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01

commit 68c1bf0152750e3d085d24bea7c9a47b80e5189a
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Wed May 8 15:09:41 2013 -0400

    Fix logic in get_compressed_holdings()
    
    [This commit has been squashed for merging. LFW]
    
      * This commit rearranges some of the logic branches to protect
        against an unusual case of having two holding statements with
        the same start value, but one being open-ended and one not.
    
      * The logic in get_combined_holdings() was a little sloppy and
        repeated some steps unnecessarily.  This cleans things up.
    
        See the test case in the previous commit for more clarity.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
index dff0066..03975cf 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
@@ -390,10 +390,8 @@ sub get_compressed_holdings {
         if ($runner eq $holding) {
             $curr_holding->extend;
             $runner->increment;
-        } elsif ($runner gt $holding) { # should not happen unless holding is not in series
-            carp("Found unexpected holding, skipping");
         } elsif ($holding->is_open_ended) { # special case, as it will always be the last
-            if ($runner eq $holding->clone->compressed_to_first) {
+            if ($runner ge $holding->clone->compressed_to_first) {
                 $curr_holding->compressed_end();
             } else {
                 push(@comp_holdings, $curr_holding);
@@ -402,6 +400,8 @@ sub get_compressed_holdings {
                 $curr_holding->seqno($seqno);
             }
             last;
+        } elsif ($runner gt $holding) { # should not happen unless holding is not in series
+            carp("Found unexpected holding, skipping");
         } else {
             push(@comp_holdings, $curr_holding);
 
@@ -550,12 +550,20 @@ sub get_combined_holdings {
                 $combined_holdings[-1]->clone->compressed_to_last
                 : $combined_holdings[-1]->clone;
 
+            # next, get the end (or only) holding of the current
+            # holding being considered
+            my $holding_end;
+            if ($holding->is_compressed) {
+                $holding_end = $holding->is_open_ended ?
+                undef
+                : $holding->clone->compressed_to_last;
+            } else {
+                $holding_end = $holding;
+            }
+
             # next, make sure $holding isn't fully contained
-            my $holding_end = $holding->is_compressed ?
-                $holding->clone->compressed_to_last
-                : $holding;
-            # if $holding is fully contained, skip it
-            if ($holding_end le $last_holding_end) {
+            # if it is, skip it
+            if ($holding_end and $holding_end le $last_holding_end) {
                 next;
             }
 
@@ -564,16 +572,9 @@ sub get_combined_holdings {
                 $holding->clone->compressed_to_first
                 : $holding;
 
+            # see if they overlap
             if ($last_holding_end->increment ge $holding_start) {
                 # they overlap, combine them
-                my $holding_end;
-                if ($holding->is_compressed) {
-                    $holding_end = $holding->is_open_ended ?
-                    undef
-                    : $holding->compressed_to_last;
-                } else {
-                    $holding_end = $holding;
-                }
                 $combined_holdings[-1]->compressed_end($holding_end);
             } else {
                 # no overlap, start a new group

commit 12d88a006c06015e9bba5de483af6b987722ee7f
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue May 7 18:23:27 2013 -0400

    Tie in new MFHD method to serials module/MFHD tests for compressing, combining
    
    [This commit has been squashed for merging. LFW]
    
     *  Now that we have a potentially better alternative, let's call
        get_combined_holdings() in place of get_compressed_holdings() in
        Serial.pm.
    
     *  First, add a test for the new get_combined_holdings() method.
    
        Second, add a known problem case for get_compressed_holdings().
        The fix will come in a subsequent commit.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
index 6425257..71fc560 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
@@ -1899,10 +1899,10 @@ sub _summarize_contents {
     foreach my $scap_field (@scap_fields_ordered) { #TODO: use generic MFHD "summarize" method, once available
         my @updated_holdings;
         eval {
-            @updated_holdings = $mfhd->get_compressed_holdings($scap_field);
+            @updated_holdings = $mfhd->get_combined_holdings($scap_field);
         };
         if ($@) {
-            my $msg = "get_compressed_holdings(): $@ ; using sdist ID #" .
+            my $msg = "get_combined_holdings(): $@ ; using sdist ID #" .
                 ($sdist ? $sdist->id : "<NONE>") . " and " .
                 scalar(@$issuances) . " issuances, of which one has ID #" .
                 $issuances->[0]->id;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhd.t b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhd.t
index 29ee865..97e64fd 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhd.t
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhd.t
@@ -89,6 +89,18 @@ $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
 is_deeply($holdings_a[0]->compressed_to_last, $holdings_b[0], 'compressed to last, normal');
 is($holdings_a[1]->compressed_to_last, undef, 'compressed to last, open ended');
 
+# test: get compressed holdings
+$testno++;
+
+$rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
+$rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
+
+ at holdings_a = $rec->get_compressed_holdings(($rec->captions('853'))[0]);
+ at holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
+
+is_deeply(\@holdings_a, \@holdings_b, 'get compressed holdings');
+
+
 # test: get compressed holdings, open ended member
 $testno++;
 
@@ -126,5 +138,17 @@ foreach my $holding (@holdings_a) {
 
 is_deeply(\@holdings_a, \@holdings_b, 'comparison testing via sort');
 
+# test: get combined holdings
+$testno++;
+
+$rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
+$rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
+
+ at holdings_a = $rec->get_combined_holdings(($rec->captions('853'))[0]);
+ at holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
+
+is_deeply(\@holdings_a, \@holdings_b, 'get combined holdings');
+
+
 close $testdata;
 1;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
index a450bb4..65a6fe8 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/test/mfhddata2.txt
@@ -19,6 +19,22 @@
 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
 863 41 $81.1$a1$b8$i1990$j08
 
+245 00 $aGet compressed holdings
+853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
+863 40 $81.1$a1$b1-4$i1990$j01-04
+863 40 $81.2$a1$b2-3$i1990$j02-03
+863 40 $81.3$a1$b6-7$i1990$j06-07
+863 41 $81.4$a1$b8$i1990$j08
+863 41 $81.5$a1$b10$i1990$j10
+863 40 $81.6$a1-$b10-$i1990-$j10-
+863 41 $81.7$a1$b12$i1990$j12
+
+245 00 $aGet compressed holdings, result
+853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
+863 40 $81.1$a1$b1-4$i1990$j01-04
+863 40 $81.2$a1$b6-8$i1990$j06-08
+863 40 $81.3$a1-$b10-$i1990-$j10-
+
 245 00 $aGet compressed holdings, open ended member
 853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
 863 41 $81.1$a1$b4$i1990$j04
@@ -54,4 +70,19 @@
 863 40 $81.8$a1$b4-7$i1990$j04-07
 863 40 $81.9$a1$b4-7$i1990$j04-07
 
+245 00 $aGet combined holdings
+853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
+863 40 $81.1$a1$b1-4$i1990$j01-04
+863 40 $81.2$a1$b2-3$i1990$j02-03
+863 40 $81.3$a1$b6-7$i1990$j06-07
+863 41 $81.4$a1$b8$i1990$j08
+863 41 $81.5$a1$b10$i1990$j10
+863 40 $81.6$a1-$b10-$i1990-$j10-
+863 41 $81.7$a1$b12$i1990$j12
+
+245 00 $aGet combined holdings, result
+853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
+863 40 $81.1$a1$b1-4$i1990$j01-04
+863 40 $81.2$a1$b6-8$i1990$j06-08
+863 40 $81.3$a1-$b10-$i1990-$j10-
 

commit df0d0704534db44eab4cb7a4b414510c61b21c40
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Tue May 7 18:19:34 2013 -0400

    Add new get_combined_holdings() method to MFHD.pm
    
    This commit adds a new method to the MFHD module which creates an
    array of compressed holdings from all holdings for a given caption,
    combining as needed.
    
    NOTE: This method is similar to, but much less aggressive/strict than
    get_compressed_holdings(). Ultimately, get_compressed_holdings()
    might be deprecated in favor of this.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
index 32ea066..dff0066 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm
@@ -502,6 +502,90 @@ sub get_decompressed_holdings {
     return @return_holdings;
 }
 
+#
+# create an array of compressed holdings from all holdings for a given caption,
+# combining as needed
+#
+# NOTE: this sub is similar to, but much less aggressive/strict than
+# get_compressed_holdings(). Ultimately, get_compressed_holdings() might be
+# deprecated in favor of this
+#
+# TODO: gap marking, gap preservation
+#
+# TODO: some of this could be moved to the Caption (and/or Holding) object to
+# allow for combining in the absense of an overarching MFHD object
+#
+sub get_combined_holdings {
+    my $self = shift;
+    my $caption = shift;
+
+    my @holdings = $self->holdings_by_caption($caption);
+    return () if !@holdings;
+
+    # basic check for necessary pattern information
+    if (!scalar keys %{$caption->pattern}) {
+        carp "Cannot combine without pattern data, returning original holdings";
+        return @holdings;
+    }
+
+    my @sorted_holdings = sort {$a cmp $b} @holdings;
+
+    my @combined_holdings = (shift(@sorted_holdings));
+    my $seqno = 1;
+    $combined_holdings[0]->seqno($seqno);
+    foreach my $holding (@sorted_holdings) {
+        # short-circuit: if we hit an open-ended holding,
+        # it 'includes' all the rest, so just exit the loop
+        if ($combined_holdings[-1]->is_open_ended) {
+            last;
+        } elsif ($holding eq $combined_holdings[-1]) {
+            # duplicate, skip
+            next;
+        } else {
+            # at this point, we know that $holding is gt $combined_holdings[-1]
+            # we just need to figure out if they overlap or not
+
+            # first, get the end (or only) holding of [-1]
+            my $last_holding_end = $combined_holdings[-1]->is_compressed ?
+                $combined_holdings[-1]->clone->compressed_to_last
+                : $combined_holdings[-1]->clone;
+
+            # next, make sure $holding isn't fully contained
+            my $holding_end = $holding->is_compressed ?
+                $holding->clone->compressed_to_last
+                : $holding;
+            # if $holding is fully contained, skip it
+            if ($holding_end le $last_holding_end) {
+                next;
+            }
+
+            # now, get the beginning (or only) holding of $holding
+            my $holding_start = $holding->is_compressed ?
+                $holding->clone->compressed_to_first
+                : $holding;
+
+            if ($last_holding_end->increment ge $holding_start) {
+                # they overlap, combine them
+                my $holding_end;
+                if ($holding->is_compressed) {
+                    $holding_end = $holding->is_open_ended ?
+                    undef
+                    : $holding->compressed_to_last;
+                } else {
+                    $holding_end = $holding;
+                }
+                $combined_holdings[-1]->compressed_end($holding_end);
+            } else {
+                # no overlap, start a new group
+                $holding->seqno(++$seqno);
+                push(@combined_holdings, $holding);
+            }
+        }
+    }
+
+    return @combined_holdings;
+}
+
 ##
 ## close any open-ended holdings which are followed by another holding by
 ## combining them

-----------------------------------------------------------------------

Summary of changes:
 .../src/perlmods/lib/OpenILS/Application/Serial.pm |    4 +-
 Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD.pm    |   91 +++++++++++++++++++-
 .../src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm |   38 +++++++-
 .../perlmods/lib/OpenILS/Utils/MFHD/test/mfhd.t    |   24 +++++
 .../lib/OpenILS/Utils/MFHD/test/mfhddata2.txt      |   65 +++++++++++---
 5 files changed, 197 insertions(+), 25 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list