X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=html.pl;h=3bd0cf27e0d1948620c3dd035d3b1fd1aa5401e0;hb=b82e1b8518c8822be87978d8dda289e9c497e61a;hp=9873d9cb3bd67a1875d52eb8b160f48f984c0ff5;hpb=3fc7dbf7be19a4ebabe9d193486f2a6132ee0ced;p=koha-bibliografija
diff --git a/html.pl b/html.pl
index 9873d9c..3bd0cf2 100755
--- a/html.pl
+++ b/html.pl
@@ -14,12 +14,27 @@ use Carp qw(confess);
use utf8;
use JSON;
use POSIX qw(strftime);
+use Storable;
use lib '/srv/koha_ffzg';
use C4::Context;
use XML::LibXML;
use XML::LibXSLT;
+my $pid_file = '/dev/shm/bibliografija.pid';
+{
+ if ( -e $pid_file ) {
+ open(my $fh, '<', $pid_file);
+ my $pid = <$fh>;
+ no autodie; # it will die on kill
+ kill 0, $pid || die "$0 allready running as pid $pid";
+ }
+ open(my $fh, '>', $pid_file);
+ print $fh $$;
+ close($fh);
+}
+
+
my $dbh = C4::Context->dbh;
sub debug {
@@ -99,10 +114,11 @@ while( my $row = $sth_auth->fetchrow_hashref ) {
debug 'department_in_group' => $department_in_group;
foreach my $department ( keys %$department_in_sum ) {
- $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
+# $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
}
debug 'auth_department' => $auth_department;
+store $auth_department, '/dev/shm/auth_department.storable';
debug 'auth_group' => $auth_group;
debug 'department_in_sum' => $department_in_sum;
@@ -112,10 +128,11 @@ my $marcxml;
my $sth_select_authors = $dbh->prepare(q{
select
- biblionumber,
+ biblioitems.biblionumber,
itemtype,
- marcxml
+ metadata as marcxml
from biblioitems
+join biblio_metadata on (biblio_metadata.biblionumber = biblioitems.biblionumber)
where
agerestriction > 0
});
@@ -309,23 +326,33 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) {
$type_stats->{$type}++;
- if ( $type =~ m/(edt|trl|com|ctb)/ ) {
- push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
- push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber};
- } elsif ( $type =~ m/aut/ ) {
- if ( ! $have_100 ) {
- $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
- if ( $have_edt ) {
- $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
+ my @types = split(/[\s\/]+/, $type);
+
+ foreach my $type ( @types ) {
+ my $type = substr($type,0,3);
+ $type_stats->{_count_each_type}->{$type}++;
+
+ if ( $type =~ m/(edt|trl|com|ctb)/ ) {
+ push @{ $authors->{$authid}->{__sec}->{ $category } }, $row->{biblionumber};
+ push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber};
+ $type =~ s/(com|ctb)/_ostalo/;
+ push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber};
+
+ } elsif ( $type =~ m/aut/ ) {
+ if ( ! $have_100 ) {
+ $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
+ if ( $have_edt ) {
+ $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
+ } else {
+ push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
+ }
} else {
push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
}
} else {
- push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
+# warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
+ $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
}
- } else {
-# warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
- $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
}
}
delete $data->{700};
@@ -336,6 +363,7 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) {
}
debug 'authors' => $authors;
+store $authors, '/dev/shm/authors.storable';
debug 'type_stats' => $type_stats;
debug 'skip' => $skip;
debug 'biblio_year' => $biblio_year;
@@ -361,6 +389,7 @@ sub html_title {
|, join(" ", @_), qq|
+
|;
@@ -391,15 +420,19 @@ sub li_biblio {
qq|\n|;
}
+sub unique {
+ my $unique;
+ $unique->{$_}++ foreach @_;
+ return keys %$unique;
+}
+
sub unique_biblionumber {
- my @v = @_;
- my $u;
- $u->{$_}++ foreach @v;
+ my @v = unique @_;
return sort {
$biblio_year->{$b} <=> $biblio_year->{$a} ||
$biblio_full_name->{$a} cmp $biblio_full_name->{$b} ||
$a <=> $b
- } keys %$u;
+ } @v;
}
sub author_html {
@@ -407,26 +440,34 @@ sub author_html {
return unless exists $authors->{$authid}->{$type};
- print $fh qq|$label
\n|;
+ print $fh qq|$label
\n|;
foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
my $label = $category_label->{$category} || 'Bez kategorije';
- print $fh qq|$label
\n\n|;
+ print $fh qq|$label
\n\n|;
foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
print $fh li_biblio( $biblionumber );
}
- print $fh qq|
\n|;
+ print $fh qq|\n|;
}
}
+my @toc_type_label = (
+'aut' => 'Primarno autorstvo',
+'edt' => 'Uredništva',
+'trl' => 'Prijevodi',
+'_ostalo' => 'Ostalo',
+);
+
sub count_author_years {
my $years = shift;
my ($authid) = @_;
foreach my $type ( keys %{ $authors->{$authid} } ) {
+# next if $type =~ m/^_/; # FIXME
foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) {
- foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
- $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }++;
+ foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
+ $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++;
}
}
}
@@ -435,7 +476,9 @@ sub count_author_years {
sub html_year_selection {
my $fh = shift;
- my @authids = @_;
+ my @authids = unique @_;
+
+ debug 'html_year_selection authids=', [ @authids ];
print $fh qq|Godine:\n|;
my $type_cat_count = {};
@@ -445,10 +488,17 @@ sub html_year_selection {
$years = count_author_years( $years, $authid );
}
+ debug 'years' => $years;
+
foreach my $year ( sort { $b <=> $a } keys %$years ) {
print $fh qq| \n|;
foreach my $type_cat ( keys %{ $years->{$year} } ) {
- $type_cat_count->{ $type_cat } += $years->{$year}->{$type_cat};
+ my $count = scalar keys %{ $years->{$year}->{$type_cat} };
+ $years->{$year}->{$type_cat} = $count; # remove biblionumbers and use count
+ $type_cat_count->{ $type_cat } += $count;
+ my ($type,$cat) = split(/-/, $type_cat);
+ $type_cat_count->{_toc}->{$type}->{$cat}++;
+ $type_cat_count->{_toc_count}->{$type} += $count;
}
}
@@ -466,65 +516,33 @@ var years = |, encode_json($years), q|;
var type_cat_count = |, encode_json($type_cat_count), q|;
-function year_show(year) {
- $('.y'+year).show();
- console.debug('show', year);
- for(var type_cat in years[year]) {
- if ( ( type_cat_count[ type_cat ] += years[year][type_cat] ) == years[year][type_cat]) {
- $('a[name="'+type_cat+'"]').show();
- console.debug(type_cat, 'show');
- }
- }
-}
+
+
+ |;
-function year_hide(year) {
- $('.y'+year).hide();
- console.debug('hide', year);
- for(var type_cat in years[year]) {
- if ( ( type_cat_count[ type_cat ] -= years[year][type_cat] ) == 0 ) {
- $('a[name="'+type_cat+'"]').hide();
- console.debug(type_cat, 'hide');
+ debug 'type_cat_count' => $type_cat_count;
+
+ # TOC
+ print $fh qq|\n|;
+ my $i = 0;
+ while ( $i < $#toc_type_label ) {
+ my $type = $toc_type_label[$i++] || die "type";
+ my $label = $toc_type_label[$i++] || die "label";
+ next unless exists $type_cat_count->{_toc}->{$type};
+ print $fh qq| - $label $type_cat_count->{_toc_count}->{$type}
\n \n|;
+ foreach my $category ( sort keys %{ $type_cat_count->{_toc}->{$type} } ) {
+ my $label = $category_label->{$category} || 'Bez kategorije';
+ my $count = $type_cat_count->{ $type . '-' . $category };
+ my $cat_html = $category;
+ $cat_html =~ s/\./-/g;
+ print $fh qq| - $label $count
\n|;
}
+ print $fh qq|
\n|;
}
-}
+ print $fh qq|
\n|;
-function toggle_year(year, el) {
- if ( el.checked ) {
- year_show(year);
- } else {
- year_hide(year);
- }
}
-function all_years( turn_on ) {
- $('input[name=year_selection]').each( function(i,el) {
- if ( turn_on ) {
- if ( ! el.checked ) {
- el.checked = true;
- year_show( el.value );
- }
- } else {
- if ( el.checked ) {
- el.checked = false;
- year_hide( el.value );
- }
- }
- } );
-}
-
-$(document).ready( function() {
- console.info('ready');
-
- $('input[name=year_selection]').each( function(i, el) {
- var year = el.value;
- console.debug( 'on load', year, el.checked );
- if (! el.checked) year_hide(year);
- });
-
-});
-
- |;
-}
foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
@@ -543,8 +561,12 @@ foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
html_year_selection $fh => $row->{authid};
- author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
- author_html( $fh, $row->{authid}, 'sec' => 'UredniÅ¡tva, prijevodi, kriÄka izdanja' );
+ my $i = 0;
+ while ( $i < $#toc_type_label ) {
+ my $type = $toc_type_label[$i++] || die "type";
+ my $label = $toc_type_label[$i++] || die "label";
+ author_html( $fh, $row->{authid}, $type => $label );
+ }
print $fh html_end;
close($fh);
@@ -563,7 +585,7 @@ my $department_category_author;
foreach my $department ( sort keys %$auth_department ) {
foreach my $authid ( sort @{ $auth_department->{$department} } ) {
my @categories = keys %{ $authors->{$authid}->{aut} };
- push @categories, keys %{ $authors->{$authid}->{sec} };
+ push @categories, keys %{ $authors->{$authid}->{__sec} };
foreach my $category ( sort @categories ) {
push @{ $department_category_author->{$department}->{$category} }, $authid;
push @{ $department_category_author->{'AAA_ukupno'}->{$category} }, $authid if $department_in_sum->{$department};
@@ -580,9 +602,9 @@ debug 'department_category_author' => $department_category_author;
sub department_html {
- my ( $fh, $department, $type, $label ) = @_;
+ my ( $fh, $department, $type, $label, $csv_fh ) = @_;
- print $fh qq|$label
\n|;
+ print $fh qq|$label
\n|;
foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
@@ -593,12 +615,36 @@ sub department_html {
next unless @biblionumber;
- my $label = $category_label->{$category} || 'Bez kategorije';
- print $fh qq|$label
\n|;
+ my $year = $li[1];
+ my @html;
+ foreach ( split(/}{} ) {
+ my $nr = $1;
+ s{\s+}{ }gs;
+ $html[$nr] = $_;
+ } else {
+ warn "SKIPPED: Can't find col in [$_] from $li[4]" unless m/^<[^>]+>$/;
+ }
+ }
+ my $html = join("\t", @html);
+
+ $html =~ s{?[^>]*>}{}gs;
+ $html =~ s{\s+$}{}gs;
+ print $csv_fh "$bib_num\t$year\t$type\t$label\t$category\t$cat_label\t$html\n";
+ }
+
+ print $fh qq||;
}
}
@@ -607,7 +653,7 @@ sub department_html {
mkdir 'html/departments' unless -d 'html/departments';
open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
-print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|\n|;
+print $dep_fh html_title('Odsjeci Filozofskog fakulteta u Zagrebu'), qq|\n|;
foreach my $department ( sort keys %$department_category_author ) {
my $dep = $department || 'Nema odsjeka';
my $dep_file = unac_string('utf-8',$dep);
@@ -623,13 +669,24 @@ foreach my $department ( sort keys %$department_category_author ) {
}
html_year_selection $fh => @authids;
- department_html( $fh, $department, 'aut', 'Primarno autorstvo' );
+ my $csv_fh;
+ if ( $department eq 'AAA_ukupno' ) {
+ open($csv_fh, '>:encoding(utf-8)', "html/departments/$department.csv");
+ }
- department_html( $fh, $department, 'sec', 'Sekundarno autorstvo' );
+ my $i = 0;
+ while ( $i < $#toc_type_label ) {
+ my $type = $toc_type_label[$i++] || die "type";
+ my $label = $toc_type_label[$i++] || die "label";
+ department_html( $fh, $department, $type, $label, $csv_fh );
+ }
+
+ close($csv_fh) if $csv_fh;
print $fh html_end;
close($fh);
rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
+
}
print $dep_fh qq|
\n|, html_end;
close($dep_fh);
@@ -704,12 +761,9 @@ sub table_count {
my $label = shift @_;
my $department = shift @_;
my $group = shift @_;
- my @biblionumbers = @_;
- my $unique;
- $unique->{$_}++ foreach @biblionumbers;
- my @bibs = keys %$unique;
- $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @bibs;
- $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @bibs;
+ my @biblionumbers = unique @_;
+ $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @biblionumbers;
+ $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @biblionumbers;
}
foreach my $group ( '', keys %$azvo_group_title ) {
@@ -801,3 +855,5 @@ close($fh2);
rename 'html/azvo.new', 'html/azvo.html';
rename 'html/azvo2.new', 'html/azvo2.html';
+unlink $pid_file;
+