All pastes #1036370 Raw Edit

None

public text v1 · immutable
#1036370 ·published 2008-06-02 00:30 UTC
rendered paste body
#!/usr/bin/env python# via http://lost-theory.org/python/dynamicimg.htmlimport Image,ImageDrawimport reimport osfilename = "/media/mmc1/battery.log"imagename = "/media/mmc1/graph.png"log = file(r"%s" % filename)line = len(log.readlines())X = line+60Y = 130 #image width and heightlog.close()def graph(filename):    img = Image.new("RGB", (X,Y), "#FFFFFF")    draw = ImageDraw.Draw(img)    #draw some axes and markers    #for i in range(X/6):                #if i % 5 == 0:            #draw.text((i*10+15, Y-15), `i*10`, fill="#000")    for j in range(1,Y/10-2):        draw.text((0,Y-15-j*10), `j*10`, fill="#000")    draw.line((20,Y-19,X,Y-19), fill="#000")    draw.line((19,20,19,Y-18), fill="#000")    #read in file and graph it    ots4et=0    log = file(r"%s" % filename)    for (i, value) in enumerate(log):        proc = value[22:26]        chas = value[15:17]        min = value[18:20]	data = value[1:13]	if i==1:            draw.text((i+25, Y-120), data, fill="#000")        if re.search("Charging", value):	    if ots4et == 0:		#draw.line((i+20, Y-15, i+20, 20), fill="#DDD")		draw.line((i+20,Y-20,i+20,Y-30), fill="#33CC33")	    else:		hours,minutes = divmod(ots4et, 60)		worktime="%s:%s" % (hours, minutes)		draw.line((i+20,Y-20,i+20,Y-30), fill="#33CC33")		draw.text((i+15, Y-15), worktime, fill="#000")		ots4et = 0	        else:		if re.search("---", value):		    draw.line((i+20, Y-15, i+20, 20), fill="#000")		    print "line"		else:                    chas = int(chas)                    min = int(min)		    ots4et=ots4et+10		    proc = eval(proc)                    if min == 0:                        draw.line((i+20, Y-15, i+20, 20), fill="#DDD")		        draw.line((i+20,Y-20,i+20,Y-10-proc), fill="#fff")		        if chas % 2 == 0:			    #draw.text((i+15, Y-15), `ots4et`, fill="#000")			    print "worked"                                    else:                        draw.line((i+20,Y-20,i+20,Y-10-proc), fill="#55d")	if i==line-1:	    hours,minutes = divmod(ots4et, 60)	    worktime="%s:%s" % (hours, minutes)	    draw.text((i+15, Y-15), worktime, fill="#000")         img.save(imagename)graph(filename)image="/usr/bin/browser --url file://%s" % (imagename)os.system(image)