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

Unified Diff: sitescripts/stats/common.py

Issue 11481051: Update stats processing (Closed)
Patch Set: Improved performance using memoization Created Aug. 29, 2013, 1:39 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 | « sitescripts/stats/bin/pagegenerator.py ('k') | sitescripts/stats/countrycodes.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/stats/common.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/stats/common.py
@@ -0,0 +1,147 @@
+# coding: utf-8
+
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-2013 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import re
+
+def filename_encode(name):
+ """
+ This encodes any string to a valid file name while ensuring that the
+ original string can still be reconstructed. All characters except 0-9, A-Z,
+ the period and underscore are encoded as "-12cd" where "12cd" stands for the
+ hexadecimal representation of the character's ordinal.
+ """
+ return re.sub(r"[^\w\.]", lambda match: "-%04x" % ord(match.group(0)), name)
+
+def filename_decode(path):
+ """
+ This reconstructs a string encoded with filename_encode().
+ """
+ return re.sub(r"-([0-9a-f]{4})", lambda match: unichr(int(match.group(1), 16)), path)
+
+basic_fields = [
+ {
+ "name": "day",
+ "title": "Days of month",
+ "coltitle": "Day",
+ "showaverage": True,
+ "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)),
+ },
+ {
+ "name": "weekday",
+ "title": "Days of week",
+ "coltitle": "Weekday",
+ "showaverage": True,
+ "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)),
+ "isspecial": lambda weekday: weekday == 5 or weekday == 6,
+ },
+ {
+ "name": "hour",
+ "title": "Hours of day",
+ "coltitle": "Hour",
+ "showaverage": True,
+ "sort": lambda obj: sorted(obj.items(), key=lambda (k,v): int(k)),
+ },
+ {
+ "name": "country",
+ "title": "Countries",
+ "coltitle": "Country",
+ },
+ {
+ "name": "ua",
+ "title": "Browsers",
+ "coltitle": "Browser",
+ },
+ {
+ "name": "fullua",
+ "title": "Browser versions",
+ "coltitle": "Browser version",
+ },
+ {
+ "name": "mirror",
+ "title": "Download mirrors",
+ "coltitle": "Download mirror",
+ },
+]
+
+downloader_fields = [
+ {
+ "name": "addonName",
+ "title": "Extensions",
+ "coltitle": "Extension",
+ },
+ {
+ "name": "fullAddon",
+ "title": "Extension versions",
+ "coltitle": "Extension version",
+ },
+ {
+ "name": "application",
+ "title": "Host applications",
+ "coltitle": "Host application",
+ },
+ {
+ "name": "fullApplication",
+ "title": "Host application versions",
+ "coltitle": "Host application version",
+ },
+ {
+ "name": "platform",
+ "title": "Platforms",
+ "coltitle": "Platform",
+ },
+ {
+ "name": "fullPlatform",
+ "title": "Platform versions",
+ "coltitle": "Platform version",
+ },
+ {
+ "name": "downloadInterval",
+ "title": "Download intervals",
+ "coltitle": "Download interval",
+ },
+ {
+ "name": "firstDownload",
+ "title": "Initial download",
+ "filter": True,
+ },
+ {
+ "name": "firstInDay",
+ "title": "First download this day",
+ "filter": True,
+ },
+ {
+ "name": "firstInWeek",
+ "title": "First download this week",
+ "filter": True,
+ },
+ {
+ "name": "firstInMonth",
+ "title": "First download this month",
+ "filter": True,
+ },
+]
+
+install_fields = [
+ {
+ "name": "installType",
+ "title": "Install types",
+ "coltitle": "Install type",
+ },
+]
+
+
+fields = basic_fields + downloader_fields + install_fields
« no previous file with comments | « sitescripts/stats/bin/pagegenerator.py ('k') | sitescripts/stats/countrycodes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld