** cd /usr/lib/python2.5/site-packages
** ln -sf wx-2.8-gtk2-unicode/wx .
* python-scipy
+
+== START VIEWER ==
+
+./run_viwer
+
+== START LOGGING TEST(TEMPORARY) ==
+
+python test.py
+++ /dev/null
-#!/usr/bin/env python
-
-"""
-Example to draw a cursor and report the data coords in wx
-"""
-
-import matplotlib
-matplotlib.use('WXAgg')
-
-from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
-from matplotlib.backends.backend_wx import NavigationToolbar2Wx
-from matplotlib.figure import Figure
-from numpy import arange, sin, pi
-
-import wx
-
-class CanvasFrame(wx.Frame):
-
- def __init__(self, ):
- wx.Frame.__init__(self,None,-1,
- 'CanvasFrame',size=(550,350))
-
- self.SetBackgroundColour(wx.NamedColor("WHITE"))
-
- self.figure = Figure()
- self.axes = self.figure.add_subplot(111)
- t = arange(0.0,3.0,0.01)
- s = sin(2*pi*t)
-
- self.axes.plot(t,s)
- self.axes.set_xlabel('t')
- self.axes.set_ylabel('sin(t)')
- self.figure_canvas = FigureCanvas(self, -1, self.figure)
-
- # Note that event is a MplEvent
- self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar)
- self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)
-
- self.sizer = wx.BoxSizer(wx.VERTICAL)
- self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
- self.SetSizer(self.sizer)
- self.Fit()
-
- self.statusBar = wx.StatusBar(self, -1)
- self.statusBar.SetFieldsCount(1)
- self.SetStatusBar(self.statusBar)
-
- self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
- self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
- self.toolbar.Show()
-
- def ChangeCursor(self, event):
- self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
-
- def UpdateStatusBar(self, event):
- if event.inaxes:
- x, y = event.xdata, event.ydata
- self.statusBar.SetStatusText(( "x= " + str(x) +
- " y=" +str(y) ),
- 0)
-
-class App(wx.App):
-
- def OnInit(self):
- 'Create the main window and insert the custom frame'
- frame = CanvasFrame()
- self.SetTopWindow(frame)
- frame.Show(True)
- return True
-
-if __name__=='__main__':
- app = App(0)
- app.MainLoop()
self.options = options
def run(self):
- cs = ClientSession(self.dbname, self.cs_id)
- x = []; y1 = []; y2 = []
- restrictions = []
+ self.plot_graph()
+
+ def plot_stat_graph(self):
+ pass
+
+ def plot_graph(self):
+ cs = ClientSession(self.dbname, self.cs_id)
+ x = []; y = {'ds':[], 'us':[], 'acc_us':[], 'acc_ds':[]}
+ restrictions = [];
+ prev_us = 0; prev_ds = 0;
date2 = julianToDatetime(cs.start_time)
td = timedelta(days=date2.day, \
seconds=date2.second, \
hours=date2.hour, \
microseconds=date2.microsecond)
- if self.options[2]:
- date_start = self.time_from_date(date2, self.options[2])
+ if self.options[3]:
+ date_start = self.time_from_date(date2, self.options[3])
restrictions.append(('timestamp', float(datetimeToJulian(date_start)), 'gte'))
- if self.options[3]:
- date_stop = self.time_from_date(date2, self.options[3])
+ if self.options[4]:
+ date_stop = self.time_from_date(date2, self.options[4])
restrictions.append(('timestamp', float(datetimeToJulian(date_stop)), 'lte'))
stmc = StatusMessageCollection(self.dbname, self.cs_id, restrictions)
- stmit = stmc.getIter()
- while True:
- try:
- stm = stmit.next()
- except StopIteration:
- break
+ stmit = stmc.getIter()
+ while True:
+ try:
+ stm = next(stmit)
+ except StopIteration:
+ break
date1 = julianToDatetime(stm.timestamp)
difftime = date1 - td
- x.append(date2num(difftime))
- if self.options[0]:
- y1.append(stm.download_speed)
- if self.options[1]:
- y2.append(stm.upload_speed)
- self.plot_figure(self.cs_id, self.axes_id, x, y1, y2)
+ x.append(date2num(difftime))
+ if self.options[1]:
+ y['ds'].append(stm.download_speed)
+ if self.options[0]:
+ y['acc_ds'].append(stm.download_speed - prev_ds);
+ prev_ds = stm.download_speed;
+ if self.options[2]:
+ y['us'].append(stm.upload_speed)
+ if self.options[0]:
+ y['acc_us'].append(stm.upload_speed - prev_us);
+ prev_us = stm.upload_speed;
+ self.plot_figure(self.cs_id, self.axes_id, x, y)
def time_from_date(self, date, tstr):
time = strptime(tstr, "%H:%M:%S")
time_stop = Str()
download_speed = Bool()
upload_speed = Bool()
+ acceleration = Bool()
plot = Button()
Item('40'),
Item('time_stop', label='Stop')),
HGroup('download_speed',Item('30'), 'upload_speed'),
+ Item('acceleration'),
show_border=True, label='Plotting Options'),
Item('10'),
Item('plot', show_label=False),
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\''),
+ 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')),
+ Group(
Item('speeds', show_label=False, style='simple'),
- Item('views', show_label=False, style='simple'),
+ Item('views', show_label=False, style='simple')),
+ Item('acceleration'),
show_border=True, label='Plotting Options'),
Item('10'),
Item('plot2', show_label=False, height=100),
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]
+ options = [self.acceleration, self.download_speed, self.upload_speed, self.time_start, self.time_stop]
PlotterThread(dbfile, self.cs_id, 0, self.plot_figure, options).start()
def _views_changed(self, new):
dbfile = dbpath + self.dbname + dbextension
print self.speeds
if self.speeds=='Download Speed':
- options = [True, False, self.time_start, self.time_stop]
+ options = [self.acceleration, True, False, self.time_start, self.time_stop]
else:
- options = [False, True, self.time_start, self.time_stop]
+ options = [self.acceleration, False, True, self.time_start, self.time_stop]
if self.views == 'Split':
self.figure.clf();
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):
+ def plot_figure(self, cs_id, axes_id, x, y):
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:
- axes.plot_date(x, y2, '-', label='upload speed: Client '+cs_id)
+ for key in y.keys():
+ if y[key]:
+ axes.plot_date(x, y[key],'-', label=key+' Client '+cs_id)
axes.xaxis.set_major_formatter(DateFormatter('%H:%M:%S'))
#self.axes.set_xlabel("time (s)")
axes.legend(shadow=True, fancybox=True)
Item('panel', style="custom", springy=True, width= -90),
show_labels=False,
),
- title='Editor',
+ title='P2P-NEXT Viewer',
resizable=True,
height=1, width=1,
buttons=NoButtons)
+++ /dev/null
-#!/bin/bash
-
-PYTHONPATH=../auto/db/ python test.py ../auto/db/client-limitation-experiment.db
+++ /dev/null
-#!/bin/bash
-
-PYTHONPATH=../auto/db/ python test2.py ../auto/db/client-limitation-experiment.db
-import matplotlib.pyplot as plt
import sys
import getopt
-import sqlite3
import julian
-from datetime import datetime
-from datetime import timedelta
-from DatabaseWriter import DatabaseWriter
-
+import matplotlib.pyplot as plt
+from config import *
+from DbObjects import *
+import numpy as np
def main():
- dbw=DatabaseWriter(sys.argv[1])
- curs = dbw.select_status_messages(2)
- x=[]
- y1=[]
- y2=[]
-
- for row in curs:
- diff = datetime.today() - julian.julianToDatetime(row[1])
- x.append(diff.seconds)
- y1.append(row[4])
- y2.append(row[5])
- weeks, days = divmod(diff.days, 7)
- min, sec = divmod(diff.seconds, 60)
- hours, min = divmod(min, 60)
- #print hours, min, sec
- plt.plot(x, y1, 'b', x, y2, 'r')
- plt.grid(linestyle='-')
- plt.show()
- #plt.savefig("test.png", dpi=3000)
-
+ msg_types = {0:[0, "CHOKE"], 1:[0, "UNCHOKE"], 2:[0, "INTERESTED"], 3: [0, "NOT_INTERESTED"], \
+ 4:[0, "HAVE"], 5:[0, "BITFIELD"], 6:[0, "REQUEST"], 7:[0, "PIECE"], 8:[0, "CANCEL"], \
+ 9:[0, "DHT_PORT"]}
+ dbname = 'test.db'
+ vbmc = VerboseMessageCollection(dbname, 4);
+ vbmcit = vbmc.getIter()
+ while True:
+ try:
+ vbm = next(vbmcit)
+ except StopIteration:
+ break
+ msg_types[vbm.message_type][0] = msg_types[vbm.message_type][0] + 1;
+
+ print msg_types
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ plt.subplots_adjust(left=0.13, right=0.90)
+ vals = []
+ ticks = []
+ pos = np.arange(len(msg_types))+.3
+ for list in msg_types.values():
+ vals.append(list[0])
+ ticks.append(list[1])
+ ax.barh(pos, vals, height=0.3, align='center')
+ ax.grid(True)
+ plt.yticks(pos, ticks)
+ #ax.set_yticklabels(ticks);
+ plt.show()
+
+
if __name__ == "__main__":
sys.exit(main())
-
-#plt.plot([1,2,3,4], [1,4,9,16], 'b', [1,2,3,4], [1,2,3,14], 'r')
-#plt.axis([0, 6, 0, 20])
-#plt.grid(linestyle='-')
-#plt.savefig("test.svg", dpi=100)
-#plt.show()
+++ /dev/null
-import matplotlib.pyplot as plt
-import sys
-import getopt
-import julian
-from DbObjects import *
-
-def main():
- dbname = sys.argv[1];
- csc = ClientSessionCollection(dbname, 1);
- #cscit = csc.getIter();
-
- i=1
- for cs in csc.css:
- if i == 3:
- break
-
- #try:
- #cs = next(cscit)
- #except StopIteration:
- #break
- ##print(cs)
- stmc = StatusMessageCollection(dbname, cs.id);
- #stmit = stmc.getIter();
- x_local = []
- y_local = []
- for stm in stmc.stms:
- #while True:
- #try:
- #stm = next(stmit)
- #except StopIteration:
- #break
- #print(stm)
- difftime = julian.julianToDatetime(stm.timestamp) - julian.julianToDatetime(cs.start_time)
- x_local.append(difftime.seconds)
- y_local.append(stm.download_speed)
-
- plt.subplot(2, 1, i)
- plt.plot(x_local, y_local)
- plt.grid(True)
- i = i+1
-
-# plt.subplot(2,1,1)
-# plt.plot([1,2,3], [2,3,4])
-# plt.grid(linestyle='dashed')
-# plt.subplot(2,1,2)
-# plt.plot([4,5,6], [2,7,8])
-# #print xy_global
-# plt.grid(linestyle='dashed')
- plt.show()
-
-if __name__ == "__main__":
- sys.exit(main())
\ No newline at end of file
+++ /dev/null
-"""
-An example of how to use pylab to manage your figure windows, but
-modify the GUI by accessing the underlying gtk widgets
-"""
-import matplotlib
-matplotlib.use('GTKAgg')
-from pylab import get_current_fig_manager, subplot, plot, legend, connect, show
-
-ax = subplot(111)
-plot([1,2,3], 'ro-', label='easy as 1 2 3')
-plot([1,4,9], 'gs--', label='easy as 1 2 3 squared')
-legend()
-
-
-manager = get_current_fig_manager()
-# you can also access the window or vbox attributes this way
-toolbar = manager.toolbar
-
-# now let's add a button to the toolbar
-import gtk
-next = 8; #where to insert this in the mpl toolbar
-button = gtk.Button('Click me')
-button.show()
-
-def clicked(button):
- print 'hi mom'
-button.connect('clicked', clicked)
-
-toolitem = gtk.ToolItem()
-toolitem.show()
-toolitem.set_tooltip(
- toolbar.tooltips,
- 'Click me for fun and profit')
-
-toolitem.add(button)
-toolbar.insert(toolitem, next); next +=1
-
-# now let's add a widget to the vbox
-label = gtk.Label()
-label.set_markup('Drag mouse over axes for position')
-label.show()
-vbox = manager.vbox
-vbox.pack_start(label, False, False)
-vbox.reorder_child(manager.toolbar, -1)
-
-def update(event):
- if event.xdata is None:
- label.set_markup('Drag mouse over axes for position')
- else:
- label.set_markup('<span color="#ef0000">x,y=(%f, %f)</span>'%(event.xdata, event.ydata))
-
-connect('motion_notify_event', update)
-
-show()
\ No newline at end of file