OLD | NEW |
(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'] |
| 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 entry[col] = int(entry[col]) |
| 48 |
| 49 yield entry |
OLD | NEW |