/[pdpsoft]/nl.nikhef.ndpf.groupviews/tags/REL-1.1.0/runplt.py
ViewVC logotype

Annotation of /nl.nikhef.ndpf.groupviews/tags/REL-1.1.0/runplt.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2385 - (hide annotations) (download) (as text)
Thu Jul 28 12:06:57 2011 UTC (11 years, 2 months ago) by templon
File MIME type: application/x-python
File size: 12684 byte(s)
Tag Release 1.1; version in service week 30, 2011
1 templon 2348 #! /usr/bin/env python
2    
3     NUMGROUPS=8
4    
5     import os
6    
7     pfnam = os.environ['HOME']+'/tmp/run.plt'
8    
9     infh = open(os.environ['HOME']+'/tmp/groups.rdata','r')
10     datablocks = infh.read().split('\n\n')
11    
12     countslist = list() # holds one rundict per timestamp
13     timestringlist = list() # same order as countslist
14    
15     for block in datablocks[:-1]:
16     lines = block.split('\n')
17     timestr = lines[0] ; timestringlist.append(timestr)
18     rundict = dict() # format rundict['vo'] = number_running
19     for l in lines[1:]:
20     vo, num = eval(l, {}, {})
21     rundict[vo] = num
22     countslist.append(rundict)
23    
24     def avgdata(vals, tstamps, step):
25     # step must be odd
26     # lengths of vals and tstamps must be identical, and
27     # also must be integer multiple of step
28    
29     newvals = list()
30     newstamps = list()
31     if len(vals) % step != 0:
32     print "length of input arrays must be multiple of step size"
33     sys.exit(0)
34     optr = 0
35     while optr < len(vals):
36     print optr
37     print step
38     print vals[optr:optr+step]
39    
40     newvals.append(sum(vals[optr:optr+step]))
41     newstamps.append(tstamps[optr + (fact/2)])
42     optr += fact
43     return newvals, newstamps
44    
45     sl1 = countslist[-75:]
46     sl2 = timestringlist[-75:]
47    
48     hrtuple_small = (
49     sl1, sl2,
50     [
51     # 'set terminal x11 size 1000,535\n',
52     'set terminal png size 365,201 font "arial,8"\n',
53     'set key autotitle columnheader\n',
54     'set xdata time\n',
55     'set timefmt "%b-%d-%Y-%H:%M:%S"\n',
56     'set output "/user/templon/public_html/run-hr-small.png"\n',
57     '# time range must be in same format as data file\n',
58     'set grid xtics mxtics ytics mytics front\n',
59     'set yrange [0 : *]\n',
60     'set auto fix\n'
61     'set key outside samplen 1\n',
62     'set format x "%H:%M"\n',
63     'set xtics 3600\n',
64     'set mxtics 6\n',
65     'set mytics 2\n'
66     ],
67     os.environ['HOME']+'/tmp/myd_hr_s'
68     )
69    
70     hrtuple_large = (
71     sl1, sl2,
72     [
73     'set terminal png size 1000,535 font "arial,10"\n',
74     'set output "/user/templon/public_html/run-hr-large.png"\n',
75     'set format x "%H:%M"\n',
76     'set xtics 3600\n',
77     'set mxtics 6\n',
78     'set mytics 4\n'
79     'set key autotitle columnheader\n',
80     'set xdata time\n',
81     'set timefmt "%b-%d-%Y-%H:%M:%S"\n',
82     '# time range must be in same format as data file\n',
83     'set grid xtics mxtics ytics mytics front\n',
84     'set yrange [0 : *]\n',
85     'set auto fix\n'
86     'set key outside samplen 1\n',
87     ],
88     os.environ['HOME']+'/tmp/myd_hr_l'
89     )
90    
91     sl3 = countslist[-720:]
92     sl4 = timestringlist[-720:]
93    
94     daytuple_small = (
95     sl3, sl4,
96     [
97     'set terminal png size 365,201 font "arial,8"\n',
98     'set output "/user/templon/public_html/run-day-small.png"\n',
99     'set format x "%H:%M"\n',
100     'set xtics 21600\n',
101     'set mxtics 3\n'
102     ],
103     os.environ['HOME']+'/tmp/myd_day_s'
104     )
105    
106     daytuple_large = (
107     sl3, sl4,
108     [
109     'set terminal png size 1000,535 font "arial,10"\n',
110     'set output "/user/templon/public_html/run-day-large.png"\n',
111     'set format x "%H:%M"\n',
112     'set xtics 7200\n',
113     'set mxtics 4\n'
114     ],
115     os.environ['HOME']+'/tmp/myd_day_l'
116     )
117    
118     sl5 = countslist[-5760:]
119     sl6 = timestringlist[-5760:]
120    
121     weektuple_small = (
122     sl5, sl6,
123     [
124     'set terminal png size 365,201 font "arial,8"\n',
125     'set output "/user/templon/public_html/run-week-small.png"\n',
126     'set format x "%a"\n',
127     'set xtics 86400\n',
128     'set nomxtics \n'
129     ],
130     os.environ['HOME']+'/tmp/myd_week_s'
131     )
132    
133     # sl7, sl8 = avgdata(sl5, sl6, 5)
134    
135     weektuple_large = (
136     sl5[::5], sl6[::5],
137     [
138     'set terminal png size 1000,535 font "arial,10"\n',
139     'set output "/user/templon/public_html/run-week-large.png"\n',
140     'set format x "%a"\n',
141     'set xtics 86400\n',
142     'set mxtics 3\n'
143     ],
144     os.environ['HOME']+'/tmp/myd_week_l'
145     )
146    
147     sl10 = countslist[-22300:]
148     sl11 = timestringlist[-22300:]
149    
150     # sl12, sl13 = avgdata(sl10, sl11, 100)
151    
152     monthtuple_small = (
153     sl10[::100], sl11[::100],
154     [
155     'set terminal png size 365,201 font "arial,8"\n',
156     'set output "/user/templon/public_html/run-month-small.png"\n',
157     'set format x "%m/%d"\n',
158     'set xtics 604800\n',
159     'set nomxtics \n'
160     ],
161     os.environ['HOME']+'/tmp/myd_month_s'
162     )
163    
164     # sl14, sl15 = avgdata(sl10, sl11, 20)
165    
166     monthtuple_large = (
167     sl10[::20], sl11[::20],
168     [
169     'set terminal png size 1000,535 font "arial,10"\n',
170     'set output "/user/templon/public_html/run-month-large.png"\n',
171     'set format x "%m/%d"\n',
172     'set xtics 604800\n',
173     'set mxtics 7\n'
174     ],
175     os.environ['HOME']+'/tmp/myd_month_l'
176     )
177    
178    
179     # do it again but for queued jobs
180    
181     infh = open(os.environ['HOME']+'/tmp/groups.qdata','r')
182     datablocks = infh.read().split('\n\n')
183    
184     countslist = list() # holds one rundict per timestamp
185     timestringlist = list() # same order as countslist
186    
187     for block in datablocks[:-1]:
188     lines = block.split('\n')
189     timestr = lines[0] ; timestringlist.append(timestr)
190     rundict = dict() # format rundict['vo'] = number_running
191     for l in lines[1:]:
192     vo, num = eval(l, {}, {})
193     rundict[vo] = num
194     countslist.append(rundict)
195    
196     qhrtuple_small = (
197     countslist[-75:],
198     timestringlist[-75:],
199     [
200     # 'set terminal x11 size 1000,535\n',
201     'set terminal png size 365,201 font "arial,8"\n',
202     'set key autotitle columnheader\n',
203     'set xdata time\n',
204     'set timefmt "%b-%d-%Y-%H:%M:%S"\n',
205     'set output "/user/templon/public_html/queued-hr-small.png"\n',
206     '# time range must be in same format as data file\n',
207     'set grid xtics mxtics ytics mytics front\n',
208     'set yrange [0 : *]\n',
209     'set auto fix\n'
210     'set key outside samplen 1\n',
211     'set format x "%H:%M"\n',
212     'set xtics 3600\n',
213     'set mxtics 6\n',
214     'set mytics 3\n'
215     ],
216     os.environ['HOME']+'/tmp/myqd_hr'
217     )
218    
219     qhrtuple_large = (
220     countslist[-75:],
221     timestringlist[-75:],
222     [
223     'set terminal png size 1000,535 font "arial,10"\n',
224     'set output "/user/templon/public_html/queued-hr-large.png"\n',
225     'set format x "%H:%M"\n',
226     'set xtics 3600\n',
227     'set mxtics 6\n',
228     'set mytics 3\n'
229     'set key autotitle columnheader\n',
230     'set xdata time\n',
231     'set timefmt "%b-%d-%Y-%H:%M:%S"\n',
232     '# time range must be in same format as data file\n',
233     'set grid xtics mxtics ytics mytics front\n',
234     # 'set yrange [0 : 2600]\n',
235     'set auto fix\n'
236     'set key outside samplen 1\n',
237     ],
238     os.environ['HOME']+'/tmp/myqd_hr'
239     )
240    
241     qdaytuple_small = (
242     countslist[-720:],
243     timestringlist[-720:],
244     [
245     'set terminal png size 365,201 font "arial,8"\n',
246     'set output "/user/templon/public_html/queued-day-small.png"\n',
247     'set format x "%H:%M"\n',
248     'set xtics 21600\n',
249     'set mxtics 3\n'
250     ],
251     os.environ['HOME']+'/tmp/myqd_day'
252     )
253    
254     qdaytuple_large = (
255     countslist[-720:],
256     timestringlist[-720:],
257     [
258     'set terminal png size 1000,535 font "arial,10"\n',
259     'set output "/user/templon/public_html/queued-day-large.png"\n',
260     'set format x "%H:%M"\n',
261     'set xtics 7200\n',
262     'set mxtics 4\n'
263     ],
264     os.environ['HOME']+'/tmp/myqd_day'
265     )
266    
267    
268     plottuple_list = [ hrtuple_small, hrtuple_large, daytuple_small,
269     daytuple_large, weektuple_small, weektuple_large,
270     monthtuple_small, monthtuple_large,
271     qhrtuple_small, qhrtuple_large,
272     qdaytuple_small, qdaytuple_large
273     ]
274    
275     plotfileh = open(pfnam,'w')
276    
277     def emit_plotfile(pfh, plotslist):
278     # pfh is handle to plot file object
279     # first make the right data structure: rundata['vo']['timestamp'] = number
280     rundata = dict() # format rundata['vo']['timestamp'] = number
281     tsl = plotslist[1]
282     ctl = plotslist[0]
283     for i in range(len(tsl)):
284     for vo in ctl[i].keys():
285     if vo not in rundata.keys():
286     rundata[vo] = dict()
287     rundata[vo][tsl[i]] = ctl[i][vo]
288    
289     sums = dict()
290     for k in rundata.keys():
291     sums[k] = sum(rundata[k].values())
292    
293     vos_by_jobs = sorted(sums, key=sums.get, reverse=False)
294    
295     topvos = vos_by_jobs[-NUMGROUPS:]
296    
297     dfh = open(plotslist[3], 'w')
298     dfh.write('timestamp ')
299     for k in topvos:
300     dfh.write("%8s " % k)
301     dfh.write('\n')
302     for t in tsl:
303     dfh.write(t+ " ")
304     for k in topvos:
305     if t in rundata[k].keys():
306     val = rundata[k][t]
307     else:
308     val = 0
309     dfh.write("%4d " % val)
310     dfh.write('\n')
311     dfh.close()
312    
313     import glob
314     import os
315    
316     gplines = plotslist[2]
317    
318     # gplines.append('set terminal png size 335,201\n')
319    
320     ctr = 1
321     for vo in reversed(topvos):
322     if ctr == 1:
323     pstr = 'plot '
324     datafnam = plotslist[3]
325     pstr += '"' + datafnam + '" using 1:($' + repr(topvos.index(vo)+2)
326     for k2 in range(topvos.index(vo)+1, 1, -1):
327     pstr += '+$' + repr(k2)
328     pstr += ') t "' + vo + '"'
329     if ctr < len(topvos):
330     pstr += ' w boxes fs solid,'
331     ctr += 1
332     else:
333     pstr += ' w boxes fs solid'
334     gplines.append(pstr + '\n')
335    
336     for l in gplines:
337     pfh.write(l)
338    
339     # gplines.append('set terminal png size 1000,535\n')
340     # gplines.append('set output "/user/templon/public_html/wait-hr-large.png"\n')
341     # gplines.append('set format x "%H:%M"\n')
342     # gplines.append('set format y "%.0te+%S"\n')
343     # gplines.append('set xtics 3600\n')
344    
345     # ctr = 1
346     # for vo in volist:
347     # if ctr == 1:
348     # pstr = 'plot '
349     # datafnam = os.environ['HOME']+'/tmp/'+vo+'.wdata'
350     # pstr += '"< tail -75 ' + datafnam + '" using 1:3' + \
351     # ' title "' + vo + '"'
352     # if ctr < len(volist):
353     # pstr += ' with lines lw 3,'
354     # ctr += 1
355     # else:
356     # pstr += ' with lines lw 1'
357     # gplines.append(pstr + '\n')
358    
359     # gplines.append('set terminal png size 335,201\n')
360     # gplines.append('set output "/user/templon/public_html/wait-day-small.png"\n')
361     # gplines.append('set format x "%H:%M"\n')
362     # gplines.append('set format y "%.0te+%S"\n')
363     # gplines.append('set xtics 21600\n')
364     # gplines.append('set mxtics 3\n')
365    
366     # ctr = 1
367     # for vo in volist:
368     # if ctr == 1:
369     # pstr = 'plot '
370     # datafnam = os.environ['HOME']+'/tmp/'+vo+'.wdata'
371     # pstr += '"< tail -720 ' + datafnam + '" using 1:3' + \
372     # ' title "' + vo + '"'
373     # if ctr < len(volist):
374     # pstr += ' with lines lw 3,'
375     # ctr += 1
376     # else:
377     # pstr += ' with lines lw 1'
378     # gplines.append(pstr + '\n')
379    
380     # gplines.append('set terminal png size 1000,535\n')
381     # gplines.append('set output "/user/templon/public_html/wait-day-large.png"\n')
382     # gplines.append('set format x "%H:%M"\n')
383     # gplines.append('set format y "%.0te+%S"\n')
384     # gplines.append('set xtics 7200\n')
385     # gplines.append('set mxtics 4\n')
386    
387     # ctr = 1
388     # for vo in volist:
389     # if ctr == 1:
390     # pstr = 'plot '
391     # datafnam = os.environ['HOME']+'/tmp/'+vo+'.wdata'
392     # pstr += '"< tail -720 ' + datafnam + '" using 1:3' + \
393     # ' title "' + vo + '"'
394     # if ctr < len(volist):
395     # pstr += ' with lines lw 3,'
396     # ctr += 1
397     # else:
398     # pstr += ' with lines lw 1'
399     # gplines.append(pstr + '\n')
400    
401     # gplines.append('set terminal png size 335,201\n')
402     # gplines.append('set output "/user/templon/public_html/wait-week-small.png"\n')
403     # gplines.append('set format x "%a"\n')
404     # gplines.append('set format y "%.0te+%S"\n')
405     # gplines.append('set xtics 86400\n')
406     # gplines.append('set mxtics 3\n')
407    
408     # ctr = 1
409     # for vo in volist:
410     # if ctr == 1:
411     # pstr = 'plot '
412     # datafnam = os.environ['HOME']+'/tmp/'+vo+'.wdata'
413     # pstr += '"< tail -5760 ' + datafnam + '" using 1:3' + \
414     # ' title "' + vo + '"'
415     # if ctr < len(volist):
416     # pstr += ' with lines lw 3,'
417     # ctr += 1
418     # else:
419     # pstr += ' with lines lw 1'
420     # gplines.append(pstr + '\n')
421    
422     # gplines.append('set terminal png size 1000,535\n')
423     # gplines.append('set output "/user/templon/public_html/wait-week-large.png"\n')
424     # gplines.append('set format x "%a %H:%M"\n')
425     # gplines.append('set format y "%.0te+%S"\n')
426     # gplines.append('set xtics 86400\n')
427     # gplines.append('set mxtics 3\n')
428    
429     # ctr = 1
430     # for vo in volist:
431     # if ctr == 1:
432     # pstr = 'plot '
433     # datafnam = os.environ['HOME']+'/tmp/'+vo+'.wdata'
434     # pstr += '"< tail -5760 ' + datafnam + '" using 1:3' + \
435     # ' title "' + vo + '"'
436     # if ctr < len(volist):
437     # pstr += ' with lines lw 3,'
438     # ctr += 1
439     # else:
440     # pstr += ' with lines lw 1'
441    
442     for itm in plottuple_list:
443     emit_plotfile(plotfileh, itm)
444    
445     plotfileh.close()
446     os.system(os.environ['HOME']+'/bin/gnuplot ' + pfnam)

Properties

Name Value
svn:executable *
svn:keywords Id URL

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28