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

Unified Diff: abp/stats/filterhits.py

Issue 30037555: NoIssue - Added filterhit statistics loading capability
Patch Set: Created April 3, 2019, 4:07 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 | « abp/stats/__init__.py ('k') | tests/test_stats/data/filterhits.csv » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: abp/stats/filterhits.py
diff --git a/abp/stats/filterhits.py b/abp/stats/filterhits.py
new file mode 100644
index 0000000000000000000000000000000000000000..311b1600a4bff9820564692597add72454afc9f6
--- /dev/null
+++ b/abp/stats/filterhits.py
@@ -0,0 +1,49 @@
+# This file is part of Adblock Plus <https://adblockplus.org/>,
+# Copyright (C) 2006-present 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/>.
+
+"""Helping methods for filterhit-related statistics."""
+
+import csv
+
+
+def load_filterhit_statistics(path, sources=None):
+ """Load filterhit statistics from a csv file.
+
+ Parameters
+ ----------
+ path: str
+ Path to the csv file with the filterhit statistics.
+ sources: iterable of str
+ With the filter sources we're interested in. If not None, only filters
+ from these sources will be included in the result.
+
+ Returns
+ -------
+ generator of dict
+ With the csv entries.
+
+ """
+ integer_cols = ['onehour_sessions', 'hits']
+
+ with open(path) as csvstream:
+ reader = csv.DictReader(csvstream)
+
+ for entry in reader:
+ if sources and entry['source'] not in sources:
+ continue
+ for col in integer_cols:
+ entry[col] = int(entry[col])
+
+ yield entry
« no previous file with comments | « abp/stats/__init__.py ('k') | tests/test_stats/data/filterhits.csv » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld