In [1]:
from pymongo import MongoClient
import datetime
In [2]:
client = MongoClient()
In [3]:
db = client['saa-2_samples_raw']
In [4]:
coll = db['axelrod_stats_treestructured']
In [5]:
db.collection_names()
Out[5]:
In [6]:
coll.count()
Out[6]:
In [7]:
ids = coll.find({"run_finalized": 1},{"_id": 1})
In [8]:
ids
Out[8]:
In [9]:
id_list = []
for id in ids:
id_list.append(id)
In [10]:
len(id_list)
Out[10]:
In [11]:
import random
In [12]:
selected_ids = random.sample(id_list, 20)
In [13]:
selected_ids
Out[13]:
In [14]:
test_id = selected_ids[0]
In [15]:
res = coll.find_one(test_id, fields={'culture_graphml_repr'})
In [16]:
graph_list = res['culture_graphml_repr']
In [17]:
len(graph_list)
Out[17]:
In [18]:
import networkx as nx
In [19]:
graphs = []
for g in graph_list:
g_c = g['content']
graph = nx.parse_graphml(g_c)
graphs.append(graph)
In [20]:
for i in range(0, len(graphs)):
fname = "random-trait-graph-"
fname += str(i)
fname += ".dot"
nx.write_dot(graphs[i], fname)
In [21]:
import madsenlab.axelrod.utils as utils
In [22]:
rec = 0
selected_ids = random.sample(id_list, 1)
for id in selected_ids:
res = coll.find_one(id, fields={'culture_graphml_repr'})
graph_list = res['culture_graphml_repr']
graphs = []
for g in graph_list:
g_c = g['content']
graph = nx.parse_graphml(g_c)
graphs.append(graph)
for i in range(0, len(graphs)):
fname = "tmp/random-trait-graph-"
fname += "%03d" % rec
fname += ".dot"
utils.write_ordered_dot(graphs[i], fname, str(id))
rec += 1
In [23]:
p = utils.generate_ordered_dot(graph, "foo")
In [24]:
import re
In [1]:
n = 5124
import math
l = math.log10(n)
o = int(math.ceil(l))
print o
In [ ]: