]> git.somenet.org - pub/jan/parprog.git/blob - scan/parseDat.py
parser for scan
[pub/jan/parprog.git] / scan / parseDat.py
1 #!/usr/bin/env python2
2
3 import os, subprocess
4
5 def listtofile(listing, file):
6         fd = open(file, 'r')
7         for i in listing:
8                 fd.write(i+"\n")
9         fd.close()
10
11 def makeGraphs(graphs, graphtitle = "Title", xlabel = "Numbers calculated", ylabel = "Time needed for calculation"):
12         gendir = "stats/generated/"
13         subprocess.call(["mkdir", "-p", gendir])
14         p = subprocess.Popen(['gnuplot'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
15         # now do the plots
16         for graphfile in graphs:
17                 # set output 'filename'
18                 p.stdin.write("set terminal png font arial 8 #size 600,300\n")
19                 p.stdin.write("set grid\n")
20                 p.stdin.write("set datafile separator ';'\n")
21                 p.stdin.write("set title 'Timing of each "+graphtitle+"'\n")
22                 p.stdin.write("set xlabel '"+xlabel+"'\n")
23                 p.stdin.write("set ylabel '"+ylabel+"'\n")
24                 p.stdin.write("set output '"+gendir+graphfile+"'\n")
25                 # plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
26                 plots = []
27                 for title, file, cols in graphs[graphfile]:
28                         plots.append("'"+gendir+file+"' using "+str(cols)+" title '"+str(title)+"' with lines")
29                 plotcommand = ", ".join(plots)
30                 #print gendir+graphfile
31                 p.stdin.write("plot "+plotcommand+"\n")
32         p.communicate()[0]
33         p.stdin.close()
34
35 statsdir = 'stats/raw/'
36 runs = os.listdir(statsdir)
37 #print runs
38
39 bigrunlist = []
40 for i in runs:
41         runfiles = os.listdir(statsdir+i)
42 #       print runfiles
43         for file in runfiles:
44 #               print "File: %s%s/%s" % (statsdir, i, file)
45                 splitfilename = file.split('_')
46                 dict = {}
47                 dict['no'] = int(splitfilename[0].lstrip('no'))
48                 dict['nnp'] = int(splitfilename[1].lstrip('nnp'))
49                 dict['n'] = int(splitfilename[2].lstrip('n'))
50                 fd = open(statsdir+i+'/'+file, "r")
51                 fd_text = fd.read()
52                 fd.close()
53                 fd_lines = fd_text.split("\n")
54                 for line in fd_lines:
55                         if line == "":
56                                 continue
57                         elements = line.split(" ")
58                         if elements[1] != "timings:":
59                                 continue
60                         for elem in elements:
61                                 (key, value) = elem.split(":", 1)
62                                 if key == 'prep':
63                                         dict['prep'] = float(value)
64                                 elif key == 'algo':
65                                         dict['algo'] = float(value)
66                                 elif key == 'postp':
67                                         dict['postp'] = float(value)
68                                 elif key == 'end':
69                                         dict['end'] = float(value)
70                         bigrunlist.append(dict)
71 nos = {}
72 nnps = {}
73 ns = {}
74 foolist = {}
75 for i in bigrunlist:
76         if not (i['no'], i['nnp'], i['n']) in foolist:
77                 foolist[(i['no'], i['nnp'], i['n'])] = [i['end']]
78         else:
79                 foolist[(i['no'], i['nnp'], i['n'])].append(i['end'])
80         if not i['no'] in nos:
81                 nos[i['no']] = {}
82         if not i['nnp'] in nnps:
83                 nnps[i['nnp']] = {}
84         if not i['n'] in ns:
85                 ns[i['n']] = {}
86 #print "NOs: %s" % nos
87 #print "NNPs: %s" % nnps
88 #print "Ns: %s" % ns
89 uniquelist = []
90 for key in foolist:
91         minval = min(foolist[key])
92         uniquelist.append((key[0], key[1], key[2], minval))
93 uniquelist.sort()
94 alg_dict = {}
95 sched_dict = {}
96 for i in uniquelist:
97         if i[0] not in alg_dict:
98                 alg_dict[i[0]] = {}
99         if i[1] not in alg_dict[i[0]]:
100                 alg_dict[i[0]][i[1]] = []
101         alg_dict[i[0]][i[1]].append(str(i[2])+";"+str(i[3]))
102         if i[1] not in sched_dict:
103                 sched_dict[i[1]] = {}
104         if i[0] not in sched_dict[i[1]]:
105                 sched_dict[i[1]][i[0]] = []
106         sched_dict[i[1]][i[0]].append(str(i[2])+";"+str(i[3]))
107         #print "od["+i[0]+"]["+i[1]+"] = "+str(i[2])+":"+str(i[3])
108
109 graphs_alg = {}
110 graphs_sched = {}
111 gendir = "stats/generated/"
112 subprocess.call(["mkdir", "-p", gendir])
113 for alg in alg_dict:
114         pngfile = 'no.'+str(alg)+'.png'
115         graphs_alg[pngfile] = []
116         for sched in alg_dict[alg]:
117                 datfile = 'data.no'+str(alg)+'.nnp'+str(sched)+'.dat'
118                 fh = open(gendir+datfile, 'a+')
119                 graphs_alg[pngfile].append((sched, datfile, '1:2'))
120                 for dot in alg_dict[alg][sched]:
121                         fh.write(dot+"\n")
122                 fh.close()
123 for sched in sched_dict:
124         pngfile = 'nnp.'+str(sched)+'.png'
125         graphs_sched[pngfile] = []
126         for alg in sched_dict[sched]:
127                 datfile = 'data.no'+str(alg)+'.nnp'+str(sched)+'.dat'
128                 graphs_sched[pngfile].append((alg, datfile, '1:2'))
129
130 #graphs['test1.png'] = [('linetitle1', 'prefix.hillis.dat', '1:2')]
131
132 makeGraphs(graphs_alg, "no")
133 makeGraphs(graphs_sched, "nnp")