Revisão | df51ef4089652d534525d8179079a0407fc2bb54 (tree) |
---|---|
Hora | 2009-09-01 21:47:02 |
Autor | lorenzo |
Commiter | lorenzo |
This code can be used to study the presence of people at a conference (or
in general in a situation when the bootcount is not needed since each tag
unambiguously identifies a visitor). It relies on contact reports rather than
sighting reports to detect the presence of the tags (contact reports are
broadcast more often and at higher power). It fundamentally prints out all the
nodes (hence also isolated tags) of the graph built in a given timeslice.
@@ -0,0 +1,86 @@ | ||
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 = (0xf6e103d4, 0x77a739f6, 0x65eecead, 0xa40543a9 ) | |
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 | +#NB: now I am NOT filtering on the tag IDs | |
22 | + | |
23 | +analyzer = ContactGraphAnalyzer(loader, 20) | |
24 | + | |
25 | + | |
26 | +for frame in analyzer: | |
27 | + | |
28 | + #Thanks Corrado! | |
29 | + | |
30 | + #I changed into a comment a lot of lines which are no longer needed. | |
31 | + | |
32 | + # my_nodes=frame['graph'].nodes() | |
33 | + # my_nodes_list=["%d" %x for x in frame['graph'].nodes()] | |
34 | + # my_nodes_string=" ".join(my_nodes_list) | |
35 | + | |
36 | + # #The same result is achieved with the suggestion by Ciro | |
37 | + | |
38 | + # #string.join(map(str, my_nodes)) ## to be used within a print statement | |
39 | + | |
40 | + # my_edge_list_ini=["%d %d" %(x, y) for x,y, in frame['graph'].edges() ] | |
41 | + | |
42 | + # my_edge_string=" ".join(my_edge_list_ini) | |
43 | + | |
44 | + # my_edge_string_vert="\n".join(my_edge_list_ini) #prints out the edge list in the form of a binary tag-tag interaction | |
45 | + | |
46 | + | |
47 | + | |
48 | + | |
49 | + # time_list_ini=[frame['time']]*len(frame['graph'].edges()) | |
50 | + # time_list_ini=["%d" %x for x in time_list_ini] | |
51 | + # time_string=" ".join(time_list_ini) | |
52 | + # time_string_vert="\n".join(time_list_ini) #prints out time as a vertical string | |
53 | + | |
54 | + | |
55 | + # # total=["%d %d %d" %(x[0], x[1], z) for x,z in zip(frame['graph'].edges(),[frame['time']]*len(frame['graph'].edges()) ) ] | |
56 | + # # total="\n".join(total) | |
57 | + | |
58 | + #Suggestion by Corrado. "\n" is a string and its .join method automatically adds another string to it. | |
59 | + #the object within [] is a list of strings from which I extract a triplet of integers. | |
60 | + | |
61 | + # total="\n".join(["%d %d %d" %( frame["time"],x, y) for x,y in frame['graph'].edges()]) | |
62 | + | |
63 | + total="\n".join(["%d %d" %( frame["time"],x) for x in frame['graph'].nodes()]) | |
64 | + | |
65 | + | |
66 | + # total=frame['graph'].nodes() | |
67 | + | |
68 | + | |
69 | + | |
70 | + # time_and_edges_vert="\n".join(time_and_edges) | |
71 | + | |
72 | + | |
73 | + #old layout I had chosen for my printout | |
74 | + #use -1 as a separator | |
75 | + | |
76 | + #print frame['time'], -1, my_edge_list , -1,frame['graph'].number_of_nodes(),-1, my_nodes_list | |
77 | + | |
78 | + | |
79 | + | |
80 | + if (len(frame['graph'].nodes())>0): | |
81 | + | |
82 | + print total | |
83 | + | |
84 | + | |
85 | + | |
86 | + |