diff options
author | Pacien TRAN-GIRARD | 2014-10-24 19:59:05 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-10-24 19:59:05 +0200 |
commit | bdf9099df8c2a4636b0ad0e710b73330877eef37 (patch) | |
tree | 63fd704f15f3030f1455aad0ef92403c5d093c70 /wikibania/ban/BanDBWrapper.py | |
parent | 16529a0d212e1387eacd590c0e5e1b1a13dc2641 (diff) | |
download | wikistats-bdf9099df8c2a4636b0ad0e710b73330877eef37.tar.gz |
Very cleaner, much class, such readable, wow
Diffstat (limited to 'wikibania/ban/BanDBWrapper.py')
-rw-r--r-- | wikibania/ban/BanDBWrapper.py | 25 |
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 @@ | |||
1 | from collections import defaultdict | ||
2 | |||
3 | import numpy | ||
4 | |||
5 | |||
6 | class 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()} | ||