collect symposiom titles
[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 $abstract;
36
37         warn "# reading $file\n";
38
39         {
40                 open(my $fh, '<:raw', $file);
41                 local $/ = undef;
42                 my $xml = <$fh>;
43 #               warn dump($xml);
44                 $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
45         }
46
47         warn "# abstract = ", dump($abstract);
48
49         my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
50         warn "# $id abstract = ", dump($abstract);
51
52         foreach my $k (qw( ContributionType )) {
53                 $stat->{$k}->{ $abstract->{$k}->[0] } ++;
54         }
55
56         if ( my $s = $abstract->{Symposium_title} ) {
57                 $s = $s->[0];
58                 push @{ $stat->{_symposium}->{$s} }, $id;
59         }
60
61         my $f = $abstract->{field};
62
63         push @{ $stat->{_symposium}->{ $f->{1}->{'content'} } }, $id if exists $f->{1}->{content};
64         push @{ $stat->{_theme}->{     $f->{2}->{'content'} } }, $id if exists $f->{2}->{content};
65
66         $stat->{field}->{ $_ }++ foreach keys %$f;
67
68         $id2nr->{ $id } = $nr++;
69
70 }
71
72 warn "# stat = ",dump($stat);
73
74 __END__
75
76 warn "$nr";
77
78         my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
79         $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
80
81         foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
82                 $doc->appendParagraph(text => join(' ',
83                         map { $a->{$_}->[0] } qw( FirstName FamilyName )
84                 ), style => 'Heading 2');
85                 $doc->appendParagraph(text => join(' ',
86                         map { $a->{$_}->[0] } qw( Affiliation )
87                 ), style => 'Heading 3');
88                 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
89         }
90
91 #       $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
92         foreach my $p ( split(/[\n\r]+/, $abstract->{Content}->[0] ) ) {
93                 $doc->appendParagraph(text => $p, style => 'Abstract');
94         }
95
96         $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
97         
98
99         $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
100 }
101
102 warn "# stat = ",dump($stat);
103
104 $doc->save;
105
106
107 open(my $fh, '>', 'affiliation.csv');
108 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
109         print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
110 }
111
112 __DATA__
113     "Symposium proposal"  => 12,
114         "Symposium abstract"  => 52,
115     "Oral presentation"   => 141,
116     "Poster presentation" => 71,
117