scls19fr / python-lms-tools

Python library to manage quiz format(s) used by differents Learning management system (LMS) especially Moodle (currently only Aiken format is supported)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XML Moodle support

scls19fr opened this issue · comments

XML Moodle support should be considered.

For output yattag may help https://github.com/leforestier/yattag

For input
xmltodict https://github.com/martinblech/xmltodict
or
lxml objectify http://lxml.de/objectify.html
or BeautifulSoup https://www.crummy.com/software/BeautifulSoup/bs4/
could help

Test quiz quality:

import xmltodict
fname = "questions.xml"
n_errors = 0
with open(fname, "r") as fd:
    s = fd.read()
    xml = xmltodict.parse(s)
    question_categories = xml["question_categories"]["question_category"]
    for question_category in question_categories:
        if question_category["questions"] is not None:
            if len(question_category["questions"]) > 0:
                for question in question_category["questions"]["question"]:
                    answers = question["plugin_qtype_multichoice_question"]["answers"]
                    if answers is not None:
                        n_ans = len(answers["answer"])
                        if n_ans != 4:
                            n_errors += 1
                            id = question["@id"]
                            name = question["name"]
                            print("n_ans: %02d %s %s" % (n_ans, id, name))
print("n_errors: %d" % n_errors)
n_ans: 08 466680 bia_2000_amv_05
n_ans: 16 465138 bia_2009_amd_03
n_ans: 16 466077 bia_2010_cda_02
n_ans: 16 466140 bia_2007_cda_05
n_ans: 16 466196 bia_2004_cda_01
n_ans: 16 466236 bia_2002_cda_01
n_ans: 14 466296 bia_1999_cda_01
n_ans: 10 466304 bia_1999_cda_09
n_ans: 07 466343 bia_1997_cda_08
n_ans: 08 466420 bia_2013_amv_05
n_ans: 08 466423 bia_2013_amv_08
n_ans: 08 466464 bia_2011_amv_09
n_ans: 06 466493 bia_2010_amv_18
n_ans: 08 466525 bia_2008_amv_10
n_ans: 06 466573 bia_2006_amv_18
n_ans: 08 466589 bia_2005_amv_14
n_ans: 08 466659 bia_2001_amv_04
n_ans: 08 466675 bia_2001_amv_20
n_ans: 07 466701 bia_1999_amv_06
n_ans: 08 466717 bia_1998_amv_02
n_ans: 08 466806 bia_2014_nrs_11
n_ans: 16 472629 bia_2014o_cda_07
n_errors: 22

voir #16