Initial version

master
LEdoian 3 years ago
commit 4fca06fcdf

@ -0,0 +1,56 @@
from .mapfile import MapFile
import pygame
colors = {
'?' : (192, 192, 192), # Non-tried
'*' : (0 , 0 , 255), # Non-trimmed
'/' : (255, 255, 0) , # Non-scraped
'-' : (255, 0 , 0) , # Bad
'+' : (0 , 128, 0) , # Recovered
None: (0 , 0 , 0) , # Not on disk
}
BORDERCOLOR = (64,64,64)
W = 1900
H = 1000
CELLSIZE = 7
CELLBORDER = 1
CELLMARGIN = 1
CELLOFFSET = CELLSIZE + 2*CELLBORDER + CELLMARGIN
COLUMNS = W // CELLOFFSET
ROWS = H // CELLOFFSET
CELLS = COLUMNS * ROWS
class Visualisation:
def __init__(self, fn):
pygame.init()
self.disp = pygame.display.set_mode((W, H))
self.mapfile = MapFile(fn)
self.mapfile.load()
def draw(self):
self.disp.fill((0,0,0)) # Dark theme :-)
sz = self.mapfile.size
sqsz = sz / CELLS
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])
color = colors[symb]
line = cid // COLUMNS
col = cid % COLUMNS
pos = (line, col)
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)
pygame.display.flip()

@ -0,0 +1,73 @@
def read_mapfile(fn):
comments = []
status = None
blockstrings = []
with open(fn, 'r') as f:
for line in f:
if line.startswith("#"):
comments.append(line)
elif status is None:
status = line
else:
blockstrings.append(line)
# Post-processing
status = status.split()
status[0] = int(status[0], base=0)
status[2] = int(status[2], base=0)
status = tuple(status)
blocks = []
for blockstring in blockstrings:
spl = blockstring.split()
start = int(spl[0], base=0)
length = int(spl[1], base=0)
char = spl[2]
blocks.append((start, length, char))
return (status, blocks, comments)
class MapFile:
def __init__(self, filename):
self.mapfilename = filename
def load(self):
self.status, self.blocks, self.comments = read_mapfile(self.mapfilename)
self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks))
def get_state(self, pos):
# TODO: this is lame
for blk in self.blocks:
if pos >= blk[0] and pos < blk[0] + blk[1]:
return blk[2]
def get_hist(self, start, end):
relevant_blocks = []
for blk in self.blocks:
if start < blk[0] + blk[1] and end >= blk[0]:
relevant_blocks.append(blk)
# Trimming:
trmblks = []
for blk in relevant_blocks:
bg, lt, symb = blk
if bg < start:
lt -= start - bg
bg = start
if bg + lt > end:
lt -= bg+lt - end
trmblks.append((bg, lt, symb))
# Grouping by symbols:
grp = {}
for blk in trmblks:
if blk[2] not in grp:
grp[blk[2]] = 0
grp[blk[2]] += blk[1]
return grp

@ -0,0 +1,9 @@
#!/bin/python3
import ddresc_visu.draw as v
visu = v.Visualisation('/mnt/TAP9701/2021-08-11_Pm_ddresc_mapfile')
visu.draw()
import time
time.sleep(10)
Loading…
Cancel
Save