リビジョン | 70b9d97185740966fa69c1757c49aa1715d0e7dc (tree) |
---|---|
日時 | 2009-08-08 00:25:06 |
作者 | lorenzo |
コミッター | lorenzo |
CAVEAT: this code works only with the initial version of the library
by Ciro. However, it prints out the tag-tag contact list and the corresponding
time, i.e. everything I need to get the tag contact duration/interval
@@ -0,0 +1,76 @@ | ||
1 | +#!/usr/bin/env python | |
2 | +# loop over 20-second intervals, compute contact graph for each interval, print out the nodes of the graph | |
3 | + | |
4 | +import sys | |
5 | +from sociopatterns.loader import Loader | |
6 | +from sociopatterns.analysis import ContactGraphAnalyzer | |
7 | +#import string #Probably I do not need this module any longer. | |
8 | +#Python has a lot of methods already inbuilt for a string object. | |
9 | + | |
10 | + | |
11 | +#XXTEA_CRYPTO_KEY = ( 0xf6e103d4, 0x77a739f6, 0x65eecead, 0xa40543a9 ) | |
12 | + | |
13 | +XXTEA_CRYPTO_KEY = ( 0xd2e3fd73, 0xfa70ca9c, 0xe2575826, 0x0fe09946 ) | |
14 | + | |
15 | + | |
16 | +loader = Loader(sys.argv[1:], decode=1, xxtea_crypto_key=XXTEA_CRYPTO_KEY, | |
17 | + load_contacts=1, unique_contacts=1, load_sightings=0) | |
18 | + | |
19 | +analyzer = ContactGraphAnalyzer(loader, 20, tag_id_min=1100, tag_id_max=2047) | |
20 | + | |
21 | +for frame in analyzer: | |
22 | + | |
23 | + #Thanks Corrado! | |
24 | + | |
25 | + #I changed into a comment a lot of lines which are no longer needed. | |
26 | + | |
27 | + # my_nodes=frame['graph'].nodes() | |
28 | + # my_nodes_list=["%d" %x for x in frame['graph'].nodes()] | |
29 | + # my_nodes_string=" ".join(my_nodes_list) | |
30 | + | |
31 | + # #The same result is achieved with the suggestion by Ciro | |
32 | + | |
33 | + # #string.join(map(str, my_nodes)) ## to be used within a print statement | |
34 | + | |
35 | + # my_edge_list_ini=["%d %d" %(x, y) for x,y, in frame['graph'].edges() ] | |
36 | + | |
37 | + # my_edge_string=" ".join(my_edge_list_ini) | |
38 | + | |
39 | + # my_edge_string_vert="\n".join(my_edge_list_ini) #prints out the edge list in the form of a binary tag-tag interaction | |
40 | + | |
41 | + | |
42 | + | |
43 | + | |
44 | + # time_list_ini=[frame['time']]*len(frame['graph'].edges()) | |
45 | + # time_list_ini=["%d" %x for x in time_list_ini] | |
46 | + # time_string=" ".join(time_list_ini) | |
47 | + # time_string_vert="\n".join(time_list_ini) #prints out time as a vertical string | |
48 | + | |
49 | + | |
50 | + # # total=["%d %d %d" %(x[0], x[1], z) for x,z in zip(frame['graph'].edges(),[frame['time']]*len(frame['graph'].edges()) ) ] | |
51 | + # # total="\n".join(total) | |
52 | + | |
53 | + #Suggestion by Corrado. "\n" is a string and its .join method automatically adds another string to it. | |
54 | + #the object within [] is a list of strings from which I extract a triplet of integers. | |
55 | + | |
56 | + total="\n".join(["%d %d %d" %( frame["time"],x, y) for x,y in frame['graph'].edges()]) | |
57 | + | |
58 | + | |
59 | + | |
60 | + # time_and_edges_vert="\n".join(time_and_edges) | |
61 | + | |
62 | + | |
63 | + #old layout I had chosen for my printout | |
64 | + #use -1 as a separator | |
65 | + | |
66 | + #print frame['time'], -1, my_edge_list , -1,frame['graph'].number_of_nodes(),-1, my_nodes_list | |
67 | + | |
68 | + | |
69 | + | |
70 | + if (len(frame['graph'].edges())>0): | |
71 | + | |
72 | + print total | |
73 | + | |
74 | + | |
75 | + | |
76 | + |