In [1]:
%matplotlib inline
In [51]:
import bigbang.mailman as mailman
import bigbang.graph as graph
import bigbang.process as process
from bigbang.parse import get_date
from bigbang.archive import Archive
import bigbang.twopeople as twoppl
reload(process)
import pandas as pd
import datetime
import matplotlib.pyplot as plt
import numpy as np
import math
import pytz
import pickle
import os
pd.options.display.mpl_style = 'default' # pandas has a set of preferred graph formatting options
In [109]:
#:::::::::::::::::::::::::::::::::
#insert one or more urls of the mailing lists you want to include in the analysis
#if more mailing lists are included, the data are aggregated and treated as a single object of analysis
#e.g. urls = []
urls = ["http://lists.ncuc.org/pipermail/ncuc-discuss/",
"https://mm.icann.org/pipermail/cc-humanrights/"]
archives = [mailman.open_list_archives(url,"../archives") for url in urls]
archives = pd.concat(archives)
In [145]:
#comput and plot top senders (people sending out emails)
#set the number of top senders to be displayed
n_top_senders = 5
activity = Archive.get_activity(Archive(archives))
tot_activity = activity.sum(0)
tot_activity.sort()
print tot_activity[-n_top_senders:]
tot_activity[-n_top_senders:].plot(kind = 'barh', width = 1)
Out[145]:
In [111]:
#compute replies list (sender+replier)
arc_data = Archive(archives).data
from_users = arc_data[['From']]
to_users = arc_data[arc_data['In-Reply-To'] > 0][['From','Date','In-Reply-To']]
replies = pd.merge(from_users, to_users, how='inner',
right_on='In-Reply-To',left_index=True,
suffixes=['_original','_response'])
In [117]:
#compute and plot top repliers (people responding to mails)
#set the number of top repliers to be displayed
n_top_repliers = 10
from collections import defaultdict
repliers_count = defaultdict(int)
for reply in replies['From_response']:
repliers_count[reply] += 1
repliers_count = sorted(repliers_count.iteritems(), key = lambda (k,v):(v,k))
for replier_count in repliers_count[-n_top_repliers:]:
print replier_count[0]+' '+str(replier_count[1])
repliers_count = pd.DataFrame.from_records(repliers_count, index = 0)
repliers_count[-n_top_repliers:].plot(kind = 'barh', width = 1)
Out[117]:
In [144]:
#compute and plot top dyads (pairs of replier-receiver)
#select the number of top dyads to be desplayed
n_top_dyads = 10
dyads = twoppl.panda_allpairs(replies, twoppl.unique_pairs(replies))
dyads = dyads.sort("num_replies", ascending = False)
print dyads[:n_top_dyads]["A"]+' '+dyads[:n_top_dyads]["B"]+' '+str(dyads[:n_top_dyads]["num_replies"])
dyads['dyad'] = dyads['A']+dyads['B']
dyads[:n_top_dyads].plot(kind = 'barh', width = 1, x = 'dyad', y = 'num_replies')
Out[144]:
In [ ]: