summaryrefslogtreecommitdiff
path: root/data/tpl/vnpage_stats
blob: 6a450e145d3ad051ec029af07695314b4ba03616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<ul id="stats">

[[
  my $max = 1; my $total = 0; my $sum = 0;
  for (0..$#{$d{votes}{graph}}) {
    $total += $d{votes}{graph}[$_];
    $max = $d{votes}{graph}[$_] if $d{votes}{graph}[$_] > $max;
    $sum += ($_+1) * $d{votes}{graph}[$_];
  }
]]
[[ if(!$d{user} || ($d{pl} && $d{user}{votes})) { ]]-
<li><h3>Vote graph <p class="actions">[[= $total ]]- vote[[= $total==1?'':'s' ]]- total
  [[= $total && $d{user} ? sprintf(', average: %.1f.', $sum/$total) : '' ]]</p></h3>
<table id="tvg">
[[ for (reverse 0..$#{$d{votes}{graph}}) { ]]-
 <tr>
  <td class="tc1">[[= $_+1 ]]</td>
  <td class="tc2"><div style="width: -[[= ($d{votes}{graph}[$_]/$max)*270 + 5 ]]px">&nbsp;</div>[[= $d{votes}{graph}[$_] ]]</td>
 </tr>
[[ } ]]-
</table></li>

[[ if($#{$d{votes}{latest}} >= 0) { ]]
<li><h3>Recent votes</h3>
<table id="tvr">
[[ for (@{$d{votes}{latest}}) { ]]-
 <tr>
 [[ if(!$d{user}) { ]]-
  <td class="tc1">[[= userstr $_ ]]</td>
 [[ } else { ]]-
  <td class="tc1"><a href="/v[[= $_->{vid} ]]">[[: length($_->{title})>30?substr($_->{title},0,27).'...':$_->{title} ]]</a></td>
 [[ } ]]-
  <td class="tc2">[[= $_->{vote} ]]</td>
  <td class="tc3">[[= formatdate('%Y-%m-%d %R', $_->{date}, 'dh') ]]</td>
 </tr>
[[ } ]]-
</table></li>
[[ } } ]]-
</ul>