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

Unified Diff: sitescripts/stats/bin/pagegenerator.py

Issue 5664623214723072: Issue 1560 - ZeroDivisionError in sitescripts.stats.bin.pagegenerator (Closed)
Patch Set: Better work-around for zero divisors Created Nov. 12, 2014, 8:55 p.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 | « no previous file | sitescripts/stats/template/fileOverview.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/stats/bin/pagegenerator.py
===================================================================
--- a/sitescripts/stats/bin/pagegenerator.py
+++ b/sitescripts/stats/bin/pagegenerator.py
@@ -23,20 +23,21 @@ from sitescripts.stats.countrycodes impo
@cached(float("inf"))
def get_template_environment():
return get_custom_template_environment({
"monthname": lambda value: date(int(value[0:4]), int(value[4:]), 1).strftime("%b %Y"),
"weekday": lambda value: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][int(value)],
"countryname": lambda value: countrycodes.get(value, "Unknown"),
"sortfield": lambda value, field: (field["sort"] if "sort" in field else default_sort)(value),
- "maxhits": lambda items: max(itertools.chain((value["hits"] for key, value in items), [1])),
- "maxbandwidth": lambda items: max(itertools.chain((value["bandwidth"] for key, value in items), [1])),
- "sumhits": lambda items: max(sum(value["hits"] for key, value in items), 1),
- "sumbandwidth": lambda items: max(sum(value["bandwidth"] for key, value in items), 1),
+ "maxhits": lambda items: max(value["hits"] for key, value in items),
+ "maxbandwidth": lambda items: max(value["bandwidth"] for key, value in items),
+ "sumhits": lambda items: sum(value["hits"] for key, value in items),
+ "sumbandwidth": lambda items: sum(value["bandwidth"] for key, value in items),
+ "percentage": lambda value, total: float(value) / total * 100 if total != 0 else 0,
"isspecial": lambda name, field: field["isspecial"](name) if "isspecial" in field else False,
"defaultcount": get_default_count,
})
@cached(float("inf"))
def get_main_page_template():
return get_template_environment().get_template(get_config().get("stats", "mainPageTemplate"))
« no previous file with comments | « no previous file | sitescripts/stats/template/fileOverview.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld