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 = 1000 BAN_FILE = "resources/ban_list.json" ban_dict_list = bandict.BanList(BAN_FILE, samples=SAMPLES, from_internet=True) # ======== 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))