Create visual representation of viewport sizes from usradm audit log
This commit is contained in:
commit
10e29c3e39
|
@ -0,0 +1,73 @@
|
||||||
|
#!/home/hjp/venv/screen-sizes/bin/python
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import PIL.Image
|
||||||
|
import PIL.ImageDraw
|
||||||
|
import PIL.ImageFont
|
||||||
|
|
||||||
|
sizes = []
|
||||||
|
with open(sys.argv[1]) as fh:
|
||||||
|
for ln in fh:
|
||||||
|
audit_record = json.loads(ln[ln.find("{"):])
|
||||||
|
sizes.append(audit_record["data"]["device_info"]["viewport"])
|
||||||
|
|
||||||
|
widths = sorted(set(s["width"] for s in sizes))
|
||||||
|
heights = sorted(set(s["height"] for s in sizes))
|
||||||
|
width = widths[-1]
|
||||||
|
height = heights[-1]
|
||||||
|
print(width, height)
|
||||||
|
|
||||||
|
dist = [
|
||||||
|
[0] * width
|
||||||
|
for y in range(height)
|
||||||
|
]
|
||||||
|
|
||||||
|
for i, s in enumerate(sizes):
|
||||||
|
w = s["width"]
|
||||||
|
h = s["height"]
|
||||||
|
print(i, w, h)
|
||||||
|
for y in range(h):
|
||||||
|
for x in range(w):
|
||||||
|
dist[y][x] += 1
|
||||||
|
|
||||||
|
dist_w = [0] * width
|
||||||
|
for i, s in enumerate(sizes):
|
||||||
|
w = s["width"]
|
||||||
|
for x in range(w):
|
||||||
|
dist_w[x] += 1
|
||||||
|
|
||||||
|
dist_h = [0] * height
|
||||||
|
for i, s in enumerate(sizes):
|
||||||
|
h = s["height"]
|
||||||
|
for y in range(h):
|
||||||
|
dist_h[y] += 1
|
||||||
|
|
||||||
|
origin_x = origin_y = 150
|
||||||
|
img = PIL.Image.new('L', (width+origin_x, height+origin_y))
|
||||||
|
max_val = len(sizes)
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
img.putpixel((x+origin_x, y+origin_y), int(dist[y][x] * 255 / max_val))
|
||||||
|
for x in range(width):
|
||||||
|
img.putpixel((x+origin_x, -int(dist_w[x] * 100 / max_val) + origin_y), 255)
|
||||||
|
for y in range(height):
|
||||||
|
img.putpixel((-int(dist_h[y] * 100 / max_val) + origin_x, y + origin_y), 255)
|
||||||
|
|
||||||
|
draw = PIL.ImageDraw.Draw(img)
|
||||||
|
font = PIL.ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 16)
|
||||||
|
txt_img = PIL.Image.new('L', (50, 20))
|
||||||
|
txt_draw = PIL.ImageDraw.Draw(txt_img)
|
||||||
|
|
||||||
|
for x in widths:
|
||||||
|
draw.line(((x + origin_x, -100 + origin_y), (x + origin_x, origin_y)), 128)
|
||||||
|
txt_draw.rectangle(((0, 0), (49, 19)), fill=0)
|
||||||
|
txt_draw.text((50, 10), str(x), 255, font, "rm")
|
||||||
|
rot_txt_img = txt_img.rotate(-90, expand=True);
|
||||||
|
img.paste(rot_txt_img, (x-10 + origin_x, -150 + origin_y))
|
||||||
|
|
||||||
|
for y in heights:
|
||||||
|
draw.line(((-100 + origin_x, y + origin_y), (origin_x, y + origin_y)), 128)
|
||||||
|
draw.text((-100 + origin_x, y + origin_y), str(y), 255, font, "rm")
|
||||||
|
|
||||||
|
img.save("output.png")
|
Loading…
Reference in New Issue