install-osrf.sh: set ejabberd host correctly during registration on prod
[sitka/sitka-tools.git] / marc_export_custom / stats-distribution.pl
1 #!/usr/bin/perl
2 use MARC::Batch;
3 use strict;
4 use warnings;
5 my $batch = MARC::Batch->new( 'USMARC', @ARGV );
6 $batch->strict_off();
7 $batch->warnings_off();
8 my %bibs;
9 my %holdings;
10 my $count_raw = 0;
11 my $count_copies = 0;
12 my $count_901c = 0;
13 while ( my $marc = $batch->next ) {
14         $count_raw++;
15         my $field_901c = $marc->subfield(901,"c");
16         if(defined $field_901c) {
17                 chomp $field_901c;
18                 $count_901c++ if ($field_901c =~ /^.+$/);
19         }
20
21         my @field_852 = $marc->field(852);
22         my %holding_libs;
23         if(@field_852) {
24                 FIELD852: foreach my $my852 (@field_852) {
25                         my $my852b = $my852->subfield('b');
26                         next FIELD852 unless (defined $my852b and $my852b =~ /^.+$/);
27                         chomp $my852b;
28                         $holdings{$my852b} = 0 unless exists($holdings{$my852b});
29                         $holdings{$my852b}++;
30                         $holding_libs{$my852b} = 1;
31                 }
32         }
33         foreach(keys %holding_libs) {
34                 $bibs{$_} = 0 unless exists($bibs{$_});
35                 $bibs{$_}++;
36         }
37 }
38
39 foreach my $lib (sort keys %bibs) {
40         printf("bibs,%s,%d\n",$lib,$bibs{$lib});
41 }
42 foreach my $lib (sort keys %holdings) {
43         printf("copies,%s,%d\n",$lib,$holdings{$lib});
44         $count_copies += $holdings{$lib};
45 }
46
47 printf "summary,distinct-bibs-raw,%d\n",$count_raw;
48 printf "summary,distinct-bibs-901c,%d\n",$count_901c;
49 printf "summary,distinct-copies,%d\n",$count_copies;
50
51
52 # vim: ts=2 sw=2