From 918fb26b562ef80f72755a7103f420f8f07816de Mon Sep 17 00:00:00 2001 From: Jan Maximilian Michal <j.michal@stud.uni-goettingen.de> Date: Sun, 11 Dec 2016 23:39:27 +0000 Subject: [PATCH] Gaps do have points now. Added two more scripts. --- README.md | 4 +- hallgrim/parser.py | 14 ++--- scripts/Eine Methode (I1-ID: 75li4j91gdg0).py | 52 +++++++++++++++---- scripts/Rekursion (I1-ID: vi02mcw0lfh0).py | 35 +++++++++++++ 4 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 scripts/Rekursion (I1-ID: vi02mcw0lfh0).py diff --git a/README.md b/README.md index 2617f6f..f27e52d 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ implemented. ### TODO -* Add a good description / documentation. -* Add more functionality (finalize gap, alignment) +* Add a more description / documentation. +* Add more functionality (numeric gap, multiple answers per gap, alignment) * Make parsers more robust. * Create whole test object with questions for direct import. Create two versions (one for internal use and one for the test.) diff --git a/hallgrim/parser.py b/hallgrim/parser.py index 697e65c..70d7e50 100644 --- a/hallgrim/parser.py +++ b/hallgrim/parser.py @@ -33,31 +33,31 @@ def gap_parser(task): # '\[select\]([\w\W]+?)\[\/select\]' # '\[numeric\]([\w\W]+?)\[\/numeric\]' # We match against one big regex that consists of three smaller ones (see above) - _all = re.compile('(\[numeric\]([\w\W]+?)(\[\/numeric\])|(\[select\])([\w\W]+?)\[\/select\]|\[gap\]([\w\W]+?)(\[\/gap\]))', re.MULTILINE) + _all = re.compile('(\[numeric\((([0-9]*[.])?[0-9]+)P\)\]([\w\W]+?)(\[\/numeric\])|(\[select\])([\w\W]+?)\[\/select\]|\[gap\((([0-9]*[.])?[0-9]+)P\)\]([\w\W]+?)(\[\/gap\]))', re.MULTILINE) for m in re.finditer(_all, task): ('[gap]' in m.groups()) gaps = deque() for m in re.finditer(_all, task): if '[select]' in m.groups(): - match = m.group(5) + match = m.group(7) lines = match.strip().split('\n') regex = re.compile('\[(([0-9]*[.])?[0-9]+| )\]\s?([\w\W]+)', re.MULTILINE) parse = [re.search(regex, line).groups() for line in lines] gaps.append(([(text, float(points) if not points == ' ' else 0) for points, _, text in parse], 999)) if '[/gap]' in m.groups(): - match = m.group(6).strip('\n\t ') - gaps.append((match, 4)) ## ADD POINTS !! + match = m.group(10) + gaps.append((match, m.group(8))) if '[/numeric]' in m.groups(): - match = m.group(2) + match = m.group(4) regex = re.compile('[-+]?\d*\.\d+|\d+') parse = re.findall(regex, match) if len(parse) == 1: - gaps.append(((parse[0], parse[0], parse[0]), 4)) + gaps.append(((parse[0], parse[0], parse[0]), m.group(2))) elif len(parse) == 3: - gaps.append((tuple(parse), 4)) + gaps.append((tuple(parse), m.group(2))) else: raise Exception("Numeric gap takes either exactly one value or (value, min, max).") diff --git a/scripts/Eine Methode (I1-ID: 75li4j91gdg0).py b/scripts/Eine Methode (I1-ID: 75li4j91gdg0).py index 77316dd..1ab1b5c 100644 --- a/scripts/Eine Methode (I1-ID: 75li4j91gdg0).py +++ b/scripts/Eine Methode (I1-ID: 75li4j91gdg0).py @@ -1,17 +1,51 @@ meta = { 'author': 'ILIAS Author', 'title': 'Eine Methode (I1-ID: 75li4j91gdg0)', - 'type': 'multi', + 'type': 'gap', 'points': 5.0, } -task = """ decription """ +gap1 = "[select][0.0]final\n [0.5]static\n [0]void\n [0]private\n [/select]" +gap2 = "[select][0]string\n [0]int\n [0.5]boolean\n [0]class\n [/select]" +gap3 = "[select][1]return\n [0]system.out.println\n [0]=\n [0]set\n [/select]" +gap4 = "[select][0]j % 4\n [0]j : 4\n [0.5]j % 4 == 0\n [0]j : 4 == 0\n [/select]" +gap5 = "[select][0.5]&&\n [0.5]||\n [0.5]&\n [0]^\n [/select]" +gap6 = "[select][0]j : 100 != 0 || j : 400 == 0\n [0]j % 100 != 0 || j % 400 = 0\n [0]j : 100 != 0 || j : 400 = 0\n [1]j % 100 != 0 || j % 400 == 0\n [/select]" -choices = """ -[X] A -[ ] B -[ ] C -[X] D -""" +task = """ + +Ein Jahr ist ein Schaltjahr, wenn es durch 4 aber nicht durch 100 teilbar ist +oder aber, wenn es durch 400 teilbar ist. Ergänzen Sie den folgenden Quelltext +so, dass die Methode genau dann den Wert true liefert, wenn Jahr j ein +Schaltjahr ist. + +```java +class Schaltjahr { + public static void main(String[] args) { + int jahr = Integer.parseInt(args[0]); + System.out.println(schaltjahr(jahr)); + } + public %s %s schaltjahr (int j) { + %s (%s %s %s); + } +} +``` + +""" % (gap1, gap2, gap3, gap4, gap5, gap6) -feedback = """ decription """ + +feedback = """ +Der vollständige Code: + +```java_copy +class Schaltjahr { + public static void main(String[] args) { + int jahr = Integer.parseInt(args[0]); + System.out.println(schaltjahr(jahr)); + } + public static boolean schaltjahr (int j) { + return (j % 4 == 0 && j % 100 != 0 || j % 400 == 0); + } +} +``` +""" diff --git a/scripts/Rekursion (I1-ID: vi02mcw0lfh0).py b/scripts/Rekursion (I1-ID: vi02mcw0lfh0).py new file mode 100644 index 0000000..cd6e030 --- /dev/null +++ b/scripts/Rekursion (I1-ID: vi02mcw0lfh0).py @@ -0,0 +1,35 @@ +meta = { + 'author': 'ILIAS Author', + 'title': 'Rekursion (I1-ID: vi02mcw0lfh0)', + 'type': 'gap', + 'points': 4, +} + +task = """ +Welchen String liefert der Aufruf exB(5)? + +```java_copy +public static String exB(int n) { + if (n <= 0) + return ""; + return exB(n-2) + (n+1) + exB(n-1); +} +``` + +Geben Sie die Ziffern hintereinander an, d.h. ohne Leerzeichen o.ä.: [gap(4P)]243263252432[/gap] +""" + +feedback = """ + +Der Rekursionsbaum stellt die Aufrufe durch Knoten dar, die jeweils mit dem +Aufrufargument markiert sind. Die äußeren Knoten (ganz unten) entsprechen +Basisfällen, sie tragen nicht zum Ergebnisstring bei (denn sie liefern nur das +leere Wort). Die anderen (inneren) Knoten tragen bei, und zwar in unserem Fall +je eine Ziffer. + +glw4u2g0xfg0.png + +Traversiert man den Baum in Inorder-Reihenfolge, so ist die Reihenfolge der +Aufrufargumente genau `1, 3, 2, 1, 5, 2, 1, 4, 1, 3, 2, 1`. Die entsprechenden +Ziffern sind immer um 1 höher, also lautet der Ergebnisstring: 243263252432 +""" -- GitLab