#!/usr/bin/env python3 import sys, math, re if len(sys.argv)!=3: print("Usage: {0} ".format(sys.argv[0]),file=sys.stderr) sys.exit(1) bffname=sys.argv[1] hmfname=sys.argv[2] #def setgray(brightness): # ramp=[231,230,225,224,219,218,213,212,207,206,201,200,199,198,197,196] # code="\x1B[38;5;{0}m".format(ramp[int(brightness*(len(ramp)-1))]) # brightness=int(brightness*25) # #if brightness==0: code="\x1B[0;30m" # #elif brightness==25: code="\x1B[1;37m" # #else: code="\x1B[38;5;{0}m".format(brightness-1+232) # print(code,end="") #for (c,count) in source: # setgray(math.log(count/maxcount*3+1)/math.log(4)) # print(c,end="") def htmlconvert(ch): if ch=="<": return "<" elif ch==">": return ">" elif ch=="\n": return "
" elif ch==" ": return " " else: return ch def hexcolor(r,g,b): r,g,b=[int(x*255) for x in [r,g,b]] return "#{0:0>2}{1:0>2}{2:0>2}".format(hex(r)[2:],hex(g)[2:],hex(b)[2:]) def colorfor(freq): ramp=[ (0.0, (1.0,1.0,1.0)), (0.3, (0.3,0.5,0.5)), (0.7, (0.2,0.2,1.0)), (0.85, (0.6,0.1,1.0)), (1.0, (1.0,0.0,0.0)) ] for i in range(len(ramp)): if ramp[i][0]>=freq: break; if i==0: return hexcolor(*ramp[i][1]) c1=ramp[i-1][1] c2=ramp[i][1] t=(freq-ramp[i-1][0])/(ramp[i][0]-ramp[i-1][0]) return hexcolor(*[c1[i]*(1-t)+c2[i]*t for i in [0,1,2]]) with open(bffname) as f: source=[c for c in f.read()] maxcount=0 with open(hmfname) as f: for line in f: idx,count=[int(x) for x in line.split(" ")] source[idx]=(htmlconvert(source[idx]),count) maxcount=max(maxcount,count) print(""" Heatmap for execution of """+bffname+"""

"""+bffname+"""

Frequency:
(% of maximum)
""") i=0 for (c,count) in source: if i==0 or source[i-1][1]!=count: print( "" .format(colorfor(count/maxcount),count,int(count/maxcount*100)), end="") print(c,end="") if i==len(source)-1 or source[i+1][1]!=count: print("",end="") i+=1 print(""" """)