
import bsddb
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

def main():
    db = bsddb.hashopen('latency.db', 'r')

    samples = list()
    for k, v in db.iteritems():
        # extract key parts
        parts = k.split('|')
        remote, start, end = parts[0], int(parts[1]), int(parts[2])
        # extract value parts
        parts = v.split('|')
        count, timeout, lost, mrtt, artt = int(parts[0]), int(parts[1]), int(parts[2]), float(parts[3]), float(parts[4])
        # add entry
        samples.append((start, artt))

    s = sorted(samples, cmp=lambda x, y: cmp(x[0], y[0]))
    graphit(s)
    
def graphit(data):

    t, l = list(), list()
    for a,b in data:
        t.append(a)
        l.append(b)
    # the histogram of the data
    plt.bar(t, l, facecolor='green', alpha=0.5)
    plt.xlabel('Time')
    plt.ylabel('latency')
    plt.title('i2p latency graph')
    plt.savefig('latency.png')
               

            
if __name__ == '__main__':
    main()

@@ -540,16 +540,28 @@
 rt, artt
+, mrtt, lost
 ))%0A%0A    
@@ -661,17 +661,30 @@
 %0A    t, 
-l
+mean, mx, lost
  = list(
@@ -685,16 +685,32 @@
  list(),
+ list(), list(),
  list()%0A
@@ -720,16 +720,20 @@
  for a,b
+,c,d
  in data
@@ -762,17 +762,20 @@
         
-l
+mean
 .append(
@@ -785,82 +785,158 @@
     
-# the histogram of the data%0A    plt.bar(t, l, facecolor='green', alpha=0.5
+    mx.append(c)%0A        lost.append(d / 10.0)%0A%0A    plt.figure(1)%0A    plt.subplot(2, 1, 1) %0A    plt.title('i2p reliabilty graph')%0A    plt.plot(t, lost
 )%0A  
@@ -953,9 +953,9 @@
 el('
-T
+t
 ime'
@@ -976,45 +976,137 @@
 el('
-latency')%0A    plt.title('i2p 
+packet drop')%0A    plt.subplot(2, 1, 2) %0A    plt.plot(t, mean)%0A    plt.plot(t, mx)%0A    plt.xlabel('time')%0A    plt.ylabel('
 latency 
 grap
@@ -1101,21 +1101,20 @@
 latency 
-graph
+(ms)
 ')%0A    p

improve latency anaylsis graphs