-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakecodes.py
More file actions
executable file
·75 lines (62 loc) · 1.86 KB
/
makecodes.py
File metadata and controls
executable file
·75 lines (62 loc) · 1.86 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from __future__ import print_function
import sys
import numpy
import hashlib
import time
seed = time.clock()
if len(sys.argv) < 4:
print("""Usage: {} classlist.txt filename.tex filename.tsv
""".format(sys.argv[0]))
sys.exit(1)
cls = open(sys.argv[1], "r")
tex = open(sys.argv[2], "w")
tsv = open(sys.argv[3], "w")
tex.write("""\\pdfoutput=1
\\documentclass[extrafontsizes,36pt,oneside,letterpaper]{memoir}
\\usepackage{microtype}
\\usepackage{tikz}
\\usepackage[margin=1in]{geometry}
\\pagestyle{empty}
\\begin{document}
\\vspace{2in}
\\begin{center}
\\newcommand{\\A}[1]{%
\\begin{tikzpicture}
\\node[draw,circle,inner sep=1pt] {#1};
\\end{tikzpicture}}
\\newcommand{\\E}[1]{%
\\begin{tikzpicture}
\\node[draw,rectangle, inner sep=5pt] {#1};
\\end{tikzpicture}}
""")
tsv.write("Name\tAuthorCode\tRefereeCode\n")
codes = []
names = []
for name in cls:
name = name.strip()
names.append(name)
nameb = bytes(name, 'utf-8')
myhash = numpy.fromstring(hashlib.sha512(nameb).digest(), dtype='uint16')
autcode = str(myhash[0]).zfill(5)
refcode = str(myhash[-1]).zfill(5)[1:]
tex.write("{\\tiny \\today }\\\\\n")
tex.write("{}\\\\\n".format(name))
tex.write("\\vspace{2in}\n")
tex.write("{\\large Author Code:\\hfill")
for c in autcode:
tex.write("\\A{}".format(c))
tex.write("}\\vspace{2in}\n")
tex.write("{\\normalsize Keep this page. You need it to submit your grades!}\n")
tex.write("\\vfill\n")
tex.write("{\\normalsize Referee Code:\\hfill")
for c in refcode:
tex.write("\\E{}".format(c))
tex.write("}\\newpage\n")
tsv.write("{}\t{}\t{}\n".format(name, autcode, refcode))
codes.append(autcode)
codes.append(refcode)
tex.write("\\end{center}\\end{document}")
tex.close()
tsv.close()
cls.close()
assert len(set(codes)) == 2*len(names), "DUPLICATE FOUND! RE-RUN!"