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

Side by Side Diff: abp/stats/filterhits.py

Issue 30037555: NoIssue - Added filterhit statistics loading capability
Patch Set: Addressed Initial Comments Created April 3, 2019, 5:15 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
« no previous file with comments | « abp/stats/__init__.py ('k') | setup.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # This file is part of Adblock Plus <https://adblockplus.org/>,
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 """Helping methods for filterhit-related statistics."""
17
18 import csv
19
20
21 def load_filterhit_statistics(path, sources=None):
22 """Load filterhit statistics from a csv file.
23
24 Parameters
25 ----------
26 path: str
27 Path to the csv file with the filterhit statistics.
28 sources: iterable of str
29 With the filter sources we're interested in. If not None, only filters
30 from these sources will be included in the result.
31
32 Returns
33 -------
34 generator of dict
35 With the csv entries.
36
37 """
38 integer_cols = ['onehour_sessions', 'hits', 'domains', 'rootdomains']
39
40 with open(path) as csvstream:
41 reader = csv.DictReader(csvstream)
42
43 for entry in reader:
44 if sources and entry['source'] not in sources:
45 continue
46 for col in integer_cols:
47 try:
48 entry[col] = int(entry[col])
49 except KeyError:
50 continue
51
52 yield entry
OLDNEW
« no previous file with comments | « abp/stats/__init__.py ('k') | setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld