Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/logs/template/subscription.html

Issue 9503001: Subscription stats: Make sure there can be no division by zero errors (Closed)
Patch Set: Fixed the issue in all the relevant places now Created March 1, 2013, 8:29 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgsubstate ('k') | sitescripts/logs/template/subscriptionOverview.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/logs/template/subscription.html
===================================================================
--- a/sitescripts/logs/template/subscription.html
+++ b/sitescripts/logs/template/subscription.html
@@ -43,19 +43,20 @@
<td>Month {{month|monthname}} (<a href="{{overviewURL}}">To overview page</a>)</td>
</tr>
</table>
<div class="block_title">Days of month</div>
<div class="block">
<table align="center" style="margin-bottom: 20px;">
<tr align="bottom">
- {%- set maxHits, maxBandwidth = day|max(attribute='hits'), day|max(attribute='bandwidth') %}
- {%- set totalHits = day|sum(attribute='hits') %}
- {%- set totalBandwidth = day|sum(attribute='bandwidth') %}
+ {%- set maxHits = day|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = day|max(attribute='bandwidth')|ensuremin(1) %}
+ {%- set totalHits = day|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = day|sum(attribute='bandwidth')|ensuremin(1) %}
{%- set dayCount = day|length %}
{%- if currentMonth and dayCount > 1 %}
{%- set totalHits = totalHits - day[-1].hits %}
{%- set totalBandwidth = totalBandwidth - day[-1].bandwidth %}
{%- set dayCount = dayCount - 1 %}
{%- endif %}
{%- for info in day %}
<td align="center" style="vertical-align: bottom;">
@@ -130,17 +131,18 @@
</tr>
</table>
</div>
<div class="block_title">Days of week</div>
<div class="block">
<table align="center" style="margin-bottom: 20px;">
<tr align="bottom">
- {%- set maxHits, maxBandwidth = weekday|max(attribute='hits'),weekday|max(attribute='bandwidth') %}
+ {%- set maxHits = weekday|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = weekday|max(attribute='bandwidth')|ensuremin(1) %}
{%- for info in weekday %}
<td align="center" style="vertical-align: bottom;">
<div class="hitsChart vertical" title="Hits: {{info.hits}}" style="height: {{(info.hits / maxHits * 100)|round(method='ceil')|int}}px"></div>
{{- '' -}}
<div class="bandwidthChart vertical" alt="Bandwidth: {{info.bandwidth|bytes}}"" title="Bandwidth: {{info.bandwidth|bytes}}" style="height: {{(info.bandwidth / maxBandwidth * 100)|round(method='ceil')|int}}px"></div>
</td>
{%- endfor %}
</tr>
@@ -154,34 +156,35 @@
</table>
<table align="center">
<tr>
<th bgcolor="#ECECEC">Day</th>
<th bgcolor="#66DDEE" colspan="2">Hits</th>
<th bgcolor="#2EA495">Bandwidth</th>
</tr>
- {%- set totalHits = weekday|sum(attribute='hits') %}
- {%- set totalBandwidth = weekday|sum(attribute='bandwidth') %}
+ {%- set totalHits = weekday|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = weekday|sum(attribute='bandwidth')|ensuremin(1) %}
{%- for info in weekday %}
<tr{% if info.id > 4 %} class="special"{% endif %}>
<td>{{info.id|weekday}}</td>
<td align="right">{{info.hits}}</td>
<td align="right">{{(info.hits / totalHits * 100)|round(precision=1)}}%</td>
<td align="right">{{info.bandwidth|bytes}}</td>
</tr>
{%- endfor %}
</table>
</div>
<div class="block_title">Hours</div>
<div class="block">
<table align="center" style="margin-bottom: 20px;">
<tr align="bottom">
- {%- set maxHits, maxBandwidth = hour|max(attribute='hits'),hour|max(attribute='bandwidth') %}
+ {%- set maxHits = hour|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = hour|max(attribute='bandwidth')|ensuremin(1) %}
{%- for info in hour %}
<td align="center" style="vertical-align: bottom;">
<div class="hitsChart vertical" title="Hits: {{info.hits}}" style="height: {{(info.hits / maxHits * 100)|round(method='ceil')|int}}px;"></div>
{{- '' -}}
<div class="bandwidthChart vertical" title="Bandwidth: {{info.bandwidth|bytes}}" style="height: {{(info.bandwidth / maxBandwidth * 100)|round(method='ceil')|int}}px;"></div>
</td>
{%- if loop.last and info.id|int < 23 %}
{%- for dummyHour in range(info.id|int + 1, 24) %}
@@ -213,18 +216,18 @@
</table>
<table align="center">
<tr>
<th bgcolor="#ECECEC">Hour</th>
<th bgcolor="#66DDEE" colspan="2">Hits</th>
<th bgcolor="#2EA495">Bandwidth</th>
</tr>
- {%- set totalHits = hour|sum(attribute='hits') %}
- {%- set totalBandwidth = hour|sum(attribute='bandwidth') %}
+ {%- set totalHits = hour|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = hour|sum(attribute='bandwidth')|ensuremin(1) %}
{%- for info in hour %}
<tr>
<td>{{info.id}}</td>
<td align="right">{{info.hits}}</td>
<td align="right">{{(info.hits / totalHits * 100)|round(precision=1)}}%</td>
<td align="right">{{info.bandwidth|bytes}}</td>
</tr>
{%- endfor %}
@@ -235,19 +238,20 @@
<div class="block_title">Browsers</div>
<div class="block">
<table align="center">
<tr>
<th bgcolor="#ECECEC">Browser</th>
<th bgcolor="#66DDEE" colspan="2">Hits</th>
<th bgcolor="#2EA495">Bandwidth</th>
</tr>
- {%- set maxHits, maxBandwidth = app|max(attribute='hits'),app|max(attribute='bandwidth') %}
- {%- set totalHits = app|sum(attribute='hits') %}
- {%- set totalBandwidth = app|sum(attribute='bandwidth') %}
+ {%- set maxHits = app|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = app|max(attribute='bandwidth')|ensuremin(1) %}
+ {%- set totalHits = app|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = app|sum(attribute='bandwidth')|ensuremin(1) %}
{%- for info in app[0:10] %}
<tr>
<td>{{info.id}}</td>
<td align="right">{{info.hits}}</td>
<td align="right">{{(info.hits / totalHits * 100)|round(precision=1)}}%</td>
<td align="right">{{info.bandwidth|bytes}}</td>
<td class="chart">
<div class="hitsChart horizontal" style="width: {{(info.hits / maxHits * 100)|round(method='ceil')|int}}px;"></div><br />
@@ -291,19 +295,20 @@
<div class="block">
<table align="center">
<tr>
<th bgcolor="#ECECEC" colspan="3">Country</th>
<th bgcolor="#66DDEE" colspan="2">Hits</th>
<th bgcolor="#2EA495">Bandwidth</th>
<th>&nbsp;</th>
</tr>
- {%- set maxHits, maxBandwidth = country|max(attribute='hits'),country|max(attribute='bandwidth') %}
- {%- set totalHits = country|sum(attribute='hits') %}
- {%- set totalBandwidth = country|sum(attribute='bandwidth') %}
+ {%- set maxHits = country|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = country|max(attribute='bandwidth')|ensuremin(1) %}
+ {%- set totalHits = country|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = country|sum(attribute='bandwidth')|ensuremin(1) %}
{%- for info in country[0:10] %}
<tr>
<td><div class="flag {{info.image}}"></div></td>
<td>{{info.name}}</td>
<td>{{info.id}}</td>
<td align="right">{{info.hits}}</td>
<td align="right">{{(info.hits / totalHits * 100)|round(precision=1)}}%</td>
<td align="right">{{info.bandwidth|bytes}}</td>
@@ -352,19 +357,20 @@
<div class="block">
<table align="center">
<tr>
<th bgcolor="#ECECEC">Mirror</th>
<th bgcolor="#66DDEE" colspan="2">Hits</th>
<th bgcolor="#2EA495">Bandwidth</th>
<th>&nbsp;</th>
</tr>
- {%- set maxHits, maxBandwidth = mirror|max(attribute='hits'),mirror|max(attribute='bandwidth') %}
- {%- set totalHits = mirror|sum(attribute='hits') %}
- {%- set totalBandwidth = mirror|sum(attribute='bandwidth') %}
+ {%- set maxHits = mirror|max(attribute='hits')|ensuremin(1) %}
+ {%- set maxBandwidth = mirror|max(attribute='bandwidth')|ensuremin(1) %}
+ {%- set totalHits = mirror|sum(attribute='hits')|ensuremin(1) %}
+ {%- set totalBandwidth = mirror|sum(attribute='bandwidth')|ensuremin(1) %}
{%- for info in mirror %}
<tr>
<td>{{info.id}}</td>
<td align="right">{{info.hits}}</td>
<td align="right">{{(info.hits / totalHits * 100)|round(precision=1)}}%</td>
<td align="right">{{info.bandwidth|bytes}}</td>
<td class="chart">
<div class="hitsChart horizontal" style="width: {{(info.hits / maxHits * 100)|round(method='ceil')|int}}px;"></div><br />
« no previous file with comments | « .hgsubstate ('k') | sitescripts/logs/template/subscriptionOverview.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld