Skip to content
Snippets Groups Projects
Commit 918fb26b authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Gaps do have points now. Added two more scripts.

parent 486f5131
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,8 @@ implemented. ...@@ -19,8 +19,8 @@ implemented.
### TODO ### TODO
* Add a good description / documentation. * Add a more description / documentation.
* Add more functionality (finalize gap, alignment) * Add more functionality (numeric gap, multiple answers per gap, alignment)
* Make parsers more robust. * Make parsers more robust.
* Create whole test object with questions for direct import. Create two * Create whole test object with questions for direct import. Create two
versions (one for internal use and one for the test.) versions (one for internal use and one for the test.)
......
...@@ -33,31 +33,31 @@ def gap_parser(task): ...@@ -33,31 +33,31 @@ def gap_parser(task):
# '\[select\]([\w\W]+?)\[\/select\]' # '\[select\]([\w\W]+?)\[\/select\]'
# '\[numeric\]([\w\W]+?)\[\/numeric\]' # '\[numeric\]([\w\W]+?)\[\/numeric\]'
# We match against one big regex that consists of three smaller ones (see above) # 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): for m in re.finditer(_all, task):
('[gap]' in m.groups()) ('[gap]' in m.groups())
gaps = deque() gaps = deque()
for m in re.finditer(_all, task): for m in re.finditer(_all, task):
if '[select]' in m.groups(): if '[select]' in m.groups():
match = m.group(5) match = m.group(7)
lines = match.strip().split('\n') lines = match.strip().split('\n')
regex = re.compile('\[(([0-9]*[.])?[0-9]+| )\]\s?([\w\W]+)', re.MULTILINE) regex = re.compile('\[(([0-9]*[.])?[0-9]+| )\]\s?([\w\W]+)', re.MULTILINE)
parse = [re.search(regex, line).groups() for line in lines] 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)) gaps.append(([(text, float(points) if not points == ' ' else 0) for points, _, text in parse], 999))
if '[/gap]' in m.groups(): if '[/gap]' in m.groups():
match = m.group(6).strip('\n\t ') match = m.group(10)
gaps.append((match, 4)) ## ADD POINTS !! gaps.append((match, m.group(8)))
if '[/numeric]' in m.groups(): if '[/numeric]' in m.groups():
match = m.group(2) match = m.group(4)
regex = re.compile('[-+]?\d*\.\d+|\d+') regex = re.compile('[-+]?\d*\.\d+|\d+')
parse = re.findall(regex, match) parse = re.findall(regex, match)
if len(parse) == 1: 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: elif len(parse) == 3:
gaps.append((tuple(parse), 4)) gaps.append((tuple(parse), m.group(2)))
else: else:
raise Exception("Numeric gap takes either exactly one value or (value, min, max).") raise Exception("Numeric gap takes either exactly one value or (value, min, max).")
......
meta = { meta = {
'author': 'ILIAS Author', 'author': 'ILIAS Author',
'title': 'Eine Methode (I1-ID: 75li4j91gdg0)', 'title': 'Eine Methode (I1-ID: 75li4j91gdg0)',
'type': 'multi', 'type': 'gap',
'points': 5.0, '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 = """ task = """
[X] A
[ ] B Ein Jahr ist ein Schaltjahr, wenn es durch 4 aber nicht durch 100 teilbar ist
[ ] C oder aber, wenn es durch 400 teilbar ist. Ergänzen Sie den folgenden Quelltext
[X] D 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);
}
}
```
"""
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
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment