File: plot-data

package info (click to toggle)
gstreamer1.0 1.28.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,604 kB
  • sloc: ansic: 203,072; python: 1,985; sh: 566; lex: 188; lisp: 154; java: 81; makefile: 59; cpp: 58; perl: 46
file content (81 lines) | stat: -rwxr-xr-x 2,441 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python

from __future__ import division

import pylab
import optparse
import sys

def parse_data(l, state):
    state['data'].append([float(x) for x in filter(None, l.split(' '))])
    return state

def parse_event(l, state):
    components = filter(None, l.split(' '))
    vals = [float(x) for x in components[1:]]
    if not components[0] in state:
        state[components[0]] = [vals]
    else:
        state[components[0]].append(vals)
    return state

def read_line(fd, state):
    l = fd.readline()
    if not l:
        return None
    l = l.strip()
    if l[0].isdigit():
        return parse_data(l, state)
    else:
        return parse_event(l, state)

def read_data(fd):
    state = {'data':[],
             'packet-sent':[],
             'packet-lost':[],
             'packet-received':[],
             'packet-observed':[]}
    newstate = state
    while newstate:
        state = newstate
        newstate = read_line(fd, state)
    return state

def make_xticks(start, end, numticks):
    return range(int(start), int(end), int((start-end)/numticks))

def make_plot(title):
    l = sys.stdin.readline()
    labels = l.strip().split(';')
    state = read_data(sys.stdin)
    data = state['data']
    lost_packets = state['packet-lost']
    obsv_packets = state['packet-observed']
    sent_packets = state['packet-sent']
    recd_packets = state['packet-received']

    domain = [x[0] for x in data]
    for i in range(1,len(labels)):
        pylab.plot(domain, [x[i] for x in data], label=labels[i])
    pylab.plot([x[0] for x in lost_packets], [x[1] for x in lost_packets],
               label='Client sent packet, but dropped', marker='x', linestyle=None, ms=8)
    pylab.plot([x[0] for x in sent_packets], [x[1] for x in sent_packets],
               label='Client sent packet', marker='^', linestyle=None, ms=8)
    pylab.plot([x[0] for x in obsv_packets], [x[1] for x in obsv_packets],
               label='Remote time observation', marker='D', linestyle=None, ms=8)
    pylab.plot([x[0] for x in recd_packets], [x[1] for x in recd_packets],
               label='Client received packet', marker='v', linestyle=None, ms=8)
    pylab.legend()
    pylab.ylabel(r'Clock time (s)')
    pylab.xlabel(r'Real time (s)')
    pylab.title(title)
    pylab.grid(True)
    pylab.show()
    
def main(args):
    parser = optparse.OptionParser()

    title = ' '.join(args[1:])
    make_plot(title)

main(sys.argv)