summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2014-03-10 11:55:04 +0100
committerYorhel <git@yorhel.nl>2014-03-10 11:56:25 +0100
commit721d0868f36da2412bad4a1efdbd1abac36812bd (patch)
tree9ede9993c80aceacc591c7a9d73bb2a9122fb7a3
parente13c14cdcff2af652f248f0c9b59a8631d69ede5 (diff)
Multi::API: Expose popularity, rating and votecount
http://vndb.org/t5121
-rw-r--r--data/docs/1122
-rw-r--r--lib/Multi/API.pm8
2 files changed, 29 insertions, 1 deletions
diff --git a/data/docs/11 b/data/docs/11
index 83248b24..b5667e05 100644
--- a/data/docs/11
+++ b/data/docs/11
@@ -463,6 +463,27 @@ however still required.<br />
often.
</td>
</tr>
+ <tr class="odd">
+ <td>popularity</td>
+ <td>stats</td>
+ <td>number</td>
+ <td>no</td>
+ <td>Between 0 (unpopular) and 100 (most popular).</td>
+ </tr>
+ <tr>
+ <td>rating</td>
+ <td>stats</td>
+ <td>number</td>
+ <td>no</td>
+ <td>Bayesian rating, between 1 and 10.</td>
+ </tr>
+ <tr class="odd">
+ <td>votecount</td>
+ <td>stats</td>
+ <td>integer</td>
+ <td>no</td>
+ <td>Number of votes.</td>
+ </tr>
</table>
<p>Sorting is possible on the 'id', 'title' and 'released' fields.</p><br />
@@ -1404,6 +1425,7 @@ however still required.<br />
<li>Added 'set' command, with types: votelist, vnlist and wishlist</li>
<li>New error id: 'settype'</li>
<li>Added "tags" flag and member to "get vn"</li>
+ <li>Added "stats" flag to "get vn"</li>
</ul>
<b>2.15</b>
<ul>
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index 673605ae..4775db43 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -463,11 +463,12 @@ sub get_vn {
my $get = $_[ARG0];
return cerr $get->{c}, getinfo => "Unknown info flag '$_'", flag => $_
- for (grep !/^(basic|details|anime|relations|tags)$/, @{$get->{info}});
+ for (grep !/^(basic|details|anime|relations|tags|stats)$/, @{$get->{info}});
my $select = 'v.id, v.latest';
$select .= ', vr.title, vr.original, v.c_released, v.c_languages::text[], v.c_olang::text[], v.c_platforms' if grep /basic/, @{$get->{info}};
$select .= ', vr.image, vr.img_nsfw, vr.alias AS aliases, vr.length, vr.desc AS description, vr.l_wp, vr.l_encubed, vr.l_renai' if grep /details/, @{$get->{info}};
+ $select .= ', v.c_popularity, v.c_rating, v.c_votecount' if grep /stats/, @{$get->{info}};
my @placeholders;
my $where = encode_filters $get->{filters}, \&filtertosql, $get->{c}, \@placeholders, [
@@ -544,6 +545,11 @@ sub get_vn_res {
};
$_->{image} = $_->{image} ? sprintf '%s/cv/%02d/%d.jpg', $VNDB::S{url_static}, $_->{image}%100, $_->{image} : undef;
}
+ if(grep /stats/, @{$get->{info}}) {
+ $_->{popularity} = 1 * sprintf '%.2f', 100*delete($_->{c_popularity}) || 0;
+ $_->{rating} = 1 * sprintf '%.2f', 0.1*delete($_->{c_rating}) || 0;
+ $_->{votecount} = 1 * delete $_->{c_votecount};
+ }
}
$get->{more} = pop(@$res)&&1 if @$res > $get->{opt}{results};
$get->{list} = $res;