import repository from arizona
[raven.git] / demo / pingpong / scripts / gennodelist.py
1 import dateutil.parser
2 from distutils.version import LooseVersion
3 import os
4 import json
5 import random
6 import time
7
8 MAX_AGE = 300
9 NUM_GUEST = 35
10 NODES_PER_GUEST = 40
11
12 def to_timet(x):
13     try:
14         return time.mktime(dateutil.parser.parse(x).timetuple())
15     except:
16         print "error converting time",x
17         return 0
18
19 def node_timestamp(x):
20     if not "_internal.date" in x:
21         return 0
22     return to_timet(x["_internal.date"])
23
24 def node_stork(x):
25     if not "stork.version" in x:
26         return "-1"
27     else:
28         return x["stork.version"]
29
30 def choose_random(list, count):
31     list = list[:]
32     random.shuffle(list)
33     return list[:count]
34
35 # os.system("wget http://owl.cs.arizona.edu/owl/json?db=arizona_beta -O owl.json")
36
37 x = file("owl.json","r").read()
38 owl = json.read(x)
39 nodes = owl["data"]
40
41 print nodes[0].keys()
42 # print node_timestamp(nodes[0])
43
44 highest_ts = None
45 highest_stork = None
46 for node in nodes:
47     this_time = node_timestamp(node)
48     if (highest_ts==None) or (this_time > highest_ts):
49         highest_ts = this_time
50     if (highest_stork==None) or (LooseVersion(node_stork(node)) > LooseVersion(node_stork(highest_stork))):
51         highest_stork = node_stork(node)
52
53 print "total nodes:", len(nodes)
54 print "highest_ts:", highest_ts
55 print "highest_stork:", highest_stork
56
57 recent_nodes=[]
58 for node in nodes:
59     this_time = node_timestamp(node)
60     if (this_time >= highest_ts-MAX_AGE):
61         recent_nodes.append(node)
62
63 print "recent nodes:", len(recent_nodes)
64
65 acceptable_nodes=[]
66 for node in recent_nodes:
67     if node_stork(node) == highest_stork:
68         acceptable_nodes.append(node)
69
70 print "acceptable nodes:", len(acceptable_nodes)
71
72 acceptable_names = [node["basic.id"] for node in acceptable_nodes]
73
74 file("../nodelists/all_nodes","w").write("\n".join(acceptable_names))
75
76 random.seed(0)
77
78 for i in range(1, NUM_GUEST+1):
79    this_names = choose_random(acceptable_names, NODES_PER_GUEST)
80    file("../nodelists/guest" + str(i) + "_nodes","w").write("\n".join(this_names))
81
82
83
84
85
86