Revisão | 3b3765ab3ee7c71e62de9f07f9475f6ecbc05c7e (tree) |
---|---|
Hora | 2010-07-14 01:35:39 |
Autor | lorenzo |
Commiter | lorenzo |
I added a code which implements Juliette's filters to the edgelist of the kids
at school in Lyon.
@@ -0,0 +1,148 @@ | ||
1 | +#!/usr/bin/env python | |
2 | +import scipy as s | |
3 | +import pylab as p | |
4 | +import numpy as n | |
5 | +import sys | |
6 | +import string | |
7 | + | |
8 | + | |
9 | + | |
10 | + | |
11 | +t0 = 31260-1254382848 | |
12 | + | |
13 | +#------------------------------------------------------------------------ | |
14 | +def lunch(t): | |
15 | + if (t>1254394530 and t<1254402330) or (t>1254480930 and t<1254488733): | |
16 | + return True | |
17 | + else : return False | |
18 | + | |
19 | + | |
20 | +teachers=set([1637,1733,1653,1668,1746,1709,1824,1753,1745,1852]) # 1733 never seen | |
21 | + | |
22 | +other=set([1611,65525,0,2037,1812,1449,1492,1543,1845,1609]) | |
23 | + | |
24 | +scientists = [1812,1449] | |
25 | +wrongID = [1611,65525,0,2037,1492,1543,1845,1609] | |
26 | +abs_friday = [1430,1735] | |
27 | +abs_thursday = [1715] | |
28 | + | |
29 | +removeID = wrongID+scientists | |
30 | + | |
31 | + | |
32 | +ce1bm=set([1863,1883,1851,1887,1890,1855,1739,1704,1732,1708,1710]) | |
33 | +ce1bf=set([1889,1877,1861,1854,1858,1872,1897,1898,1743,1713,1749,1702,1715,1706,1718]) # 1715 absent jeudi, to remove before 1254411000 | |
34 | +ce1badd=set([1650]) | |
35 | +ce1b=ce1bm.union(ce1bf) | |
36 | +ce1b=ce1b.union(ce1badd) | |
37 | + | |
38 | + | |
39 | +cm2pbs=set([1451,1458,1461,1468,1479,1483,1495,1516]) | |
40 | + | |
41 | + | |
42 | +def filter_id(Graph,time): | |
43 | + for id in Graph.nodes() : | |
44 | + if id in other or id ==1682 : Graph.remove_node(id) | |
45 | + #1682 ne fait que 2 recres et oublie tous les midis | |
46 | + if id in abs_friday and time > 1254411000 : Graph.remove_node(id) | |
47 | + if id in abs_thursday and time <1254411000 : Graph.remove_node(id) | |
48 | + if id in cm2pbs and lunch(time) : Graph.remove_node(id) | |
49 | + if id in [1687,1574,1707] and lunch(time) : Graph.remove_node(id) | |
50 | + #externes qui laissent le badge sur la table? | |
51 | + if id in [1459,1453] and lunch(time) and time > 1254411000 : Graph.remove_node(id) | |
52 | + #added March,10th : we yet remove the tags of ce1b because they seem to have been stocked in a box | |
53 | + if Graph.has_node(id) and metadata[id]=='ce1b' and time < 1254384588 : Graph.remove_node(id) | |
54 | + #added June,29th: we remove strange long lasting contacts in CE1B | |
55 | + if id in [1708,1743,1877,1890] and (time+t0)<61000 and (time+t0)>57000 : Graph.remove_node(id) | |
56 | + if id in [1749,1883] and (time+t0)<146000 and (time+t0)>139000: Graph.remove_node(id) | |
57 | + #added June, 30th: we remove all nodes with degree >5 | |
58 | + if Graph.has_node(id) and Graph.degree(id)>5 : Graph.remove_node(id) | |
59 | + | |
60 | + | |
61 | +def new_filter_id(sliced_interactions): | |
62 | + | |
63 | + sel_to_remove=s.zeros(0).astype("int64") | |
64 | + | |
65 | + | |
66 | + | |
67 | + for i in xrange(len(sliced_interactions)): | |
68 | + id=sliced_interactions[i,1] | |
69 | + time=sliced_interactions[i,0] | |
70 | + if id in other or id ==1682 : | |
71 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
72 | + if id in abs_friday and time > 1254411000: | |
73 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
74 | + if id in abs_thursday and time <1254411000: | |
75 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
76 | + if id in cm2pbs and lunch(time) : | |
77 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
78 | + if id in [1687,1574,1707] and lunch(time): | |
79 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
80 | + if id in [1459,1453] and lunch(time) and time > 1254411000: | |
81 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
82 | + if id in ce1b and time < 1254384588: | |
83 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
84 | + if id in [1708,1743,1877,1890] and (time+t0)<61000 and (time+t0)>57000: | |
85 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
86 | + if id in [1749,1883] and (time+t0)<146000 and (time+t0)>139000: | |
87 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
88 | + #also remove the teachers | |
89 | + if id in teachers: | |
90 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
91 | + | |
92 | + | |
93 | + | |
94 | + | |
95 | + for i in xrange(len(sliced_interactions)): | |
96 | + id=sliced_interactions[i,2] | |
97 | + time=sliced_interactions[i,0] | |
98 | + if id in other or id ==1682 : | |
99 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
100 | + if id in abs_friday and time > 1254411000: | |
101 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
102 | + if id in abs_thursday and time <1254411000: | |
103 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
104 | + if id in cm2pbs and lunch(time) : | |
105 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
106 | + if id in [1687,1574,1707] and lunch(time): | |
107 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
108 | + if id in [1459,1453] and lunch(time) and time > 1254411000: | |
109 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
110 | + if id in ce1b and time < 1254384588: | |
111 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
112 | + if id in [1708,1743,1877,1890] and (time+t0)<61000 and (time+t0)>57000: | |
113 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
114 | + if id in [1749,1883] and (time+t0)<146000 and (time+t0)>139000: | |
115 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
116 | + if id in teachers: | |
117 | + sel_to_remove=s.hstack((sel_to_remove, i)) | |
118 | + | |
119 | + | |
120 | + sel_to_remove=s.unique(sel_to_remove) | |
121 | + | |
122 | + print "sel_to_remove is, ", sel_to_remove | |
123 | + | |
124 | + #Now finally clean everything up | |
125 | + | |
126 | + clean_interactions=s.delete(sliced_interactions, s.s_[sel_to_remove], axis=0) | |
127 | + return (clean_interactions.astype("int64")) | |
128 | + | |
129 | + | |
130 | +f = open(sys.argv[1]) | |
131 | +sliced_interactions = [map(int, string.split(line)) for line in f.readlines()] | |
132 | +f.close() | |
133 | + | |
134 | +sliced_interactions = s.array(sliced_interactions, dtype="int64") | |
135 | + | |
136 | +#tag_ids=s.unique(sliced_interactions[:,1:3]) | |
137 | + | |
138 | +#print "tag_ids is, ", tag_ids | |
139 | + | |
140 | + | |
141 | +filtered_interactions=new_filter_id(sliced_interactions) | |
142 | +print "s.shape(filtered_interactions) is, ", s.shape(filtered_interactions) | |
143 | + | |
144 | + | |
145 | +n.savetxt("filtered_edge_list.dat", filtered_interactions,fmt='%d') | |
146 | + | |
147 | + | |
148 | +print("So far so good") |