andrea.crotti.0 at gmail.com
Sun Apr 10 12:40:40 CEST 2011
I've been wondering for weeks now how to do but I still didn't get a
satisfying answer, so I hope someone can give a hint...
I have some logs which I extract from simulation results.
These logs are in the form
timestamp, nodeid, eventname, event_argument
and now I have to analyze the data.
I don't have so many metrics to analyze but for example I might look for
"symmetric events", in the form
0.0, 0: DATA_SENT(1)
0.1, 1: DATA_RECEIVED(0)
(so in short the nodeid and the argument are swapped)
After many changes now the timeline is something as below, where
everything almost all the functions are static methods and return a new
list of events.
But now I don't get anything I like for the metrics.
Every metric only has to filter and return a result, but the problem is
that maybe for some metrics I want the result on all the nodes.
Some only the average, sometimes I want to correlated with the time (or
time slots) and so on.
So it must be very flexible, but at the same time not a pain to write...
I first wrote a class for every metric subclassing a Metric, but it
Then I tried many other ways but actually I'm a bit stuck...
Any suggestions from someone that maybe had a similar problem?
A timeline is generated by the list of events happened during the
simulation and it's the main point to analyze the data.
def __init__(self, events=None):
if events is None:
self.events = 
self.events = events
res = 
for evt_tuple in iter(self):
def __eq__(self, other):
return self.events == other.events
return iter(sorted(self.events, key=lambda x: x.time))
def add(self, timestamp, nodeid, evt):
"Add one line for the given nodeid"
tup = EventTuple(timestamp, nodeid, evt)
def add_tuple(self, tup):
def first_event(self, _evt):
first_evt = Timeline.filt(self.events, evt=_evt)
def sort_by(events, par='time'):
# side effecting method
events.sort(key=lambda x: x.__getattribute__(par))
def filt(events, node=None, evt=None, arg=None):
"Takes a node, an event and a function to further filter the time"
# copy locally the events and filter them
res = events[:]
if node is not None:
res = filter(lambda x: x.node == node, res)
if evt is not None:
res = filter(lambda x: x.evt.name == evt, res)
if arg is not None:
res = filter(lambda x: x.evt.arg == arg, res)
More information about the Python-list