Parser of berki style problems and generator of latex file
Samo Penic
2018-10-28 ccc0bd47fc87961eb205feb615b1774114d04eb2
Added glyphs and units
2 files modified
54 ■■■■■ changed files
GenerateTests.py 19 ●●●● patch | view | raw | blame | history
tools/Template.py 35 ●●●● patch | view | raw | blame | history
GenerateTests.py
@@ -14,16 +14,25 @@
            cont = fd.read()
        naloge.append((i, cont))
    parser=BerkiParse(naloge[0][1])
    parser = BerkiParse(naloge[0][1])
    parser.parseSections()
    n = ProblemSource(parser=parser)
    t = TemplateEngine("tools/textemplates")
    for i in range(0,5):
        p= Problem(n)
    for i in range(0, 5):
        p = Problem(n)
        pprint.pprint(p.problem)
    print(t.head(exam_title="Naslov izpita", date="27.10.2018", faculty_name="Fakulteta test", sid_prefill="11x0xxxx"))
    print(
        t.head(
            exam_title="Naslov izpita",
            date="27.10.2018",
            faculty_name="Fakulteta test",
            sid_prefill="11x0xxxx",
        )
    )
    print(t.start_paper())
    print(t.put_problem_into_template(p.problem))
    for i in range(0, 5):
        p = Problem(n)
        print(t.put_problem_into_template(p.problem))
    print(t.tail())
tools/Template.py
@@ -37,10 +37,10 @@
                retstr += Template(self.template["subproblem"]).substitute(
                    {
                        "text": sp,
                        "ans1": str(sol["correct"][0]),
                        "ans2": str(sol["wrong"][0]),
                        "ans3": str(sol["wrong"][1]),
                        "ans4": str(sol["wrong"][2]),
                        "ans1": ("${}={}\,\mathrm{{{}}}").format(sol['glyph'],sol["correct"][0], sol['unit']),
                        "ans2": ("${}={}\,\mathrm{{{}}}").format(sol['glyph'],sol["wrong"][0], sol['unit']),
                        "ans3": ("${}={}\,\mathrm{{{}}}").format(sol['glyph'],sol["wrong"][1], sol['unit']),
                        "ans4": ("${}={}\,\mathrm{{{}}}").format(sol['glyph'],sol["wrong"][2], sol['unit']),
                    }
                )
            retstr += Template(self.template["subproblem_end"]).substitute()
@@ -49,7 +49,7 @@
                {
                    "problem_number": 0,
                    "text": problem_dict["introduction"],
                    "ans1": str(problem_dict["solutions"][0]["correct"][0]),
                    "ans1": ("${}={}\,\mathrm{{{}}}").format(problem_dict["solutions"]["glyph"],problem_dict["solutions"][0]["correct"][0], problem_dict["solutions"]["unit"]),
                    "ans2": str(problem_dict["solutions"][0]["wrong"][0]),
                    "ans3": str(problem_dict["solutions"][0]["wrong"][1]),
                    "ans4": str(problem_dict["solutions"][0]["wrong"][2]),
@@ -68,20 +68,21 @@
        sid_prefill="11x0xxxx",
        start_number=0,
    ):
        return Template(self.template["head"]).substitute({
            "faculty_id": faculty_id,
            "exam_id": exam_id,
            "faculty_name": faculty_name,
            "exam_title": exam_title,
            "date": date,
            "last_line": last_line,
            "sid_prefill": sid_prefill,
            "start_number": start_number
        })
        return Template(self.template["head"]).substitute(
            {
                "faculty_id": faculty_id,
                "exam_id": exam_id,
                "faculty_name": faculty_name,
                "exam_title": exam_title,
                "date": date,
                "last_line": last_line,
                "sid_prefill": sid_prefill,
                "start_number": start_number,
            }
        )
    def tail(self):
        return ("""\end{document}""")
        return """\end{document}"""
    def start_paper(self, student_id=None, student_name=None):
        if student_id is not None: