Rev. | e788865417c80884c49f3e4f6dd112ef431dcf89 |
---|---|
Größe | 2,997 Bytes |
Zeit | 2009-09-22 18:13:25 |
Autor | lorenzo |
Log Message | I simply removed some unnecessary comments from the code and set the time
|
#!/usr/bin/env python
# dump unique contacts to stdout
import sys
from sociopatterns import Contact, Sighting
from sociopatterns.loader import Loader
import string
class PowerAnalyzer:
def __init__(self, loader, time_delta=60, tag_id_min=None, tag_id_max=None, filter=None):
self.loader = iter(loader)
#self.ip={}
self.filter = filter
self.time_delta = time_delta
self.tnext = -1
self.tag_id_min = tag_id_min
self.tag_id_max = tag_id_max
self.count_clear()
def count_clear(self):
self.count = {}
self.boot_count = {}
self.ip_dict={}
#self.ip_dict_ext={}
def count_get(self):
frame = {}
frame['time'] = self.tnext
frame['count'] = dict(self.count)
frame['boot_count'] = dict(self.boot_count)
frame["antenna"]=dict(self.ip_dict)
#frame["antenna_ext"]=dict(self.ip_dict_ext)
return frame
def __iter__(self):
for obj in self.loader:
#print obj.ip
if self.tnext < 0:
self.tnext = obj.t + self.time_delta
while obj.t >= self.tnext:
yield self.count_get()
self.count_clear()
self.tnext += self.time_delta
if self.filter and self.filter(obj):
continue
if self.tag_id_min and obj.id < self.tag_id_min:
continue
if self.tag_id_max and obj.id >= self.tag_id_max:
continue
if not obj.id in self.count:
self.count[obj.id] = {0:0, 1:0, 2:0, 3:0}
self.boot_count[obj.id] = set()
self.ip_dict[obj.id] = set()
#self.ip_dict_ext[obj.id] = set()
if obj.protocol == Contact.protocol:
self.count[obj.id][3] += 1
elif obj.protocol == Sighting.protocol:
self.count[obj.id][obj.strength] += 1
self.boot_count[obj.id].add(obj.boot_count)
self.ip_dict[obj.id].add(obj.ip)
#print "self.ip_dict is, ", self.ip_dict
#self.ip_dict_ext[obj.id].add(obj.ip)
#print "the station ip is, ", obj.ip
XXTEA_CRYPTO_KEY = ( 0xd2e3fd73, 0xfa70ca9c, 0xe2575826, 0x0fe09946 )
loader = Loader(sys.argv[1:], decode=1, xxtea_crypto_key=XXTEA_CRYPTO_KEY, load_contacts=1, unique_contacts=0, load_sightings=1, unique_sightings=0)
analyzer = PowerAnalyzer(loader, time_delta=20, tag_id_min=1100, tag_id_max=2047)
for frame in analyzer:
for tag_id in frame['count']:
if len(frame['boot_count'][tag_id]) < 1:
continue
x=frame['antenna'][tag_id]
print frame['time'], tag_id, frame['count'][tag_id][0],\
frame['count'][tag_id][1],\
frame['count'][tag_id][2], frame['count'][tag_id][3],\
list(frame['boot_count'][tag_id])[0], string.join(map(str, x)) + " -1" * (7-len(x))