aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-11-16 19:41:58 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-11-16 19:41:58 +0100
commit7134160ada7a3e08d4c463bcc410043125a203c5 (patch)
tree4455c571280bebfb014d992510010986bc30bfc9
parent362a954add901904cf1234b96d84debb9262c556 (diff)
downloadspgen-7134160ada7a3e08d4c463bcc410043125a203c5.tar.gz
spgen-7134160ada7a3e08d4c463bcc410043125a203c5.zip
improve spgen script and add new template
-rwxr-xr-xspgen.py17
-rw-r--r--templates/8,9,9,4.tex43
2 files changed, 55 insertions, 5 deletions
diff --git a/spgen.py b/spgen.py
index 30b5956..42ddfed 100755
--- a/spgen.py
+++ b/spgen.py
@@ -11,14 +11,19 @@ class SPTemplate(Template):
delimiter = '%%'
-def print_sp_template(template: SPTemplate, duration: str, names: list[str]):
- defs = [rf'\csdef{{name{i+1}}}{{{n}}}' for i, n in enumerate(names)]
+def print_sp_template(template: SPTemplate, duration: str, names: list[str],
+ seats: list[int]):
+ """Print the template including our name definitions"""
+ defs = []
+ for name in names:
+ seat = seats.pop()
+ defs.append(rf'\csdef{{name{seat}}}{{{name}}}')
defs.append(rf'\csdef{{duration}}{{{duration}}}')
print(template.substitute({'defs': '\n'.join(defs)}))
def main():
- """Entry point generating a random seating plan from students names"""
+ """Entry point generating a random seating plan from student names"""
parser = argparse.ArgumentParser()
parser.add_argument('template')
@@ -27,10 +32,12 @@ def main():
'--duration',
default=f'KW: {datetime.datetime.now().isocalendar()[1]}')
duration_group.add_argument('--week', type=int)
+ duration_group.add_argument('--seats', type=int)
args = parser.parse_args()
names = [line[:-1] for line in sys.stdin.readlines()]
- random.shuffle(names)
+ seats = list(range(1, (args.seats if args.seats else len(names)) + 1))
+ random.shuffle(seats)
duration = args.duration
if args.week:
@@ -51,7 +58,7 @@ def main():
with open(args.template, 'r', encoding='utf-8') as template_file:
template = SPTemplate(template_file.read())
- print_sp_template(template, duration, names)
+ print_sp_template(template, duration, names, seats)
if __name__ == '__main__':
diff --git a/templates/8,9,9,4.tex b/templates/8,9,9,4.tex
new file mode 100644
index 0000000..15184f4
--- /dev/null
+++ b/templates/8,9,9,4.tex
@@ -0,0 +1,43 @@
+\documentclass{standalone}
+\usepackage{tikz}
+\usetikzlibrary{calc}
+\usepackage{etoolbox}
+
+%%defs
+
+\pgfmathsetmacro\fourthColumn{10}
+\pgfmathsetmacro\thirdColumn{6}
+\pgfmathsetmacro\secondColumn{4}
+\pgfmathsetmacro\firstColumn{0}
+
+\pgfmathsetmacro\leftRows{2}
+\pgfmathsetmacro\rightRows{16}
+
+\pgfmathsetmacro\tableWidth{2}
+\pgfmathsetmacro\tableHeight{1.5}
+
+\begin{document}
+\begin{tikzpicture}[table/.style={
+ draw,
+ minimum height=\tableHeight cm,
+ minimum width=\tableWidth cm}
+]
+ \xdef\i{1}
+ \node[table] at (\fourthColumn, 0) {Pult};
+
+ \foreach \n in {1,...,8}{
+ \node[table] at (\firstColumn, \n*\tableHeight) {\csuse{name\i}};
+ \xdef\i{\inteval{\i+1}}
+ }
+ \foreach \n in {1,...,9}{
+ \node[table] at (\secondColumn, \n*\tableHeight) {\csuse{name\i}};
+ \xdef\i{\inteval{\i+1}}
+ \node[table] at (\thirdColumn, \n*\tableHeight) {\csuse{name\i}};
+ \xdef\i{\inteval{\i+1}}
+ }
+ \foreach \n in {1,...,4}{
+ \node[table] at (\fourthColumn, \n*\tableHeight+2*\tableHeight) {\csuse{name\i}};
+ \xdef\i{\inteval{\i+1}}
+ }
+\end{tikzpicture}
+\end{document}