Refactor something, edit something...

master
LEdoian 3 years ago
parent 2ee3fd0ba0
commit 70e3602445

@ -13,11 +13,11 @@ colors = {
BORDERCOLOR = (64,64,64)
W = 1920
H = 1080
CELLSIZE = 4
W = 1920 * 2 // 3
H = 1060
CELLSIZE = 8
CELLBORDER = 0
CELLMARGIN = 2
CELLMARGIN = 3
CELLOFFSET = CELLSIZE + 2*CELLBORDER + CELLMARGIN
COLUMNS = W // CELLOFFSET
@ -36,11 +36,11 @@ def get_symb(hist):
return ch
class Visualisation:
def __init__(self, fn):
def __init__(self, fn, **kwargs):
pygame.init()
self.disp = pygame.display.set_mode((W, H))
self.mapfile = MapFile(fn)
self.mapfile = MapFile(fn, **kwargs)
self.mapfile.load()
def draw(self):

@ -29,28 +29,49 @@ def read_mapfile(fn):
class MapFile:
def __init__(self, filename):
def __init__(self, filename, start=None, end=None):
self.mapfilename = filename
self.start = start
self.end = end
def load(self):
self.status, self.blocks, self.comments = read_mapfile(self.mapfilename)
if self.start is not None or self.end is not None:
self.filter_data()
self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks))
def filter_data(self):
assert self.start is not None and self.end is not None
self.blocks = self.filter_blocks(self.blocks, self.start, self.end)
self.blocks = self.trim_blocks(self.blocks, self.start, self.end)
# Move blocks:
self.status = tuple([self.status[0] - self.start, *self.status[1:]])
nblocks = []
for blk in self.blocks:
nblk = tuple([blk[0] - self.start, *blk[1:]])
nblocks.append(nblk)
self.blocks = nblocks
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):
@staticmethod
def filter_blocks(blocks, start, end):
relevant_blocks = []
for blk in self.blocks:
for blk in blocks:
if start < blk[0] + blk[1] and end >= blk[0]:
relevant_blocks.append(blk)
return relevant_blocks
# Trimming:
@staticmethod
def trim_blocks(blocks, start, end):
trmblks = []
for blk in relevant_blocks:
for blk in blocks:
bg, lt, symb = blk
if bg < start:
lt -= start - bg
@ -58,6 +79,12 @@ class MapFile:
if bg + lt > end:
lt -= bg+lt - end
trmblks.append((bg, lt, symb))
return trmblks
def get_hist(self, start, end):
relevant_blocks = self.filter_blocks(self.blocks, start, end)
trmblks = self.trim_blocks(relevant_blocks, start, end)
# Grouping by symbols:
grp = {}

@ -1,9 +1,10 @@
#!/bin/python3
import ddresc_visu.draw as v
from time import sleep
import argparse
FILE = '/mnt/TAP9701/2021-08-11_Pm_ddresc_mapfile'
visu = v.Visualisation(FILE)
visu = v.Visualisation(FILE, start=1000**3, end=30*1000**3)
def redraw():
visu.reload()

Loading…
Cancel
Save