From bb90f7ec80894a2430f9786a2c02bd56c6133ba6 Mon Sep 17 00:00:00 2001
From: Jan Maximilian Michal <j.michal@stud.uni-goettingen.de>
Date: Wed, 2 Nov 2016 17:39:22 +0000
Subject: [PATCH] Choose how many points should be given now possible.

---
 gen.py                  |  2 +-
 hallgrim/parser.py      | 17 +++++++----------
 scripts/multi_proto.py  |  1 +
 scripts/single_proto.py |  1 +
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/gen.py b/gen.py
index ec2f5ea..039570c 100755
--- a/gen.py
+++ b/gen.py
@@ -50,7 +50,7 @@ def main():
         'title': script.meta['title'],
         'maxattempts': '0',
         'shuffle': True,
-        'questions': choice_parser(script.choices),
+        'questions': choice_parser(script.choices, script.meta['points']),
     }
 
     output = os.path.join(
diff --git a/hallgrim/parser.py b/hallgrim/parser.py
index 9ad1dd0..c40d045 100644
--- a/hallgrim/parser.py
+++ b/hallgrim/parser.py
@@ -14,24 +14,18 @@ class LaTeXRenderer(Renderer):
         return '<span class="latex">{}</span>'.format(formula)
 
 class LaTeXInlineLexer(InlineLexer):
+    """ Classes are inspired by the lexer example in the mistune readme """
     def enable_latex(self):
         # add latex rules
         self.rules.latex = re.compile(
             r'\[\['                   # [[
-            r'([^\]]+)'   # Page 2|Page 2
+            r'([^\]]+)'               # formula
             r'\]\](?!\])'             # ]]
         )
-
-        # Add latex parser to default rules
-        # you can insert it some place you like
-        # but place matters, maybe 3 is not good
         self.default_rules.insert(3, 'latex')
 
     def output_latex(self, m):
         formula = m.group(1)
-
-        # you can create an custom render
-        # you can also return the html if you like
         return self.renderer.latex(formula)
 
 def get_custom_markdown():
@@ -43,10 +37,13 @@ def get_custom_markdown():
     return Markdown(renderer, inline=inline)
 
 
-def choice_parser(raw_choices):
+def choice_parser(raw_choices, points):
+    """ Parse the multiple choice answers and form an array that has the
+    following form: (text, isCorrect, points, solution) and store them in an
+    array of arbitrary size """
     lines = raw_choices.strip().split('\n')
     parse = [re.match('\[(X| )\] (.*)', line).groups() for line in lines]
-    final = [(markdown(text), True if mark == 'X' else False, 0.5) for mark, text in parse]
+    final = [(markdown(text), True if mark == 'X' else False, points) for mark, text in parse]
     return final
 
 markdown = get_custom_markdown()
diff --git a/scripts/multi_proto.py b/scripts/multi_proto.py
index 8b0c95f..d952973 100644
--- a/scripts/multi_proto.py
+++ b/scripts/multi_proto.py
@@ -2,6 +2,7 @@ meta = {
     'author': 'Jan Maximilian Michal',
     'title': 'Sortieren nach Punkten (I1-ID: nipe84411eh0)',
     'type': 'multiple choice',
+    'points': 0.5, # per correct choice
 }
 
 task = """ Hier der Anfang der Datei `punkte.csv`, die Komma-getrennte Angaben
diff --git a/scripts/single_proto.py b/scripts/single_proto.py
index 2f7b3e8..74fd790 100644
--- a/scripts/single_proto.py
+++ b/scripts/single_proto.py
@@ -2,6 +2,7 @@ meta = {
     'author': 'Jan Maximilian Michal',
     'title': 'Sortieren nach Punkten (I1-ID: nipe84411eh0)',
     'type': 'single choice',
+    'points': 4, # for correct answer
 }
 
 task = """ Hier der Anfang der Datei `punkte.csv`, die Komma-getrennte Angaben
-- 
GitLab