in heats.py [0:0]
def heatmap_plot_ascii(pixels, time_range, addr_range, resols, colorset):
highest_heat = None
lowest_heat = None
for snapshot in pixels:
for pixel in snapshot:
if highest_heat == None or highest_heat < pixel.heat:
highest_heat = pixel.heat
if lowest_heat == None or lowest_heat > pixel.heat:
lowest_heat = pixel.heat
if highest_heat == None and lowest_heat == None:
return
heat_unit = float(highest_heat + 1 - lowest_heat) / 9
colorsets = {
'gray':[
[232] * 10,
[237, 239, 241, 243, 245, 247, 249, 251, 253, 255]],
'flame':[
[232, 1, 1, 2, 3, 3, 20, 21,26, 27, 27],
[239, 235, 237, 239, 243, 245, 247, 249, 251, 255]],
'emotion':[
[232, 234, 20, 21, 26, 2, 3, 1, 1, 1],
[239, 235, 237, 239, 243, 245, 247, 249, 251, 255]],
}
colors = colorsets[colorset]
for snapshot in pixels:
chars = []
for pixel in snapshot:
heat = int(float(pixel.heat - lowest_heat) / heat_unit)
heat = min(heat, len(colors[0]) - 1)
bg = colors[0][heat]
fg = colors[1][heat]
chars.append(u'\u001b[48;5;%dm\u001b[38;5;%dm%d' %
(bg, fg, heat))
print(''.join(chars) + u'\u001b[0m')
color_samples = [u'\u001b[48;5;%dm\u001b[38;5;%dm %d ' %
(colors[0][i], colors[1][i], i) for i in range(10)]
print('# access_frequency: %s' % ''.join(color_samples) + u'\u001b[0m')
print('# x-axis: space (%d-%d: %s)' % (addr_range[0], addr_range[1],
_fmt_nr.format_sz(addr_range[1] - addr_range[0], False)))
print('# y-axis: time (%d-%d: %s)' % (time_range[0], time_range[1],
_fmt_nr.format_time(time_range[1] - time_range[0], False)))
print('# resolution: %dx%d (%s and %s for each character)' % (
len(pixels[1]), len(pixels),
_fmt_nr.format_sz(
float(addr_range[1] - addr_range[0]) / len(pixels[1]), False),
_fmt_nr.format_time(
float(time_range[1] - time_range[0]) / len(pixels), False)))