From 2ee3fd0ba00b4a8703fe6923d634bd1757e3419b Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 12 Aug 2021 20:46:32 +0200 Subject: [PATCH] Make more tweaks Best commit message. Ever. --- ddresc_visu/draw.py | 32 +++++++++++++++++++++++--------- test.py | 12 ++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ddresc_visu/draw.py b/ddresc_visu/draw.py index c38922e..d43f4ab 100644 --- a/ddresc_visu/draw.py +++ b/ddresc_visu/draw.py @@ -13,17 +13,28 @@ colors = { BORDERCOLOR = (64,64,64) -W = 1900 -H = 1000 -CELLSIZE = 7 -CELLBORDER = 1 -CELLMARGIN = 1 +W = 1920 +H = 1080 +CELLSIZE = 4 +CELLBORDER = 0 +CELLMARGIN = 2 CELLOFFSET = CELLSIZE + 2*CELLBORDER + CELLMARGIN COLUMNS = W // CELLOFFSET ROWS = H // CELLOFFSET CELLS = COLUMNS * ROWS +def get_symb(hist): + ## Majority: + #symb, _count = max(hist.items(), key=lambda x: x[1]) + #return symb + + # The worst: + order = ['-', '/', '*', '?', '+'] + for ch in order: + if ch in hist: + return ch + class Visualisation: def __init__(self, fn): pygame.init() @@ -40,9 +51,8 @@ class Visualisation: for cid in range(CELLS): start = cid * sqsz end = (cid + 1) * sqsz - hist = self.mapfile.get_hist(start, end).items() - # Majority - symb, _count = max(hist, key=lambda x: x[1]) + hist = self.mapfile.get_hist(start, end) + symb = get_symb(hist) color = colors[symb] line = cid // COLUMNS @@ -51,6 +61,10 @@ class Visualisation: rect = pygame.Rect(col * CELLOFFSET + CELLBORDER, line * CELLOFFSET + CELLBORDER, CELLSIZE+2*CELLBORDER, CELLSIZE+2*CELLBORDER) pygame.draw.rect(self.disp, color, rect) - pygame.draw.rect(self.disp, BORDERCOLOR, rect, width=CELLBORDER) + if CELLBORDER != 0: pygame.draw.rect(self.disp, BORDERCOLOR, rect, width=CELLBORDER) pygame.display.flip() + + def reload(self): + self.mapfile.load() + self.draw() diff --git a/test.py b/test.py index 5064ea2..4093b96 100755 --- a/test.py +++ b/test.py @@ -1,9 +1,13 @@ #!/bin/python3 import ddresc_visu.draw as v +from time import sleep -visu = v.Visualisation('/mnt/TAP9701/2021-08-11_Pm_ddresc_mapfile') +FILE = '/mnt/TAP9701/2021-08-11_Pm_ddresc_mapfile' +visu = v.Visualisation(FILE) -visu.draw() +def redraw(): + visu.reload() -import time -time.sleep(10) +while True: + redraw() + sleep(5)