mirror of
https://github.com/jakobkordez/s5_practice.git
synced 2025-05-15 16:20:31 +00:00
Dodan Python skript za generiranje Moodle vprašanj (#1)
* Dodan Python skript za generiranje Moodle vprašanj * Popravljena vprašanja z risanjem
This commit is contained in:
parent
3fe0f46c75
commit
81f27ef832
3
.gitignore
vendored
3
.gitignore
vendored
@ -45,3 +45,6 @@ app.*.map.json
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
|
||||
# moodle_gen.py output
|
||||
radioamaterstvo.xml
|
71
moodle_gen.py
Normal file
71
moodle_gen.py
Normal file
@ -0,0 +1,71 @@
|
||||
import json
|
||||
import base64
|
||||
|
||||
def gen_vprasanje(ime, vprasanje, odgovori, pravilen , slika = None):
|
||||
k = doloci_kategorijo(ime)
|
||||
c = f"""<question type="category">
|
||||
<category>
|
||||
<text>$course$/top/{k}</text>
|
||||
</category>
|
||||
</question>
|
||||
"""
|
||||
|
||||
if(slika != None and k != "Risanje"):
|
||||
with open(f"assets/images/{slika}", "rb") as image_file:
|
||||
vprasanje += f"<br><img src=\"data:image/png;base64, {str(base64.b64encode(image_file.read()))[2:-1]}\"/>"
|
||||
|
||||
ans = ""
|
||||
if(odgovori != None):
|
||||
for o in range(len(odgovori)):
|
||||
p = 0
|
||||
if(o == pravilen):
|
||||
p = 100
|
||||
ans += f"""<answer fraction="{p}" format="html">
|
||||
<text><![CDATA[{odgovori[o]}]]></text>
|
||||
</answer>
|
||||
"""
|
||||
|
||||
return f"""{c}<question type="multichoice">
|
||||
<name>
|
||||
<text>{ime}</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text><![CDATA[{vprasanje}]]></text>
|
||||
</questiontext>
|
||||
<answernumbering>none</answernumbering>
|
||||
{ans}
|
||||
</question>
|
||||
"""
|
||||
else:
|
||||
return f"""{c}<question type="essay">
|
||||
<name>
|
||||
<text>{ime}</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text><![CDATA[{vprasanje}<br>Za lažje ocenjevanje, v polje vpišite neko besedilo.]]></text>
|
||||
</questiontext>
|
||||
<responseformat>monospaced</responseformat>
|
||||
<responserequired>1</responserequired>
|
||||
<responsefieldlines>2</responsefieldlines>
|
||||
<attachments>0</attachments>
|
||||
</question>"""
|
||||
|
||||
def doloci_kategorijo(stevilka):
|
||||
global cat
|
||||
for c in cat:
|
||||
for q in c["questions"]:
|
||||
if q[0] <= stevilka and stevilka <= q[1]:
|
||||
return c["title"]
|
||||
|
||||
f = open("assets/questions.json")
|
||||
b = json.load(f)
|
||||
|
||||
q = b["questions"]
|
||||
cat = b["categories"]
|
||||
|
||||
f = open("radioamaterstvo.xml", "w")
|
||||
f.write("""<?xml version="1.0" encoding="UTF-8"?><quiz>""")
|
||||
for qu in q:
|
||||
f.write(gen_vprasanje(qu["id"], qu["question"], qu["answers"], qu["correct"], qu["image"]))
|
||||
f.write("""</quiz>""")
|
||||
f.close()
|
Loading…
x
Reference in New Issue
Block a user