summaryrefslogtreecommitdiff
path: root/main.py
blob: 6fd59ce54409b1d9984ca5bf6eb688d5009dc42a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from banapedia.Ban import *
import bandict
from collections import Counter
import pygal
import numpy as np

BAN_MAP_FILE = "output/ban-map.svg"
BAN_DURATION_MAP_FILE = "output/ban-duration-map.svg"
HIST_FILE = "output/histogram.svg"

SAMPLES = 30000

BAN_FILE = "resources/ban_list.json"

ban_dict_list = bandict.BanList(BAN_FILE)

# ======== HISTOGRAM ======= #

ban_durations = ban_dict_list.get_durations()
(ban_durations_bars, bins) = np.histogram(ban_durations,
                                          bins=[round(365/12*x)
                                                for x in range(1, 50+2)
                                                ]
                                          )

print("[INFO]", "Generating histogram")
bar_chart = pygal.Bar(legend_at_bottom=True)
bar_chart.title = "Active Wikipedia bans by duration (%d samples)" % SAMPLES
bar_chart.x_labels = map(str, range(1, len(ban_durations_bars)+1))
bar_chart.add("Number of active bans", ban_durations_bars)
bar_chart.render_to_file(HIST_FILE)
print("[INFO]", "Histogram generation complete")

# ======= NB BAN MAP ======= #

country_ban_list = ban_dict_list.get_countries()
nb_bans_by_country = Counter(country_ban_list)

print("[INFO]", "Generating ban map")
worldmap_chart = pygal.Worldmap(legend_at_bottom=True)
worldmap_chart.title = "World active Wikipedia bans by country (%d samples)" % SAMPLES
worldmap_chart.add("Active bans", nb_bans_by_country)
worldmap_chart.render_to_file(BAN_MAP_FILE)
print("[INFO]", "Ban map generation complete")


# ======= BAN DURATION MAP ======= #

average_ban_duration_by_country = ban_dict_list.average_ban_by_country()

print("[INFO]", "Generating ban duration map")
worldmap_chart = pygal.Worldmap(legend_at_bottom=True)
worldmap_chart.title = "Average Wikipedia ban duration by country (%d samples)" % SAMPLES
worldmap_chart.add("Average ban duration (months)", average_ban_duration_by_country)
worldmap_chart.render_to_file(BAN_DURATION_MAP_FILE)
print("[INFO]", "Ban duration map generation complete")

print("Some additional stats about ban durations:")
print("  Mean: %.2f days" % np.mean(ban_durations))
print("  Median: %.2f days" % np.median(ban_durations))
print("  Deviation: %.2f" % np.std(ban_durations))
print("  Variance: %.2f" % np.var(ban_durations))