Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > design question

Reply
Thread Tools

design question

 
 
Andrea Crotti
Guest
Posts: n/a
 
      04-10-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
wasn't nice.
Then I tried many other ways but actually I'm a bit stuck...

Any suggestions from someone that maybe had a similar problem?

--8<---------------cut here---------------start------------->8---
class Timeline(object):
"""
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 = []
else:
self.events = events

def __str__(self):
res = []
for evt_tuple in iter(self):
res.append(str(evt_tuple))

return "\n".join(res)

def __eq__(self, other):
return self.events == other.events

def __iter__(self):
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)
self.events.append(tup)

def add_tuple(self, tup):
self.events.append(tup)

def first_event(self, _evt):
first_evt = Timeline.filt(self.events, evt=_evt)[0]
return pretty_time(first_evt.time)

def sort(self):
Timeline.sort_by(self.events)

@staticmethod
def sort_by(events, par='time'):
# side effecting method
events.sort(key=lambda x: x.__getattribute__(par))

@staticmethod
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)

return res
....

--8<---------------cut here---------------end--------------->8---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class design/ design pattern question Bartholomew Simpson C++ 2 06-12-2007 08:51 PM
Class design/design pattern resources TomTom MCSD 2 10-09-2004 07:38 AM
OO design in servlet design question dave Java 5 07-17-2004 12:58 PM
Xilinx Schematic design vs VHDL code design ZackS VHDL 5 07-09-2004 07:51 AM
Looking for help/resources on Writing a nice detailed design / tech design for vb.net code SpamProof Java 3 12-01-2003 06:06 AM



Advertisments