1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

python: add some old python scripts

This commit is contained in:
Steffen Vogel 2019-03-09 00:37:23 +01:00
parent e78302ac38
commit dcf7ea8e9d
5 changed files with 160 additions and 0 deletions

63
tools/cumdist.py Normal file
View file

@ -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')

22
tools/extract_rtt.py Normal file
View file

@ -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)

23
tools/file-filter.py Executable file
View file

@ -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()

35
tools/file-merge.py Executable file
View file

@ -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()

17
tools/plots/plot_dp.py Normal file
View file

@ -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()