cleanup
This commit is contained in:
parent
456c3dd712
commit
4e7ce86193
|
@ -36,31 +36,42 @@ def label():
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# read file
|
||||||
with open(sys.argv[1], 'r') as fp:
|
with open(sys.argv[1], 'r') as fp:
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
|
|
||||||
|
# strip and split lines
|
||||||
lines = data.split('\n')
|
lines = data.split('\n')
|
||||||
lines = [x.strip() for x in lines]
|
lines = [x.strip() for x in lines]
|
||||||
lines = [x.strip(',') for x in lines]
|
lines = [x.strip(',') for x in lines]
|
||||||
lines = filter(None, lines)
|
lines = filter(None, lines)
|
||||||
|
|
||||||
|
# read values and transpose
|
||||||
data = [map(int, line.split(',')) for line in lines]
|
data = [map(int, line.split(',')) for line in lines]
|
||||||
data = np.transpose(data)
|
data = np.transpose(data)
|
||||||
|
|
||||||
print len(data)
|
print '%d series in file' % len(data)
|
||||||
|
|
||||||
|
# trim to SECONDS worth of data
|
||||||
n = len(data[0])
|
n = len(data[0])
|
||||||
m = SECONDS * 60 / 2
|
m = SECONDS * 60 / 2
|
||||||
a = max(0, int(n // 2 - m))
|
a = max(0, int(n // 2 - m))
|
||||||
b = min(n, int(n // 2 + m))
|
b = min(n, int(n // 2 + m))
|
||||||
data = [x[a:b] for x in data]
|
data = [x[a:b] for x in data]
|
||||||
|
|
||||||
data = [x for x in data if not all(q == x[0] for q in x)]
|
# remove addresses with too few values
|
||||||
|
data = [x for x in data if len(set(x)) > 1]
|
||||||
|
|
||||||
print len(data)
|
print '%d series that changed' % len(data)
|
||||||
|
|
||||||
|
# trim so all rows are full
|
||||||
data = data[:int((len(data) // COLUMNS) * COLUMNS)]
|
data = data[:int((len(data) // COLUMNS) * COLUMNS)]
|
||||||
|
|
||||||
print len(data)
|
print '%d series after trimming' % len(data)
|
||||||
|
|
||||||
|
print '%d data points each' % len(data[0])
|
||||||
|
|
||||||
|
# create sparklines in a grid pattern
|
||||||
paths = []
|
paths = []
|
||||||
for i, row in enumerate(data):
|
for i, row in enumerate(data):
|
||||||
r = i // COLUMNS
|
r = i // COLUMNS
|
||||||
|
@ -78,12 +89,9 @@ def main():
|
||||||
path.append((x, y))
|
path.append((x, y))
|
||||||
paths.append(path)
|
paths.append(path)
|
||||||
d = axi.Drawing(paths)
|
d = axi.Drawing(paths)
|
||||||
print 'transforming paths'
|
|
||||||
d = d.scale(8.5 / d.width, (12 - 0.5) / d.height)
|
|
||||||
print 'sorting paths'
|
|
||||||
d = d.sort_paths()
|
|
||||||
print 'rendering paths'
|
|
||||||
|
|
||||||
|
# add title and label and fit to page
|
||||||
|
d = d.scale(8.5 / d.width, (12 - 0.5) / d.height)
|
||||||
d = stack_drawings([d, title()], 0.25)
|
d = stack_drawings([d, title()], 0.25)
|
||||||
d = d.rotate(-90)
|
d = d.rotate(-90)
|
||||||
d = d.center(12, 8.5)
|
d = d.center(12, 8.5)
|
||||||
|
@ -91,12 +99,11 @@ def main():
|
||||||
|
|
||||||
print d.bounds
|
print d.bounds
|
||||||
|
|
||||||
|
# save outputs
|
||||||
d.dump('nes/%d.axi' % NUMBER)
|
d.dump('nes/%d.axi' % NUMBER)
|
||||||
rotated = d.rotate(90).center(8.5, 12)
|
rotated = d.rotate(90).center(8.5, 12)
|
||||||
rotated.render(scale=109 * 1, line_width=0.3/25.4).write_to_png('nes/%d.png' % NUMBER)
|
rotated.render(scale=109 * 1, line_width=0.3/25.4).write_to_png('nes/%d.png' % NUMBER)
|
||||||
rotated.dump_svg('nes/%d.svg' % NUMBER)
|
rotated.dump_svg('nes/%d.svg' % NUMBER)
|
||||||
# print sum(x.t for x in axi.Device().plan_drawing(d)) / 60
|
|
||||||
# axi.draw(d)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue