From 3cfc4aa0368728a3cfa9d29b947bef0606c25b72 Mon Sep 17 00:00:00 2001
From: David Kaufmann <astra@ionic.at>
Date: Sun, 29 Jan 2012 20:23:21 +0100
Subject: [PATCH] parsing done

---
 prefix/.gnuplot    |  5 +++
 prefix/parseDat.py | 95 +++++++++++++++++++++++++++++++++++++++++++---
 prefix/prefix.plt  | 19 ----------
 3 files changed, 95 insertions(+), 24 deletions(-)
 create mode 100644 prefix/.gnuplot
 delete mode 100644 prefix/prefix.plt

diff --git a/prefix/.gnuplot b/prefix/.gnuplot
new file mode 100644
index 0000000..77454ed
--- /dev/null
+++ b/prefix/.gnuplot
@@ -0,0 +1,5 @@
+set terminal png font arial 8 #size 600,300
+set grid
+set xlabel 'Numbers calculated'
+set ylabel 'Time needed for calculation'
+set datafile separator ';'
diff --git a/prefix/parseDat.py b/prefix/parseDat.py
index 87af602..d6d0d90 100755
--- a/prefix/parseDat.py
+++ b/prefix/parseDat.py
@@ -1,9 +1,33 @@
 #!/usr/bin/env python2
 
-import os
+import os, subprocess
 
-statsdir = 'stats/raw/'
+def listtofile(listing, file):
+	fd = open(file, 'r')
+	for i in listing:
+		fd.write(i+"\n")
+	fd.close()
+
+def makeGraphs(graphs, graphtitle):
+	gendir = "stats/generated/"
+	subprocess.call(["mkdir", "-p", gendir])
+	p = subprocess.Popen(['gnuplot'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
+	# now do the plots
+	for graphfile in graphs:
+		# set output 'filename'
+		p.stdin.write("set title 'Timing of each "+graphtitle+"'\n")
+		p.stdin.write("set output '"+gendir+graphfile+"'\n")
+		# plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
+		plots = []
+		for title, file, cols in graphs[graphfile]:
+			plots.append("'"+gendir+file+"' using "+cols+" title '"+title+"' with lines")
+		plotcommand = ", ".join(plots)
+		#print gendir+graphfile
+		p.stdin.write("plot "+plotcommand+"\n")
+	p.communicate()[0]
+	p.stdin.close()
 
+statsdir = 'stats/raw/'
 runs = os.listdir(statsdir)
 #print runs
 
@@ -16,7 +40,7 @@ for i in runs:
 		splitfilename = file.replace('hillis_', 'hillis-').split('_')
 		splitfilename[1] = splitfilename[1].replace('hillis-', 'hillis_')
 		dict = {}
-		dict['sched'] = splitfilename[0]
+		dict['scheduler'] = splitfilename[0]
 		dict['algo'] = splitfilename[1]
 		dict['n'] = int(splitfilename[2].lstrip('n'))
 		fd = open(statsdir+i+'/'+file, "r")
@@ -36,10 +60,71 @@ for i in runs:
 				elif key == 'size':
 					size = int(value)
 					if size != dict['n']:
-						print "Failed: %s is not %s" % (size, dict['nvalue'])
+						print "Failed: %s is not %s" % (size, dict['n'])
 				elif key == 'time':
 					time = float(value)
 			dict['time'] = time
 			bigrunlist.append(dict)
+
+algos = {}
+schedulers = {}
+ns = {}
+foolist = {}
 for i in bigrunlist:
-	print i
+	if not (i['algo'], i['scheduler'], i['n']) in foolist:
+		foolist[(i['algo'], i['scheduler'], i['n'])] = [i['time']]
+	else:
+		foolist[(i['algo'], i['scheduler'], i['n'])].append(i['time'])
+	if not i['algo'] in algos:
+		algos[i['algo']] = {}
+	if not i['scheduler'] in schedulers:
+		schedulers[i['scheduler']] = {}
+	if not i['n'] in ns:
+		ns[i['n']] = {}
+#print "Algos: %s" % algos
+#print "Schedulers: %s" % schedulers
+#print "Ns: %s" % ns
+uniquelist = []
+for key in foolist:
+	minval = min(foolist[key])
+	uniquelist.append((key[0], key[1], key[2], minval))
+uniquelist.sort()
+alg_dict = {}
+sched_dict = {}
+for i in uniquelist:
+	if i[0] not in alg_dict:
+		alg_dict[i[0]] = {}
+	if i[1] not in alg_dict[i[0]]:
+		alg_dict[i[0]][i[1]] = []
+	alg_dict[i[0]][i[1]].append(str(i[2])+";"+str(i[3]))
+	if i[1] not in sched_dict:
+		sched_dict[i[1]] = {}
+	if i[0] not in sched_dict[i[1]]:
+		sched_dict[i[1]][i[0]] = []
+	sched_dict[i[1]][i[0]].append(str(i[2])+";"+str(i[3]))
+	#print "od["+i[0]+"]["+i[1]+"] = "+str(i[2])+":"+str(i[3])
+
+graphs_alg = {}
+graphs_sched = {}
+gendir = 'stats/generated'
+for alg in alg_dict:
+	pngfile = 'algorithm.'+alg+'.png'
+	graphs_alg[pngfile] = []
+	for sched in alg_dict[alg]:
+		datfile = 'data.'+alg+'.'+sched+'.dat'
+		fh = open(gendir+'/'+datfile, 'a+')
+		graphs_alg[pngfile].append((sched, datfile, '1:2'))
+		for dot in alg_dict[alg][sched]:
+			fh.write(dot+"\n")
+		fh.close()
+for sched in sched_dict:
+	pngfile = 'scheduler.'+sched+'.png'
+	graphs_sched[pngfile] = []
+	for alg in sched_dict[sched]:
+		datfile = 'data.'+alg+'.'+sched+'.dat'
+		graphs_sched[pngfile].append((alg, datfile, '1:2'))
+
+#graphs['test1.png'] = [('linetitle1', 'prefix.hillis.dat', '1:2')]
+
+makeGraphs(graphs_alg, "algorithm")
+makeGraphs(graphs_sched, "scheduler")
diff --git a/prefix/prefix.plt b/prefix/prefix.plt
deleted file mode 100644
index 8dbe37b..0000000
--- a/prefix/prefix.plt
+++ /dev/null
@@ -1,19 +0,0 @@
-set terminal png font arial 8 size #600,300
-set output 'stats/prefix.png'
-set grid
-set title "Time required for each algorithm"
-set xlabel "Size of array"
-set ylabel "Time needed for calculation"
-#set xrange [ 100000 : 100000000 ]
-#set yrange [ 0.0000 : 0.75 ]
-#set xtics 0,25,200
-#set ytics 0,0.1,0.75
-set datafile separator ";"
-plot 'stats/prefix.datapar.dat' using 1:2 notitle with points, \
-	 'stats/prefix.datapar.dat' using 1:2 title "datapar" with lines, \
-	 'stats/prefix.hillis.dat' using 1:2 notitle with points, \
-	 'stats/prefix.hillis.dat' using 1:2 title "hillis" with lines, \
-	 'stats/prefix.seq.dat' using 1:2 notitle with points, \
-	 'stats/prefix.seq.dat' using 1:2 title "seq" with lines, \
-	 'stats/prefix.recurse.dat' using 1:2 notitle with points, \
-	 'stats/prefix.recurse.dat' using 1:2 title "recurse" with lines
-- 
2.43.0