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;
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 = {
+'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;
my $auth_department;
my $auth_group;
my @authors;
my $department_in_sum;
+my $department_in_group;
my $skip;
push @{ $skip->{no_academic_group} }, $row;
}
- warn "# ", dump( $row );
+# warn "# ", dump( $row );
push @{ $auth_department->{ $row->{department} } }, $row->{authid};
push @authors, $row;
$department_in_sum->{ $row->{department} }++;
+ foreach my $name ( keys %$department_groups ) {
+ my $regex = $department_groups->{$name};
+ if ( $row->{department} =~ $regex ) {
+ $department_in_group->{ $row->{department} } = $name;
+ last;
+ }
+ }
}
+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;
}
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;
=cut
my $biblio_year;
+my $biblio_full_name;
my $type_stats;
my $parser = XML::LibXML->new();
my $biblio_html;
my $biblio_parsed;
my $biblio_data;
+my $biblio_author_external;
open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
my $extract = {
'008' => undef,
- '100' => '9',
+ '100' => '(9|a)',
+ '245' => 'a',
'680' => 'i',
- '700' => '(9|4)',
+ '700' => '(9|4|a)',
'942' => '(t|r|v)'
};
}
}
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);
my $have_100 = 1;
if ( exists $data->{100} ) {
- my @first_author = map { $_->{'9'} } @{ $data->{100} };
+ my @first_author =
+ map { $_->{'9'} }
+ grep {
+ if ( ! exists $_->{9} ) {
+ $biblio_author_external->{ $row->{biblionumber} }++;
+ 0;
+ } elsif ( exists $auth_header->{ $_->{9} } ) {
+ 1; # from FFZXG
+ } else {
+ 0;
+ }
+ }
+ @{ $data->{100} };
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} ) {
- foreach my $auth ( @{ $data->{700} } ) {
+ my @other_authors =
+ grep {
+ if ( ! exists $_->{9} ) {
+ $biblio_author_external->{ $row->{biblionumber} }++;
+ 0;
+ } elsif ( exists $auth_header->{ $_->{9} } ) {
+ 1; # from FFZXG
+ } else {
+ 0;
+ }
+ }
+ @{ $data->{700} };
+ foreach my $auth ( @other_authors ) {
my $authid = $auth->{9} || next;
my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
}
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;
my $category_label;
my $sth_categories = $dbh->prepare(q{
<meta charset="UTF-8">
<title>|, join(" ", @_), qq|</title>
<link href="style.css" type="text/css" rel="stylesheet" />
+<script src="//code.jquery.com/jquery-1.11.2.js"></script>
</head>
<body>
|;
}
sub html_end {
- return qq|</body>\n</html>\n|;
+ return
+ qq|<small style="color:gray">Zadnji puta osvježeno: |,
+ strftime("%Y-%m-%d %H:%M:%S\n", localtime()),
+ qq|</body>\n</html>\n|;
}
mkdir 'html' unless -d 'html';
sub li_biblio {
my ($biblionumber) = @_;
- return qq|<li>|,
+ return qq|<li class="y|, $biblio_year->{$biblionumber}, qq|">|,
qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
biblioitem_html($biblionumber),
qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
qq|</li>\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 ) = @_;
foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
my $label = $category_label->{$category} || 'Bez kategorije';
- print $fh qq|<h3>$label</h3>\n<ul>\n|;
- foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
+ print $fh qq|<a name="$type-$category"><h3>$label</h3></a>\n<ol>\n|;
+ foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
print $fh li_biblio( $biblionumber );
}
- print $fh qq|</ul>\n|;
+ print $fh qq|</ol>\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|<span id="years">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|<label><input name="year_selection" value="$year" type=checkbox onClick="toggle_year($year, this)" checked="checked">$year</label> \n|;
+ foreach my $type_cat ( keys %{ $years->{$year} } ) {
+ $type_cat_count->{ $type_cat } += $years->{$year}->{$type_cat};
+ }
+ }
+
+ print $fh qq|
+<input type=button value="all" onClick="all_years(1)">
+<input type=button value="none" onClick="all_years(0)">
+ |;
+
+ print $fh qq|</span>|;
+
+ print $fh q|
+<script>
+
+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');
+ }
+ }
+}
+
+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);
+ });
+
+});
+</script>
+ |;
+}
+
foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
my $first = substr( $row->{full_name}, 0, 1 );
my $path = "html/$row->{authid}";
open(my $fh, '>:encoding(utf-8)', "$path.new");
print $fh html_title($row->{full_name}, "bibliografija");
- print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
+ print $fh qq|<h1>$row->{full_name} - bibliografija</h1>\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' );
print $fh html_end;
close($fh);
push @categories, keys %{ $authors->{$authid}->{sec} };
foreach my $category ( sort @categories ) {
push @{ $department_category_author->{$department}->{$category} }, $authid;
- push @{ $department_category_author->{''}->{$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 {
+ $skip->{'department_not_in_group'}->{ $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;
-}
+sub department_html {
+ my ( $fh, $department, $type, $label ) = @_;
-open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
-print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
-foreach my $department ( sort keys %$department_category_author ) {
- my $dep = $department || 'Nema odsjeka';
- my $dep_file = unac_string('utf-8',$dep);
- print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
- open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
-
- print $fh html_title($department . ' bibliografija');
- print $fh qq|<h1>$department bibliografija</h1>\n|;
-
- print $fh qq|<h2>Primarno autorstvo</h2>\n|;
+ print $fh qq|<h2>$label</h2>\n|;
foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
my @authids = @{ $department_category_author->{$department}->{$category} };
next unless @authids;
- my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{aut}->{$category} } } grep { exists $authors->{$_}->{aut}->{$category} } @authids;
- my $unique;
- $unique->{$_}++ foreach @biblionumber;
+ my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{$type}->{$category} } } grep { exists $authors->{$_}->{$type}->{$category} } @authids;
next unless @biblionumber;
my $label = $category_label->{$category} || 'Bez kategorije';
- print $fh qq|<h3>$label</h3>\n<ul>\n|;
+ print $fh qq|<a name="$type-$category"><h3>$label</h3></a>\n<ol>\n|;
print $fh li_biblio( $_ ) foreach @biblionumber;
- print $fh qq|</ul>|;
+ print $fh qq|</ol>|;
}
+}
- print $fh qq|<h2>Sekundarno autorstvo</h2>\n|;
-
- foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
-
- my @authids = @{ $department_category_author->{$department}->{$category} };
- next unless @authids;
-
- my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{sec}->{$category} } } grep { exists $authors->{$_}->{sec}->{$category} } @authids;
- next unless @biblionumber;
+mkdir 'html/departments' unless -d 'html/departments';
- my $label = $category_label->{$category} || 'Bez kategorije';
- print $fh qq|<h3>$label</h3>\n<ul>\n|;
+open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
+print $dep_fh html_title('Odsjeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
+foreach my $department ( sort keys %$department_category_author ) {
+ my $dep = $department || 'Nema odsjeka';
+ my $dep_file = unac_string('utf-8',$dep);
+ print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
+ open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
- print $fh li_biblio( $_ ) foreach @biblionumber;
+ print $fh html_title($department . ' bibliografija');
+ print $fh qq|<h1>$department bibliografija</h1>\n|;
- print $fh qq|</ul>|;
+ my @authids;
+ foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
+ push @authids, @{ $department_category_author->{$department}->{$category} };
}
+ html_year_selection $fh => @authids;
+
+ department_html( $fh, $department, 'aut', 'Primarno autorstvo' );
+ department_html( $fh, $department, 'sec', 'Sekundarno autorstvo' );
print $fh html_end;
close($fh);
my @biblionumbers = @_;
my $unique;
$unique->{$_}++ foreach @biblionumbers;
- $table->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar keys %$unique;
+ 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;
}
foreach my $group ( '', keys %$azvo_group_title ) {
debug 'table', $table;
open(my $fh, '>:encoding(utf-8)', 'html/azvo.new');
+open(my $fh2, '>:encoding(utf-8)', 'html/azvo2.new');
-print $fh html_title('AZVO tablica');
+sub print_fh {
+ print $fh @_;
+ print $fh2 @_;
+}
+
+print $fh html_title('AZVO tablica - FFZG');
+print $fh2 html_title('AZVO tablica - kolaboracija sa FFZG');
-foreach my $group ( keys %$table ) {
+foreach my $group ( keys %{ $table->{ffzg} } ) {
- print $fh "<h1>$group</h1>" if $group;
+ print_fh "<h1>$group</h1>" if $group;
- print $fh "<table border=1>\n";
- print $fh "<tr><th></th>";
- print $fh "<th>$_</th>" foreach @departments;
- print $fh "</tr>\n";
+ print_fh "<table border=1>\n";
+ print_fh "<tr><th></th>";
+ print_fh "<th>$_</th>" foreach @departments;
+ print_fh "</tr>\n";
- foreach my $row ( 0 .. $#{ $table->{$group} } ) {
- print $fh "<tr><th>", $report_labels[$row], "</th>\n";
- print $fh " <td>", $table->{$group}->[ $row ]->[ $_ ] || '', "</td>\n" foreach 0 .. $#departments;
- print $fh "</tr>\n";
+ foreach my $row ( 0 .. $#{ $table->{ffzg}->{$group} } ) {
+ print_fh "<tr><th>", $report_labels[$row], "</th>\n";
+ foreach ( 0 .. $#departments ) {
+ print_fh "<td>";
+ print $fh $table->{ffzg}->{$group}->[ $row ]->[ $_ ] || '';
+ print $fh2 $table->{external}->{$group}->[ $row ]->[ $_ ] || '';
+ print_fh "</td>\n"
+ }
+ print_fh "</tr>\n";
}
- print $fh "</table>\n";
+ print_fh "</table>\n";
} # group
-print $fh html_end;
+print_fh html_end;
close($fh);
+close($fh2);
rename 'html/azvo.new', 'html/azvo.html';
+rename 'html/azvo2.new', 'html/azvo2.html';