Commit d867354c authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel

Add scripts to generate plots of results

parent 33d84c44
#!/usr/bin/env python
from __future__ import print_function
import sys, csv, numpy as np
from os.path import basename
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
def readCSV (file):
labels = []
rows = []
with open(file, 'r') as f:
csvReader = csv.reader(f, delimiter=';')
legends = csvReader.next()
for row in csvReader:
labels.append(row[0])
rows .append(row[1:])
rows = np.array(rows)
return legends, labels, rows
def stringsToDates (strs):
from datetime import datetime
dts = [ None ] * len(strs)
for i,s in enumerate(strs):
if s in [ "today", "next" ]:
dts[i] = datetime.now()
continue
if s[-1] in 'ab':
ss = s[:-1]
h = 12 if s[-1] == 'b' else 0
else:
ss = s
h = 0
ymd = [int(x) for x in ss.split('-')]
dts[i] = datetime(ymd[0], ymd[1], ymd[2], hour=h)
return dts
def generatePlot (legends, labels, rows, title, dstfile):
n = len(legends) - 1
rcfigsize = plt.rcParams["figure.figsize"]
nrows = (n+1>>1)
figsize = (rcfigsize[0], nrows * rcfigsize[1])
fig, axes = plt.subplots(nrows = nrows,ncols=1,sharex=True,squeeze=False,figsize=figsize)
dates = stringsToDates (labels)
axes[0,0].set_title (title)
for ax in axes[:,0]:
ax.set_xlabel(legends[0])
plt.setp( ax.xaxis.get_majorticklabels(), rotation=70 )
for k in range(n):
if k % 2 == 0:
ax = axes[ (k>>1),0 ]
color = 'b'
style = 'bD-.'
else:
ax = axes[ (k>>1),0 ].twinx()
color = 'r'
style = 'ro--'
ax.plot(dates, rows[:,k], style)
# Make the y-axis label, ticks and tick labels match the line color.
ax.set_ylabel(legends[k+1], color=color)
ax.tick_params('y', colors=color)
fig.tight_layout()
plt.savefig (dstfile)
print("Saved plot to " + dstfile)
if __name__ == '__main__':
if len(sys.argv) != 2:
raise RuntimeError("Expected 1 argument")
file = sys.argv[1]
legends, labels, rows = readCSV(file)
if len(rows) == 0:
print("No data in file " + file)
sys.exit(0)
generatePlot (legends, labels, rows, file, file + ".svg")
#!/usr/bin/env python
import os, sys
from parse_benchmark import parseDirectories, generateCSV
from generate_benchmark_plot import readCSV, generatePlot
# To generate this list:
# find 20*/* -type d | sed 's/^[^\/]*\///' | sort | uniq
if len(sys.argv) > 1:
benchmarks = sys.argv[1:]
else:
benchmarks=[
"baxter-manipulation-boxes",
"baxter-manipulation-boxes-easy",
"baxter-two-arms-one-box",
"baxter-two-arms-three-boxes",
"baxter-two-arms-two-boxes",
"hrp2-on-the-ground",
"kawada",
"path_validation_manipulation",
"pr2-in-iai-kitchen",
"pr2-ini-iai-kitchen",
"pr2-manipulation-kitchen",
"pr2-manipulation-two-hand",
"ur5_path_projection",
"ur5-spline-optimization",
]
root_dir="."
output_dir="./results"
script_dir="./script"
if not os.path.isdir(output_dir): os.mkdir(output_dir)
for bench in benchmarks:
csv = os.path.join (output_dir, bench + ".csv")
keys, values = parseDirectories (root_dir, bench)
if len(keys) == 0:
print("No data for bench " + bench)
continue
with open(csv, 'w') as csvfile:
generateCSV (keys, values, csvfile)
legends, labels, rows = readCSV(csv)
if len(rows) == 0:
print("This should not happen: No data in file " + csv)
continue
svg = os.path.join (output_dir, bench + ".svg")
generatePlot (legends, labels, rows, bench, svg)
#!/usr/bin/env python
from __future__ import print_function
import sys
from os.path import isdir, join, isfile
def parseDirectories(directory, bench):
def valid (dir):
base = join(directory,dir)
if not isdir(base): return False
bdir = join(base,bench)
if not isdir(bdir): return False
return isfile(join(bdir,"benchmark"))
from os import listdir
keys = []
values = dict()
for dir in filter (valid, listdir(directory)):
file = join (directory,dir,bench,"benchmark")
if not isfile(file):
print(file + " does not exist", file=sys.stderr)
continue
values[dir] = dict()
with open (file, 'r') as f:
for line in f.readlines():
if line.startswith("Average "):
k, v = line[len("Average "):].split(':',1)
if k not in keys: keys.append(k)
values[dir][k] = v
return keys, values
def generateCSV(keys, values, csvfile, sep = ';', nan = 'nan'):
labels = sorted(values.keys())
print("Dates" + sep + sep.join(keys), file=csvfile)
for d in labels:
line = d
val = values[d]
# print(val)
for k in keys:
if val.has_key(k):
line += sep + str(float(val[k]))
else:
line += sep + nan
print(line, file=csvfile)
if __name__ == '__main__':
if len(sys.argv) != 3:
raise RuntimeError("Expected 1 argument")
directory = sys.argv[1]
bench = sys.argv[2]
keys, values = parseDirectories (directory, bench)
generateCSV (keys, values, sys.stdout)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment