Index: sitescripts/stats/bin/pagegenerator.py |
=================================================================== |
--- a/sitescripts/stats/bin/pagegenerator.py |
+++ b/sitescripts/stats/bin/pagegenerator.py |
@@ -28,16 +28,17 @@ def get_template_environment(): |
"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), |
"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")) |
@cached(float("inf")) |
def get_file_stats_template(): |
@@ -88,16 +89,19 @@ def generate_file_overview(outputfile, u |
}).dump(outputfile, encoding="utf-8") |
def get_names(dir, needdirectories): |
for file in os.listdir(dir): |
path = os.path.join(dir, file) |
if (needdirectories and os.path.isdir(path)) or (not needdirectories and os.path.isfile(path)): |
yield common.filename_decode(file), path |
+def get_default_count(field): |
+ return field.get("defaultcount", 30) |
+ |
def generate_pages(datadir, outputdir): |
for server_type, server_type_dir in get_names(datadir, True): |
baseURL = get_config().get("stats", "baseURL_" + server_type) |
filedata = {} |
current_month = None |
for month, month_dir in get_names(server_type_dir, True): |
if current_month == None or month > current_month: |
current_month = month |
@@ -109,17 +113,18 @@ def generate_pages(datadir, outputdir): |
overview_url = "../../overview-" + common.filename_encode(filename + ".html") |
filtered_urls = {} |
for field in common.fields: |
if field["name"] not in data: |
continue |
# Create filtered views for the first thirty values of a field if they |
# have filtered data. |
- for name, value in get_template_environment().filters["sortfield"](data[field["name"]], field)[0:30]: |
+ sorted_field = get_template_environment().filters["sortfield"](data[field["name"]], field) |
+ for name, value in sorted_field[0:get_default_count(field)]: |
if filter(lambda k: k not in ("hits", "bandwidth"), value.iterkeys()): |
outputfile = os.path.join(outputdir, |
common.filename_encode(server_type), |
common.filename_encode(month), |
common.filename_encode(filename), |
"filtered-%s-%s.html" % ( |
common.filename_encode(field["name"]), |
common.filename_encode(name), |