From d2588f889d8e53a996e94c646406a24634c7f2cf Mon Sep 17 00:00:00 2001 From: Marius Sandu-Popa Date: Fri, 20 Nov 2009 21:03:46 +0200 Subject: [PATCH] viewer v1.01: added comparison tab --- viewer/p2p-nexteditor.py | 139 ++++++++++++++++++++++++++++++--------- 1 file changed, 108 insertions(+), 31 deletions(-) diff --git a/viewer/p2p-nexteditor.py b/viewer/p2p-nexteditor.py index f43aedf..f56d791 100644 --- a/viewer/p2p-nexteditor.py +++ b/viewer/p2p-nexteditor.py @@ -17,10 +17,11 @@ import getopt import wx class PlotterThread(Thread): - def __init__ (self, dbname, cs_id, plot_figure, options): + def __init__ (self, dbname, cs_id, axes_id, plot_figure, options): Thread.__init__(self) self.dbname = dbname self.cs_id = cs_id + self.axes_id = axes_id self.plot_figure = plot_figure self.options = options @@ -57,14 +58,13 @@ class PlotterThread(Thread): y1.append(stm.download_speed) if self.options[1]: y2.append(stm.upload_speed) - self.plot_figure(x, y1, y2) + self.plot_figure(self.cs_id, self.axes_id, x, y1, y2) def time_from_date(self, date, tstr): time = strptime(tstr, "%H:%M:%S") td = timedelta(seconds=time.tm_sec, minutes=time.tm_min, hours=time.tm_hour) return (date + td) - class ControlPanel(HasTraits): #swarm widget dbname = String(auto_set=False, enter_set=True) @@ -92,7 +92,12 @@ class ControlPanel(HasTraits): cs_ds_limit = String() cs_us_limit = String() cs_start_time = CStr() - + + cs_id2 = String(auto_set=False, enter_set=True) + cs_ds_limit2 = String() + cs_us_limit2 = String() + cs_start_time2 = CStr() + #options widget time_start = Str() time_stop = Str() @@ -100,6 +105,11 @@ class ControlPanel(HasTraits): upload_speed = Bool() plot = Button() + + views = Enum('Simple', 'Split', 'Adder') + speeds = Enum('Download Speed', 'Upload Speed') + plot2 = Button() + help = String(''' P2P-Next Analyzer version 1.00 @@ -107,8 +117,8 @@ class ControlPanel(HasTraits): def __init__(self, figure): self.figure = figure; - self.axes = self.figure.add_axes((0.04, 0.06, 0.93, 0.91)) - self.axes.grid(linestyle='dashed') + axes = self.figure.add_axes((0.03, 0.06, 0.93, 0.91)) + axes.grid(linestyle='dashed') view = View(Group( Group( @@ -139,18 +149,37 @@ class ControlPanel(HasTraits): Item('40'), Item('time_stop', label='Stop')), HGroup('download_speed',Item('30'), 'upload_speed'), - show_border=True, label='Options'), + show_border=True, label='Plotting Options'), Item('10'), Item('plot', show_label=False), - label="Control", dock='tab', style='simple'), - #Group( - #Group( - #Item('experiment', style='custom', show_label=False), - #label="Input",), - #Group( - #Item('results', style='custom', show_label=False), - #label="Results",), - #label='Experiment', dock="tab"), + label="Client", dock='tab', style='simple'), + Group( + Item('dbname', label='Database File', style='text'), + Item('20'), + Group( + Item('cs_id', label='Id', style='simple'), + Item('10'), + Item('cs_ds_limit', label='Download LMT'), + Item('cs_us_limit', label='Upload LMT'), + Item('cs_start_time', label='Start Time'), + show_border=True, label='Client Session 1', style='readonly'), + Group( + Item('cs_id2', label='Id', style='simple'), + Item('10'), + Item('cs_ds_limit2', label='Download LMT'), + Item('cs_us_limit2', label='Upload LMT'), + Item('cs_start_time2', label='Start Time'), + show_border=True, label='Client Session 2', style='readonly', enabled_when='object.views != \'Adder\''), + Group( + HGroup(Item('time_start', label='Start'), + Item('40'), + Item('time_stop', label='Stop')), + Item('speeds', show_label=False, style='simple'), + Item('views', show_label=False, style='simple'), + show_border=True, label='Plotting Options'), + Item('10'), + Item('plot2', show_label=False, height=100), + label='Comparison', dock="tab"), Item('help', style='readonly', show_label=False, dock="tab"), layout='tabbed') ) @@ -174,24 +203,72 @@ class ControlPanel(HasTraits): self.cs_ds_limit = cs.ds_limit self.cs_us_limit = cs.us_limit self.cs_start_time = julianToDatetime(cs.start_time) + + def _cs_id2_changed(self, new): + cs = ClientSession(dbpath + self.dbname + dbextension, new); + self.cs_ds_limit2 = cs.ds_limit + self.cs_us_limit2 = cs.us_limit + self.cs_start_time2 = julianToDatetime(cs.start_time) def _plot_fired(self): - if len(self.cs_id) and (self.download_speed or self.upload_speed): - self.axes.clear() - self.axes.grid(linestyle='dashed') + if len(self.cs_id) and (self.download_speed or self.upload_speed): + self.figure.clf(); + self.axes = self.figure.add_subplot(1,1,1) + self.axes.grid(linestyle='dashed') + self.figure.subplots_adjust(left=0.03, right=0.97, top=0.98) + #self.axes.clear() + #self.axes.grid(linestyle='dashed') dbfile = dbpath + self.dbname + dbextension options = [self.download_speed, self.upload_speed, self.time_start, self.time_stop] - PlotterThread(dbfile, self.cs_id, self.plot_figure, options).start() - - def plot_figure(self, x, y1, y2): - if y1: - self.axes.plot_date(x, y1, 'b-', label='download speed') + PlotterThread(dbfile, self.cs_id, 0, self.plot_figure, options).start() + + def _views_changed(self, new): + if new == 'Adder': + self.figure.clf(); + axes = self.figure.add_subplot(1,1,1) + axes.grid(linestyle='dashed') + self.figure.subplots_adjust(left=0.03, right=0.97, top=0.98) + + def _plot2_fired(self): + if (len(self.cs_id) or len(self.cs_id2)): + #self.axes.grid(linestyle='dashed') + dbfile = dbpath + self.dbname + dbextension + print self.speeds + if self.speeds=='Download Speed': + options = [True, False, self.time_start, self.time_stop] + else: + options = [False, True, self.time_start, self.time_stop] + + if self.views == 'Split': + self.figure.clf(); + axes = self.figure.add_subplot(2,1,1) + axes.grid(linestyle='dashed') + axes = self.figure.add_subplot(2,1,2) + axes.grid(linestyle='dashed') + self.figure.subplots_adjust(left=0.03, right=0.97, top=0.98) + PlotterThread(dbfile, self.cs_id, 0, self.plot_figure, options).start() + PlotterThread(dbfile, self.cs_id2, 1, self.plot_figure, options).start() + elif self.views == 'Adder': + PlotterThread(dbfile, self.cs_id, 0, self.plot_figure, options).start() + else: + self.figure.clf(); + axes = self.figure.add_subplot(1,1,1) + axes.grid(linestyle='dashed') + self.figure.subplots_adjust(left=0.03, right=0.97, top=0.98) + PlotterThread(dbfile, self.cs_id, 0, self.plot_figure, options).start() + PlotterThread(dbfile, self.cs_id2, 0, self.plot_figure, options).start() + + def plot_figure(self, cs_id, axes_id, x, y1, y2): + axes_list = self.figure.get_axes() + axes = axes_list[axes_id] + if y1: + axes.plot_date(x, y1,'-', label='download speed: Client '+cs_id) if y2: - self.axes.plot_date(x, y2, 'r-', label='upload speed') - self.axes.xaxis.set_major_formatter(DateFormatter('%H:%M:%S')) - self.axes.set_xlabel("time (s)") - self.axes.legend(shadow=True, fancybox=True) - self.figure.autofmt_xdate(rotation=25) + axes.plot_date(x, y2, '-', label='upload speed: Client '+cs_id) + axes.xaxis.set_major_formatter(DateFormatter('%H:%M:%S')) + #self.axes.set_xlabel("time (s)") + axes.legend(shadow=True, fancybox=True) + self.figure.autofmt_xdate(bottom=0.05, rotation=25) wx.CallAfter(self.figure.canvas.draw) class MainWindow(HasTraits): @@ -207,12 +284,12 @@ class MainWindow(HasTraits): view = View(HSplit(Item('figure', editor=MPLFigureEditor(), dock='vertical'), - Item('panel', style="custom", springy=True, width= -100), + Item('panel', style="custom", springy=True, width= -90), show_labels=False, ), title='Editor', resizable=True, - height=0.75, width=0.75, + height=1, width=1, buttons=NoButtons) if __name__ == '__main__': -- 2.20.1