summaryrefslogtreecommitdiff
path: root/wikibania/ban/BanDBWrapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'wikibania/ban/BanDBWrapper.py')
-rw-r--r--wikibania/ban/BanDBWrapper.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/wikibania/ban/BanDBWrapper.py b/wikibania/ban/BanDBWrapper.py
new file mode 100644
index 0000000..8f396b0
--- /dev/null
+++ b/wikibania/ban/BanDBWrapper.py
@@ -0,0 +1,25 @@
1from collections import defaultdict
2
3import numpy
4
5
6class BanDBWrapper:
7 def __init__(self, ban_db):
8 self.ban_db = ban_db
9
10 def get_all_durations(self):
11 return [ban.calc_duration() for ban in self.ban_db.list()]
12
13 def get_all_countries(self):
14 return [ban.lookup_country_code() for ban in self.ban_db.list()]
15
16 def get_durations_by_country(self):
17 return [(ban.lookup_country_code(), ban.calc_duration()) for ban in self.ban_db.list()]
18
19 def calc_average_duration_by_country(self):
20 ban_durations_by_country = defaultdict(list)
21
22 for country, ban_duration in self.get_durations_by_country():
23 ban_durations_by_country[country].append(ban_duration)
24
25 return {country: numpy.mean(ban_durations) for country, ban_durations in ban_durations_by_country.items()}