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

Delta Between Two Patch Sets: sitescripts/stats/bin/pagegenerator.py

Issue 5664623214723072: Issue 1560 - ZeroDivisionError in sitescripts.stats.bin.pagegenerator (Closed)
Left Patch Set: Created Nov. 12, 2014, 7:43 p.m.
Right Patch Set: Better work-around for zero divisors Created Nov. 12, 2014, 8:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | sitescripts/stats/template/fileOverview.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2014 Eyeo GmbH 4 # Copyright (C) 2006-2014 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 10 matching lines...) Expand all
21 import sitescripts.stats.common as common 21 import sitescripts.stats.common as common
22 from sitescripts.stats.countrycodes import countrycodes 22 from sitescripts.stats.countrycodes import countrycodes
23 23
24 @cached(float("inf")) 24 @cached(float("inf"))
25 def get_template_environment(): 25 def get_template_environment():
26 return get_custom_template_environment({ 26 return get_custom_template_environment({
27 "monthname": lambda value: date(int(value[0:4]), int(value[4:]), 1).strftime ("%b %Y"), 27 "monthname": lambda value: date(int(value[0:4]), int(value[4:]), 1).strftime ("%b %Y"),
28 "weekday": lambda value: ["Monday", "Tuesday", "Wednesday", "Thursday", "Fri day", "Saturday", "Sunday"][int(value)], 28 "weekday": lambda value: ["Monday", "Tuesday", "Wednesday", "Thursday", "Fri day", "Saturday", "Sunday"][int(value)],
29 "countryname": lambda value: countrycodes.get(value, "Unknown"), 29 "countryname": lambda value: countrycodes.get(value, "Unknown"),
30 "sortfield": lambda value, field: (field["sort"] if "sort" in field else def ault_sort)(value), 30 "sortfield": lambda value, field: (field["sort"] if "sort" in field else def ault_sort)(value),
31 "maxhits": lambda items: max(itertools.chain((value["hits"] for key, value i n items), [1])), 31 "maxhits": lambda items: max(value["hits"] for key, value in items),
32 "maxbandwidth": lambda items: max(itertools.chain((value["bandwidth"] for ke y, value in items), [1])), 32 "maxbandwidth": lambda items: max(value["bandwidth"] for key, value in items ),
33 "sumhits": lambda items: max(sum(value["hits"] for key, value in items), 1), 33 "sumhits": lambda items: sum(value["hits"] for key, value in items),
34 "sumbandwidth": lambda items: max(sum(value["bandwidth"] for key, value in i tems), 1), 34 "sumbandwidth": lambda items: sum(value["bandwidth"] for key, value in items ),
35 "percentage": lambda value, total: float(value) / total * 100 if total != 0 else 0,
35 "isspecial": lambda name, field: field["isspecial"](name) if "isspecial" in field else False, 36 "isspecial": lambda name, field: field["isspecial"](name) if "isspecial" in field else False,
36 "defaultcount": get_default_count, 37 "defaultcount": get_default_count,
37 }) 38 })
38 39
39 @cached(float("inf")) 40 @cached(float("inf"))
40 def get_main_page_template(): 41 def get_main_page_template():
41 return get_template_environment().get_template(get_config().get("stats", "main PageTemplate")) 42 return get_template_environment().get_template(get_config().get("stats", "main PageTemplate"))
42 43
43 @cached(float("inf")) 44 @cached(float("inf"))
44 def get_file_stats_template(): 45 def get_file_stats_template():
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 164
164 outputfile = os.path.join(outputdir, common.filename_encode(server_type), "i ndex.html") 165 outputfile = os.path.join(outputdir, common.filename_encode(server_type), "i ndex.html")
165 generate_main_page(outputfile, current_month, baseURL, monthdata) 166 generate_main_page(outputfile, current_month, baseURL, monthdata)
166 167
167 if __name__ == '__main__': 168 if __name__ == '__main__':
168 setupStderr() 169 setupStderr()
169 170
170 datadir = get_config().get("stats", "dataDirectory") 171 datadir = get_config().get("stats", "dataDirectory")
171 outputdir = get_config().get("stats", "outputDirectory") 172 outputdir = get_config().get("stats", "outputDirectory")
172 generate_pages(datadir, outputdir) 173 generate_pages(datadir, outputdir)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld