-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtex2layouts.py
49 lines (36 loc) · 1.54 KB
/
tex2layouts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import ast
import itertools
import re
import typing
from amplification import tb_layout
# Credits: itertools docs
def consume(iterator, n=None):
"""Advance the iterator n-steps ahead. If n is None, consume entirely."""
# Use functions that consume iterators at C speed.
if n is None:
# feed the entire iterator into a zero-length deque
collections.deque(iterator, maxlen=0)
else:
# advance to the empty slice starting at position n
next(itertools.islice(iterator, n, n), None)
# Credits: Inspired by definition of `pairwise` in itertools docs.
def tuplewise(iterable, size):
"""Collect data into fixed-length chunks or blocks"""
copies = itertools.tee(iterable, size)
for shift_times, copy in enumerate(copies):
consume(copy, shift_times)
return zip(*copies)
tex_p = "/Users/erle/Projekte/JZKonferenzbeitrag/Farlamp-repo/tiny-supfail.tex"
with open(tex_p, "r") as f:
lines_ = f.readlines()
def chartspecs(lines: [str]):
for (l1, l2, l3) in tuplewise(lines, 3):
if not l1.startswith("% LC"):
continue
patterns = ast.literal_eval(l1.replace("% LC ", "", 1))
title_line = l2 if l2.startswith("\\") else l3
match = re.match(r"\\LearningCurve[{](.*?)[}]", title_line)
title = match.group(1)
yield {"type": "multiline", "title": title, "patterns": patterns}
cat_spec = {"title": "for LaTeX", "charts": list(chartspecs(lines_)), "collapsed": True}
tb_layout.write(tb_layout.main_layout + [cat_spec], "../short-amp-exp/results/iterate")