X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=html.pl;h=11a47a0cd9d8c7ac0621401e4d74e246a2001de9;hb=f9cb8cc0e3f47e3cc928fc092363ad9f44fb6c42;hp=2110ca418a8a8b68d09837c5cf28b313d4057539;hpb=90af0306faca65330adc4fbe1d3e8a506f204a69;p=koha-bibliografija diff --git a/html.pl b/html.pl index 2110ca4..11a47a0 100755 --- a/html.pl +++ b/html.pl @@ -12,6 +12,9 @@ use locale; use Text::Unaccent; use Carp qw(confess); use utf8; +use JSON; +use POSIX qw(strftime); +use Storable; use lib '/srv/koha_ffzg'; use C4::Context; @@ -28,14 +31,14 @@ sub debug { my $xslfilename = 'compact.xsl'; my $azvo_group_title = { -'znanstveno nastavni' => qr/(profesor|docent|znanstveni)/i, +'znanstveno nastavni' => qr/(profes|docent|znanstveni savjetnik|znanstveni suradnik)/i, 'lektori i predavači' => qr/(lektor|predavač)/i, 'asistenti i novaci' => qr/(asistent|novak)/i, }; my $department_groups = { -'AAA_humanističke' => qr/(anglistiku|arheologiju|antropologiju|filozofiju|fonetiku|germanistiku|hungarologiju|indologiju|slavenske|filologiju|komparativnu|kroatistiku|lingvistiku|povijest|romanistiku|talijanistiku)/i, -'AAB_društvene' => qr/(informacijske|pedagogiju|psihologiju|sociologiju)/i, +'AAB_humanističke' => qr/(anglistiku|arheologiju|antropologiju|filozofiju|fonetiku|germanistiku|hungarologiju|indologiju|slavenske|filologiju|komparativnu|kroatistiku|lingvistiku|povijest|romanistiku|talijanistiku)/i, +'AAC_društvene' => qr/(informacijske|pedagogiju|psihologiju|sociologiju)/i, }; my $auth_header; @@ -101,6 +104,7 @@ foreach my $department ( keys %$department_in_sum ) { } 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; @@ -128,6 +132,7 @@ where =cut my $biblio_year; +my $biblio_full_name; my $type_stats; my $parser = XML::LibXML->new(); @@ -198,6 +203,7 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { my $extract = { '008' => undef, '100' => '(9|a)', + '245' => 'a', '680' => 'i', '700' => '(9|4|a)', '942' => '(t|r|v)' @@ -234,15 +240,19 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { } } push @{ $data->{$tag} }, $sf_data if $sf_data; - } - } + } + } - if ( $data->{year} < 2008 ) { + if ( ! defined $data->{year} ) { + warn "MISSING year in ", $row->{biblionumber}; +=for remove-year-limit + } elsif ( $data->{year} < 2008 ) { push @{ $skip->{year_lt_2008} }, $row->{biblionumber}; next; } elsif ( $data->{year} > 2013 ) { push @{ $skip->{year_gt_2013} }, $row->{biblionumber}; next; +=cut } # warn "# ", $row->{biblionumber}, " data ",dump($data); @@ -273,10 +283,13 @@ while( my $row = $sth_select_authors->fetchrow_hashref ) { foreach my $authid ( @first_author ) { push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber}; } + $biblio_full_name->{ $row->{biblionumber} } = $data->{100}->[0]->{a}; } else { $have_100 = 0; } + $biblio_full_name->{ $row->{biblionumber} } ||= $data->{245}->[0]->{a}; + my $have_edt; if ( exists $data->{700} ) { @@ -298,23 +311,32 @@ 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 ) { + $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}; @@ -325,9 +347,11 @@ 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; +debug 'biblio_full_name' => $biblio_full_name; debug 'biblio_data' => $biblio_data; debug 'biblio_author_external' => $biblio_author_external; @@ -348,13 +372,17 @@ sub html_title { |, join(" ", @_), qq| + |; } sub html_end { - return qq|\n\n|; + return + qq|Zadnji puta osvježeno: |, + strftime("%Y-%m-%d %H:%M:%S\n", localtime()), + qq|\n\n|; } mkdir 'html' unless -d 'html'; @@ -368,13 +396,24 @@ debug 'authors' => \@authors; sub li_biblio { my ($biblionumber) = @_; - return qq|
  • |, + return qq|
  • |, qq|$biblionumber|, biblioitem_html($biblionumber), qq|edit|, qq|
  • \n|; } +sub unique_biblionumber { + my @v = @_; + my $u; + $u->{$_}++ foreach @v; + return sort { + $biblio_year->{$b} <=> $biblio_year->{$a} || + $biblio_full_name->{$a} cmp $biblio_full_name->{$b} || + $a <=> $b + } keys %$u; +} + sub author_html { my ( $fh, $authid, $type, $label ) = @_; @@ -384,14 +423,121 @@ sub author_html { foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) { my $label = $category_label->{$category} || 'Bez kategorije'; - print $fh qq|

    $label

    \n\n|; + print $fh qq|\n|; + } +} + + +sub count_author_years { + my $years = shift; + my ($authid) = @_; + foreach my $type ( keys %{ $authors->{$authid} } ) { + foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) { + foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) { + $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }++; + } + } + } + return $years; +} + +sub html_year_selection { + my $fh = shift; + my @authids = @_; + + print $fh qq|Godine:\n|; + my $type_cat_count = {}; + my $years; + + foreach my $authid ( @authids ) { + $years = count_author_years( $years, $authid ); + } + + 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}; + } + } + + print $fh qq| + + + |; + + print $fh qq||; + + print $fh q| + + |; +} + foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) { my $first = substr( $row->{full_name}, 0, 1 ); @@ -405,10 +551,15 @@ foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) { my $path = "html/$row->{authid}"; open(my $fh, '>:encoding(utf-8)', "$path.new"); print $fh html_title($row->{full_name}, "bibliografija"); - print $fh qq|

    $row->{full_name} - bibliografija za razdoblje 2008-2013

    |; + print $fh qq|

    $row->{full_name} - bibliografija

    \n|; + + 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' ); + #author_html( $fh, $row->{authid}, 'sec' => 'Uredništva, prijevodi, kritička izdanja' ); + author_html( $fh, $row->{authid}, 'edt' => 'Uredništva' ); + author_html( $fh, $row->{authid}, 'trl' => 'Prijevodi' ); + author_html( $fh, $row->{authid}, '_ostalo' => 'Ostalo' ); print $fh html_end; close($fh); @@ -430,7 +581,7 @@ foreach my $department ( sort keys %$auth_department ) { push @categories, keys %{ $authors->{$authid}->{sec} }; foreach my $category ( sort @categories ) { push @{ $department_category_author->{$department}->{$category} }, $authid; - push @{ $department_category_author->{'AAZ_ukupno'}->{$category} }, $authid if $department_in_sum->{$department}; + push @{ $department_category_author->{'AAA_ukupno'}->{$category} }, $authid if $department_in_sum->{$department}; if ( my $group = $department_in_group->{ $department } ) { push @{ $department_category_author->{$group}->{$category} }, $authid; } else { @@ -442,67 +593,57 @@ foreach my $department ( sort keys %$auth_department ) { debug 'department_category_author' => $department_category_author; -mkdir 'html/departments' unless -d 'html/departments'; -sub unique_biblionumber { - my @v = @_; - my $u; - $u->{$_}++ foreach @v; - return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $a <=> $b } keys %$u; -} - -open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new'); -print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|