Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle to amc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathieu Loiseau
moodle to amc
Commits
db0f29d0
Commit
db0f29d0
authored
3 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
shortAnswer
parent
63f3e96b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
XML_Moodle.py
+40
-6
40 additions, 6 deletions
XML_Moodle.py
with
40 additions
and
6 deletions
XML_Moodle.py
+
40
−
6
View file @
db0f29d0
...
@@ -22,7 +22,7 @@ class Quizz:
...
@@ -22,7 +22,7 @@ class Quizz:
if
q
.
attrib
[
'
type
'
]
==
"
multichoice
"
:
if
q
.
attrib
[
'
type
'
]
==
"
multichoice
"
:
newQ
=
MCQ
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
newQ
=
MCQ
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
elif
q
.
attrib
[
'
type
'
]
==
"
shortanswer
"
:
elif
q
.
attrib
[
'
type
'
]
==
"
shortanswer
"
:
newQ
=
Question
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
newQ
=
ShortAnswer
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
elif
q
.
attrib
[
'
type
'
]
==
"
truefalse
"
:
elif
q
.
attrib
[
'
type
'
]
==
"
truefalse
"
:
newQ
=
TF
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
newQ
=
TF
(
q
,
c
,
len
(
self
.
questions
[
c
]),
self
.
folder
)
elif
q
.
attrib
[
'
type
'
]
==
"
matching
"
:
elif
q
.
attrib
[
'
type
'
]
==
"
matching
"
:
...
@@ -101,11 +101,15 @@ class Answer:
...
@@ -101,11 +101,15 @@ class Answer:
class
MCQ
(
Question
):
class
MCQ
(
Question
):
HORIZONTAL
=
1
VERTICAL
=
0
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
super
().
__init__
(
xmlQ
,
c
,
n
,
f
)
super
().
__init__
(
xmlQ
,
c
,
n
,
f
)
self
.
choices
=
[]
self
.
choices
=
[]
self
.
choice_type
=
MCQ
.
VERTICAL
self
.
env
=
"
questionmult
"
self
.
env
=
"
questionmult
"
self
.
__parseAnswers
(
xmlQ
)
if
self
.
__class__
.
__name__
==
"
MCQ
"
:
self
.
__parseAnswers
(
xmlQ
)
def
__parseAnswers
(
self
,
xmlQ
):
def
__parseAnswers
(
self
,
xmlQ
):
self
.
shuffle
=
xmlQ
.
find
(
"
shuffleanswers
"
).
text
==
"
true
"
self
.
shuffle
=
xmlQ
.
find
(
"
shuffleanswers
"
).
text
==
"
true
"
...
@@ -115,25 +119,32 @@ class MCQ(Question):
...
@@ -115,25 +119,32 @@ class MCQ(Question):
fb
=
mlang_2_multiling
(
strip_tags
(
fb
,
self
.
folder
))
fb
=
mlang_2_multiling
(
strip_tags
(
fb
,
self
.
folder
))
self
.
choices
.
append
(
Answer
(
mlang_2_multiling
(
strip_tags
(
a
.
find
(
"
text
"
).
text
,
self
.
folder
)),
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
self
.
choices
.
append
(
Answer
(
mlang_2_multiling
(
strip_tags
(
a
.
find
(
"
text
"
).
text
,
self
.
folder
)),
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
def
get_choice_env
(
self
):
if
self
.
choice_type
==
MCQ
.
VERTICAL
:
return
"
choices
"
else
:
return
"
choiceshoriz
"
def
__str__
(
self
):
def
__str__
(
self
):
res
=
"""
\\
element{
"""
+
self
.
category
+
"""
}{
res
=
"""
\\
element{
"""
+
self
.
category
+
"""
}{
\\
begin{
"""
+
self
.
env
+
"""
}{
"""
+
self
.
id
+
"""
}
\\
nbpoints{
"""
+
score_2_str
(
self
.
max
)
+
"""
}
\\
begin{
"""
+
self
.
env
+
"""
}{
"""
+
self
.
id
+
"""
}
\\
nbpoints{
"""
+
score_2_str
(
self
.
max
)
+
"""
}
"""
+
self
.
q
+
"
\n\t\t\\
begin{
choices
}
"
"""
+
self
.
q
+
"
\n\t\t\\
begin{
"
+
self
.
get_choice_env
()
+
"
}
"
if
not
self
.
shuffle
:
if
not
self
.
shuffle
:
res
+=
"
[o]
"
res
+=
"
[o]
"
res
+=
"
\n
"
res
+=
"
\n
"
for
c
in
self
.
choices
:
for
c
in
self
.
choices
:
res
+=
str
(
c
)
res
+=
str
(
c
)
res
+=
"
\n\t\t\\
end{
choices
}
\n\t\\
end{
"
+
self
.
env
+
"
}
\n
}
\n\n
"
res
+=
"
\n\t\t\\
end{
"
+
self
.
get_choice_env
()
+
"
}
\n\t\\
end{
"
+
self
.
env
+
"
}
\n
}
\n\n
"
return
res
return
res
class
TF
(
MCQ
):
class
TF
(
MCQ
):
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
super
(
MCQ
,
self
).
__init__
(
xmlQ
,
c
,
n
,
f
)
super
().
__init__
(
xmlQ
,
c
,
n
,
f
)
self
.
choices
=
[]
self
.
choices
=
[]
self
.
env
=
"
question
"
self
.
env
=
"
question
"
self
.
shuffle
=
False
self
.
shuffle
=
False
self
.
__parseAnswers
(
xmlQ
)
if
self
.
__class__
.
__name__
==
"
MCQ
"
:
self
.
__parseAnswers
(
xmlQ
)
def
__parseAnswers
(
self
,
xmlQ
):
def
__parseAnswers
(
self
,
xmlQ
):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
...
@@ -145,6 +156,29 @@ class TF(MCQ):
...
@@ -145,6 +156,29 @@ class TF(MCQ):
else
:
else
:
self
.
choices
.
append
(
Answer
(
"
\\
multiling{faux}{false}
"
,
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
self
.
choices
.
append
(
Answer
(
"
\\
multiling{faux}{false}
"
,
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
class
ShortAnswer
(
TF
):
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
,
l
=
4
):
super
().
__init__
(
xmlQ
,
c
,
n
,
f
)
self
.
nb_lines
=
l
if
self
.
__class__
.
__name__
==
"
ShortAnswer
"
:
self
.
__parseAnswers
(
xmlQ
)
def
__parseAnswers
(
self
,
xmlQ
):
note
=
0
while
note
<
self
.
max
:
self
.
choices
.
append
(
note
)
note
+=
0.25
def
__str__
(
self
):
res
=
"""
\\
element{
"""
+
self
.
category
+
"""
}{
\\
begin{
"""
+
self
.
env
+
"""
}{
"""
+
self
.
id
+
"""
}
\\
nbpoints{
"""
+
score_2_str
(
self
.
max
)
+
"""
}
"""
+
self
.
q
+
"
\n\t\t\\
AMCOpen{lineheigh=0.8cm,lines=
"
+
str
(
self
.
nb_lines
)
+
"
}{
"
for
c
in
self
.
choices
:
res
+=
"
\\
wrongchoice{
"
+
score_2_str
(
c
)
+
"
}
\\
scoring{
"
+
score_2_str
(
c
)
+
"
}
"
res
+=
"
\\
correctchoice{
"
+
score_2_str
(
self
.
max
)
+
"
}
\\
scoring{
"
+
score_2_str
(
self
.
max
)
+
"
}
"
res
+=
"
}
\n\t\\
end{
"
+
self
.
env
+
"
}
\n
}
\n\n
"
return
res
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
quizz
=
Quizz
(
"
data/quiz-GI-4-SID-S1-top-20201204-1620.xml
"
,
"
data
"
)
quizz
=
Quizz
(
"
data/quiz-GI-4-SID-S1-top-20201204-1620.xml
"
,
"
data
"
)
#quizz = Quizz("data/quiz-GI-4.xml" , "data")
#quizz = Quizz("data/quiz-GI-4.xml" , "data")
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment