In [12]:
import csv,os,json

results_path="/home/clemsos/Dev/mitras/results"
meme_names=[ meme for meme in os.listdir(results_path) if meme[-3:] != "csv"]
#meme_names=["biaoge"]

meme_names.sort()

In [161]:
graphs=[]
for meme_name in meme_names:
    meme_path=results_path+"/"+meme_name
    json_file=meme_path+"/"+meme_name+"_graph_info.json"
    
    try :
        with open(json_file, 'rb') as memejson:
            data=json.loads(memejson.read())
            graphs.append((meme_name,data))
    except IOError:
        print "missing file %s"%json_file


missing file /home/clemsos/Dev/mitras/results/diaosi/diaosi_graph_info.json
missing file /home/clemsos/Dev/mitras/results/dufu/dufu_graph_info.json
missing file /home/clemsos/Dev/mitras/results/gangnam/gangnam_graph_info.json
missing file /home/clemsos/Dev/mitras/results/hougong/hougong_graph_info.json
missing file /home/clemsos/Dev/mitras/results/moyan/moyan_graph_info.json
missing file /home/clemsos/Dev/mitras/results/qiegao/qiegao_graph_info.json
missing file /home/clemsos/Dev/mitras/results/sextape/sextape_graph_info.json
missing file /home/clemsos/Dev/mitras/results/tuhao/tuhao_graph_info.json
missing file /home/clemsos/Dev/mitras/results/yuanfang/yuanfang_graph_info.json

In [47]:
modularities=[]
names=[]
indexes=[]
for i,graph in enumerate(graphs):
    g=graph[1]
    
    meme_name=graph[0]
    names.append(meme_name)
    indexes.append(i)

    #print modularity
    #modularities.append(modularity)
    #plt.plot(indexes,modularities)

In [43]:
print meme_names


['biaoge', 'ccp', 'diaosi', 'dufu', 'gangnam', 'hougong', 'moyan', 'qiegao', 'sextape', 'thevoice', 'tuhao', 'yuanfang']

In [94]:
%pylab inline

modularities=[.56125512]
names=["test"]
indexes=[0]

i=1

g=graph[i]
g
graph=graphs[0]
meme_name=graph[0]
names.append(meme_name)
indexes.append(i)

# modularity
modularity=g["communities"]["modularity"]
modularities.append(modularity)
print modularity

w=10 # width of the canvas
h=8 # height of the canvas
    
fig = plt.figure(figsize=(w,h))
bars = fig.add_subplot(111)

bars.set_ylabel("Modularity")
bars.set_xlabel('Memes')
bars.set_title("Modularity of the user conversation graphs")

bars.grid(True,linestyle='-',color='0.75')
bars.bar(indexes,modularities,facecolor='#2ca02c', align='center', edgecolor="#74c476")

bars.set_xticks(indexes)
bars.set_xticklabels(names,fontsize=12)
bars.set_axisbelow(indexes)
# fig.autofmt_xdate()


Populating the interactive namespace from numpy and matplotlib
0.888808663035

Betweeness_centrality distribution


In [135]:
%pylab inline

from random import uniform, randint

# init with fake data
names=["test"]
indexes=[0]
test=[{'count': randint(0,200), 'value':uniform(0,0.1)} for c in range(50)]
test.sort(key=lambda x:x['value'])
btw_cents=[test]

colors=["#2ca02c","red"]

# load data
i=1
g=graph[i]
graph=graphs[0]
meme_name=graph[0]
names.append(meme_name)
indexes.append(i)

# betweeness_centrality
w=10 # width of the canvas
h=8 # height of the canvas
    
fig = plt.figure(figsize=(w,h))
bars = fig.add_subplot(111)

bars.set_xlabel("Betweeness Centrality")
bars.set_ylabel('Count')
bars.set_title("Betweeness centrality of users in conversation graphs (distribution)")

bars.grid(True,linestyle='-',color='0.75')

btw_cents.append(g["betweeness_centrality"]["distribution"])
for j,btw_cent_dist in enumerate(btw_cents): 
    
    btw_cent_values=[float(v["value"]) for v in  btw_cent_dist]
    btw_cent_count=[v["count"]for v in  btw_cent_dist]
    #print btw_cent_count, btw_cent_values
    
    bars.plot(btw_cent_values,btw_cent_count, color=colors[j]) 
    # bars.loglog(sorted(btw_cent_count, reverse=True))
    #bars.bar(btw_cent_count,btw_cent_values,facecolor='#2ca02c', align='center', edgecolor="#74c476")


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['uniform', 'randint', 'colors', 'test']
`%pylab --no-import-all` prevents importing * from pylab and numpy

In [165]:
%pylab inline --no-import-all

# load data
i=1
graph=graphs[0]
g=graph[i]
meme_name=graph[0]
names.append(meme_name)
indexes.append(i)


# title, ylabel, value_set
modularities=[]
avg_btw_cent=[]
avg_cluster_coef=[]
avg_deg=[]
indexes=[]
names=[]

for j,graph in enumerate(graphs):
    
    g=graph[1]
    
    meme_name=graph[0]
    names.append(meme_name)
    
    try :
        modularities.append(g["communities"]["modularity"])
        avg_btw_cent.append(g["graph"]["average_betweeness_centrality"])
        avg_cluster_coef.append(g["graph"]["average_clustering_coeficient"])
        avg_deg.append(g["graph"]["average_degree"])
        indexes.append(j)
    except KeyError :
        pass


plots_data=[{"title":"Modularity of the user conversation graphs", "ylabel":"Modularity", "values":modularities },
{"title":"average_betweeness_centrality of the user conversation graphs", "ylabel":"average_betweeness_centrality", "values":avg_btw_cent },
{"title":"average_clustering_coeficient of the user conversation graphs", "ylabel":"average_clustering_coeficient", "values":avg_cluster_coef},
{"title":"average_degree of the user conversation graphs", "ylabel":"average_degree", "values":avg_deg}]

for plot in plots_data:
    w=10 # width of the canvas
    h=8 # height of the canvas
        
    fig = plt.figure(figsize=(w,h))
    bars = fig.add_subplot(111)
    
    bars.set_ylabel(plot["ylabel"])
    bars.set_xlabel('Memes')
    bars.set_title(plot["title"])

    
    bars.grid(True,linestyle='-',color='0.75')
    bars.bar(indexes,plot["values"],facecolor='#2ca02c', align='center', edgecolor="#74c476")
    
    bars.set_xticks(indexes)
    bars.set_xticklabels(names,fontsize=12)
    bars.set_axisbelow(indexes)


Populating the interactive namespace from numpy and matplotlib

In [ ]:
modularity=
modularities.append(modularity)
print modularity

w=10 # width of the canvas
h=8 # height of the canvas
    
fig = plt.figure(figsize=(w,h))
bars = fig.add_subplot(111)

bars.set_ylabel(ylabel)
bars.set_xlabel('Memes')
bars.set_title(title)

bars.grid(True,linestyle='-',color='0.75')
bars.bar(indexes,modularities,facecolor='#2ca02c', align='center', edgecolor="#74c476")

bars.set_xticks(indexes)
bars.set_xticklabels(names,fontsize=12)
bars.set_axisbelow(indexes)
# fig.autofmt_xdate()