Filename | /usr/share/koha/lib/C4/SocialData.pm |
Statements | Executed 13 statements in 807µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 24µs | 146µs | BEGIN@18 | C4::SocialData::
1 | 1 | 1 | 17µs | 41µs | BEGIN@21 | C4::SocialData::
1 | 1 | 1 | 15µs | 485µs | BEGIN@22 | C4::SocialData::
1 | 1 | 1 | 14µs | 17µs | BEGIN@20 | C4::SocialData::
0 | 0 | 0 | 0s | 0s | get_data | C4::SocialData::
0 | 0 | 0 | 0s | 0s | get_report | C4::SocialData::
0 | 0 | 0 | 0s | 0s | update_data | C4::SocialData::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::SocialData; | ||||
2 | |||||
3 | # This file is part of Koha. | ||||
4 | # | ||||
5 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
6 | # terms of the GNU General Public License as published by the Free Software | ||||
7 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
8 | # version. | ||||
9 | # | ||||
10 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
13 | # | ||||
14 | # You should have received a copy of the GNU General Public License along with | ||||
15 | # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||||
16 | # Suite 330, Boston, MA 02111-1307 USA | ||||
17 | |||||
18 | 3 | 42µs | 2 | 268µs | # spent 146µs (24+122) within C4::SocialData::BEGIN@18 which was called:
# once (24µs+122µs) by main::BEGIN@53 at line 18 # spent 146µs making 1 call to C4::SocialData::BEGIN@18
# spent 122µs making 1 call to Modern::Perl::import |
19 | |||||
20 | 3 | 29µs | 2 | 20µs | # spent 17µs (14+3) within C4::SocialData::BEGIN@20 which was called:
# once (14µs+3µs) by main::BEGIN@53 at line 20 # spent 17µs making 1 call to C4::SocialData::BEGIN@20
# spent 3µs making 1 call to C4::Context::import |
21 | 3 | 37µs | 2 | 66µs | # spent 41µs (17+25) within C4::SocialData::BEGIN@21 which was called:
# once (17µs+25µs) by main::BEGIN@53 at line 21 # spent 41µs making 1 call to C4::SocialData::BEGIN@21
# spent 24µs making 1 call to Exporter::import |
22 | 3 | 685µs | 2 | 955µs | # spent 485µs (15+470) within C4::SocialData::BEGIN@22 which was called:
# once (15µs+470µs) by main::BEGIN@53 at line 22 # spent 485µs making 1 call to C4::SocialData::BEGIN@22
# spent 470µs making 1 call to Exporter::import |
23 | |||||
24 | =head1 NAME | ||||
25 | |||||
- - | |||||
59 | sub get_data { | ||||
60 | my ( $isbn ) = @_; | ||||
61 | my $dbh = C4::Context->dbh; | ||||
62 | my $sth = $dbh->prepare( qq{SELECT * FROM social_data WHERE isbn = ? LIMIT 1} ); | ||||
63 | $sth->execute( $isbn ); | ||||
64 | my $results = $sth->fetchrow_hashref; | ||||
65 | |||||
66 | return $results; | ||||
67 | } | ||||
68 | |||||
69 | =head2 update_data | ||||
70 | |||||
- - | |||||
81 | sub update_data { | ||||
82 | my ( $output_filepath ) = @_; | ||||
83 | |||||
84 | my $dbh = C4::Context->dbh; | ||||
85 | my $sth = $dbh->prepare( qq{INSERT INTO social_data ( | ||||
86 | `isbn`, `num_critics`, `num_critics_pro`, `num_quotations`, `num_videos`, `score_avg`, `num_scores` | ||||
87 | ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) | ||||
88 | ON DUPLICATE KEY UPDATE `num_critics`=?, `num_critics_pro`=?, `num_quotations`=?, `num_videos`=?, `score_avg`=?, `num_scores`=? | ||||
89 | } ); | ||||
90 | |||||
91 | open my $file, '<', $output_filepath or die "File $output_filepath can not be read"; | ||||
92 | my $sep = qq{;}; | ||||
93 | my $i = 0; | ||||
94 | my $unknown = 0; | ||||
95 | while ( my $line = <$file> ) { | ||||
96 | my ( $isbn, $active, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores ) = split $sep, $line; | ||||
97 | next if not $active; | ||||
98 | eval { | ||||
99 | $sth->execute( $isbn, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores, | ||||
100 | $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores | ||||
101 | ); | ||||
102 | }; | ||||
103 | if ( $@ ) { | ||||
104 | warn "Can't insert $isbn ($@)"; | ||||
105 | } else { | ||||
106 | $i++; | ||||
107 | } | ||||
108 | } | ||||
109 | say "$i data insered or updated"; | ||||
110 | } | ||||
111 | |||||
112 | =head2 get_report | ||||
113 | |||||
- - | |||||
118 | sub get_report { | ||||
119 | my $dbh = C4::Context->dbh; | ||||
120 | |||||
121 | my $sth = $dbh->prepare( qq{ | ||||
122 | SELECT biblionumber, isbn FROM biblioitems | ||||
123 | } ); | ||||
124 | $sth->execute; | ||||
125 | my %results; | ||||
126 | while ( my ( $biblionumber, $isbn ) = $sth->fetchrow() ) { | ||||
127 | push @{ $results{no_isbn} }, { biblionumber => $biblionumber } and next if not $isbn; | ||||
128 | my $original_isbn = $isbn; | ||||
129 | $isbn =~ s/^\s*(\S*)\s*$/$1/; | ||||
130 | $isbn = GetNormalizedISBN( $isbn, undef, undef ); | ||||
131 | $isbn = Business::ISBN->new( $isbn ); | ||||
132 | next if not $isbn; | ||||
133 | eval{ | ||||
134 | $isbn = $isbn->as_isbn13->as_string; | ||||
135 | }; | ||||
136 | next if $@; | ||||
137 | $isbn =~ s/-//g; | ||||
138 | my $social_datas = C4::SocialData::get_data( $isbn ); | ||||
139 | if ( $social_datas ) { | ||||
140 | push @{ $results{with} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn }; | ||||
141 | } else { | ||||
142 | push @{ $results{without} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn }; | ||||
143 | } | ||||
144 | } | ||||
145 | return \%results; | ||||
146 | } | ||||
147 | |||||
148 | 1 | 13µs | 1; |