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

Side by Side Diff: sitescripts/stats/common.py

Issue 29934561: #1537 - Remove stats processing from sitescripts (Closed) Base URL: https://hg.adblockplus.org/sitescripts
Patch Set: Created Nov. 2, 2018, 12:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH
3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 import re
17 import hashlib
18
19
20 def filename_encode(name):
21 """
22 This encodes any string to a valid file name while ensuring that the
23 original string can still be reconstructed. All characters except 0-9, A-Z ,
24 the period and underscore are encoded as "-12cd" where "12cd" stands for t he
25 hexadecimal representation of the character's ordinal. File names longer
26 than 150 characters will be still be unique but no longer reversible due t o
27 file system limitations.
28 """
29 result = re.sub(r'[^\w\.]', lambda match: '-%04x' % ord(match.group(0)), nam e)
30 if len(result) > 150:
31 result = result[:150] + '--%s' % hashlib.md5(result[150:]).hexdigest()
32 return result
33
34
35 def filename_decode(path):
36 """
37 This reconstructs a string encoded with filename_encode().
38 """
39 path = re.sub(r'--[0-9A-Fa-f]{32}', u'\u2026', path)
40 path = re.sub(r'-([0-9a-f]{4})', lambda match: unichr(int(match.group(1), 16 )), path)
41 return path
42
43
44 basic_fields = [
45 {
46 'name': 'day',
47 'title': 'Days of month',
48 'coltitle': 'Day',
49 'showaverage': True,
50 'defaultcount': 31,
51 'sort': lambda obj: sorted(obj.items(), key=lambda (k, v): int(k)),
52 },
53 {
54 'name': 'weekday',
55 'title': 'Days of week',
56 'coltitle': 'Weekday',
57 'showaverage': True,
58 'sort': lambda obj: sorted(obj.items(), key=lambda (k, v): int(k)),
59 'isspecial': lambda weekday: weekday == 5 or weekday == 6,
60 },
61 {
62 'name': 'hour',
63 'title': 'Hours of day',
64 'coltitle': 'Hour',
65 'showaverage': True,
66 'sort': lambda obj: sorted(obj.items(), key=lambda (k, v): int(k)),
67 },
68 {
69 'name': 'country',
70 'title': 'Countries',
71 'coltitle': 'Country',
72 },
73 {
74 'name': 'ua',
75 'title': 'Browsers',
76 'coltitle': 'Browser',
77 },
78 {
79 'name': 'fullua',
80 'title': 'Browser versions',
81 'coltitle': 'Browser version',
82 },
83 {
84 'name': 'referrer',
85 'title': 'Referrers',
86 'coltitle': 'Referrer',
87 },
88 {
89 'name': 'status',
90 'title': 'Status codes',
91 'coltitle': 'Status code',
92 },
93 {
94 'name': 'mirror',
95 'title': 'Download mirrors',
96 'coltitle': 'Download mirror',
97 },
98 ]
99
100 downloader_fields = [
101 {
102 'name': 'addonName',
103 'title': 'Extensions',
104 'coltitle': 'Extension',
105 },
106 {
107 'name': 'fullAddon',
108 'title': 'Extension versions',
109 'coltitle': 'Extension version',
110 },
111 {
112 'name': 'application',
113 'title': 'Host applications',
114 'coltitle': 'Host application',
115 },
116 {
117 'name': 'fullApplication',
118 'title': 'Host application versions',
119 'coltitle': 'Host application version',
120 },
121 {
122 'name': 'platform',
123 'title': 'Platforms',
124 'coltitle': 'Platform',
125 },
126 {
127 'name': 'fullPlatform',
128 'title': 'Platform versions',
129 'coltitle': 'Platform version',
130 },
131 {
132 'name': 'downloadInterval',
133 'title': 'Download intervals',
134 'coltitle': 'Download interval',
135 },
136 {
137 'name': 'previousDownload',
138 'hidden': True,
139 },
140 {
141 'name': 'firstDownload',
142 'title': 'Initial download',
143 'filter': True,
144 },
145 {
146 'name': 'firstInDay',
147 'title': 'First download this day',
148 'filter': True,
149 },
150 {
151 'name': 'firstInWeek',
152 'title': 'First download this week',
153 'filter': True,
154 },
155 {
156 'name': 'firstInMonth',
157 'title': 'First download this month',
158 'filter': True,
159 },
160 ]
161
162 install_fields = [
163 {
164 'name': 'installType',
165 'title': 'Install types',
166 'coltitle': 'Install type',
167 },
168 ]
169
170
171 fields = basic_fields + downloader_fields + install_fields
OLDNEW

Powered by Google App Engine
This is Rietveld