9ba63961570fbb6488da229ec7b8bd3b93b93e3f
[star2016] / star2016-contributions.pl
1 #!/usr/bin/perl
2 use autodie;
3 use warnings;
4 use strict;
5
6 use XML::Simple;
7 use Data::Dump qw(dump);
8 use utf8;
9
10 my $odt_file   = 'contributions.odt';
11
12 my $xs = XML::Simple->new();
13
14 use     OpenOffice::OODoc       2.101;
15 my $doc = odfDocument(file => $odt_file, create => 'text');
16
17 my $stat;
18 my $id2nr;
19
20 $doc->createStyle(
21         "Abstract",
22         family          => 'paragraph',
23         parent          => 'Default Style',
24         category        => 'auto',
25         properties      => {
26                 -area                   => 'paragraph',
27                 'fo:text-align' => 'justify'
28         }
29 );
30
31
32 my $nr = 0;
33 #foreach my $file ( glob 'contributions/*.xml' ) {
34
35 my $xml;
36 open(my $fh, '<', 'contributions/all.xml');
37 {
38         local $/ = undef;
39         $xml = <$fh>;
40         close($fh);
41 }
42
43 foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
44
45         next unless $xml;
46
47         $xml = '<?xml' . $xml;
48
49         my $abstract;
50
51 print $xml;
52
53         $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
54
55         warn "# abstract = ", dump($abstract);
56
57         my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
58         warn "# $id abstract = ", dump($abstract);
59
60         foreach my $k (qw( ContributionType )) {
61                 $stat->{$k}->{ $abstract->{$k}->[0] } ++;
62         }
63
64         if ( my $s = $abstract->{Symposium_title} ) {
65                 $s = $s->[0];
66                 push @{ $stat->{_symposium}->{$s} }, $id;
67         }
68
69         my $f = $abstract->{field};
70
71         push @{ $stat->{_symposium}->{ $f->{1}->{'content'} } }, $id if exists $f->{1}->{content};
72         push @{ $stat->{_theme}->{     $f->{2}->{'content'} } }, $id if exists $f->{2}->{content};
73
74         $stat->{field}->{ $_ }++ foreach keys %$f;
75
76         $id2nr->{ $id } = $nr++;
77
78 }
79
80 warn "# stat = ",dump($stat);
81
82 __END__
83
84 warn "$nr";
85
86         my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
87         $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
88
89         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
90                 $doc->appendParagraph(text => join(' ',
91                         map { $a->{$_}->[0] } qw( FirstName FamilyName )
92                 ), style => 'Heading 2');
93                 $doc->appendParagraph(text => join(' ',
94                         map { $a->{$_}->[0] } qw( Affiliation )
95                 ), style => 'Heading 3');
96                 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
97         }
98
99 #       $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
100         foreach my $p ( split(/[\n\r]+/, $abstract->{Content}->[0] ) ) {
101                 $doc->appendParagraph(text => $p, style => 'Abstract');
102         }
103
104         $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
105         
106
107         $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
108 }
109
110 warn "# stat = ",dump($stat);
111
112 $doc->save;
113
114
115 open(my $fh, '>', 'affiliation.csv');
116 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
117         print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
118 }
119
120 __DATA__
121     "Symposium proposal"  => 12,
122         "Symposium abstract"  => 52,
123     "Oral presentation"   => 141,
124     "Poster presentation" => 71,
125