diff --git a/tools/cumdist.py b/tools/cumdist.py new file mode 100644 index 000000000..e7dc3a836 --- /dev/null +++ b/tools/cumdist.py @@ -0,0 +1,63 @@ +import csv +import sys +import numpy as np +import matplotlib.pyplot as plt +import re + +# check if called correctly +if len(sys.argv) < 2: + sys.exit('Usage: %s FILE1 FILE2' % sys.argv[0]) + +plt.figure(figsize=(8,4)) + +for fn in sys.argv[1:]: + +# m = re.match('[a-zA-Z-]+[-_](\d+)[-_](\d+).', fn) +# rate = m.group(1) +# values = m.group(2) +# print 'Processing file %s (rate=%s, values=%s)' % (fn, rate, values) + + # read data from file + data = [ ] + with open(fn) as f: + reader = csv.reader(f, delimiter='\t') + + for row in reader: + offset = float(row[0]) + +# if fn != 'nrel-test1_offset.log': +# offset = offset * 0.001 + + if offset > 100: + continue + + data.append(offset) + + # evaluate the histogram + values, base = np.histogram(data, bins='fd') + + # evaluate the cumulative + cumulative = np.cumsum(values) + cumscaled = [ float(x) / len(data) for x in cumulative ] + + # plot the cumulative function + plt.plot(base[:-1], cumscaled, label=fn, linewidth=1) + + # plot the distribution + #valscaled = [ float(x) / len(data) for x in values ] + #plt.plot(base[:-1], valscaled, label=fn, linewidth=1) + +plt.xlabel('RTT (s)') +plt.ylabel('Cum. Probability') +plt.grid(color='0.75') + +#plt.yscale('log') + +#plt.ylim([0, 1.03]) +#plt.xlim([0.025, 0.05]) + +lgd = plt.legend(title='Rate (p/s)', loc='center left', bbox_to_anchor=(1, 0.5)) + +plt.show() + +#plt.savefig('cumdist.png', dpi=600, bbox_extra_artists=(lgd,), bbox_inches='tight') diff --git a/tools/extract_rtt.py b/tools/extract_rtt.py new file mode 100644 index 000000000..aaf51b337 --- /dev/null +++ b/tools/extract_rtt.py @@ -0,0 +1,22 @@ +import csv +import sys +import re + +# check if called correctly +if len(sys.argv) != 2: + sys.exit('Usage: %s FILE' % sys.argv[0]) + +prog = re.compile('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?') + +with open(sys.argv[1]) as f: + reader = csv.reader(f, delimiter='\t') + + for row in reader: + m = prog.match(row[0]) + + if m == None or m.group(3) == None: + continue + + offset = float(m.group(3)) + + print(offset) diff --git a/tools/file-filter.py b/tools/file-filter.py new file mode 100755 index 000000000..de9e145d6 --- /dev/null +++ b/tools/file-filter.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import sys + +import villas +from villas import * + +def main(): + if len(sys.argv) != 3: + print "Usage: %s from to" % (sys.argv[0]) + sys.exit(-1) + + start = villas.Timestamp.parse(sys.argv[1]) + end = villas.Timestamp.parse(sys.argv[2]) + + for line in sys.stdin: + msg = villas.Message.parse(line) + + if start <= msg.ts <= end: + print msg + +if __name__ == "__main__": + main() diff --git a/tools/file-merge.py b/tools/file-merge.py new file mode 100755 index 000000000..3b67b12b0 --- /dev/null +++ b/tools/file-merge.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import sys + +import villas +from villas import * + +def main(): + files = sys.argv[1:] + + all = [ ] + last = { } + + for file in files: + handle = sys.stdin if file == '-' else open(file, "r") + + msgs = [ ] + for line in handle.xreadlines(): + msgs.append(villas.Message.parse(line, file)) + + all += msgs + last[file] = villas.Message(villas.Timestamp(), [0] * len(msgs[0].values), file) + + all.sort() + for msg in all: + last[msg.source] = msg + + values = [ ] + for file in files: + values += last[file].values + + print villas.Message(msg.ts, values, "") + +if __name__ == "__main__": + main() diff --git a/tools/plots/plot_dp.py b/tools/plots/plot_dp.py new file mode 100644 index 000000000..5b75cb2af --- /dev/null +++ b/tools/plots/plot_dp.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import sys +import villas.dataprocessing.readtools as rt +import villas.dataprocessing.plottools as pt +import matplotlib.pyplot as plt + +if len(sys.argv) != 2: + sys.exit(-1) + +filename = sys.argv[1] + +timeseries = rt.read_timeseries_villas(filename) + +pt.plot_timeseries(1, timeseries) + +plt.show()