Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hallgrim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Jan Maximilian Michal
hallgrim
Commits
33a13d4a
Commit
33a13d4a
authored
8 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
argparse uses subparsers now. gen ist able the generate multiple instances
parent
499e6ebd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gen.py
+59
-11
59 additions, 11 deletions
gen.py
hallgrim/IliasXMLCreator/packer.py
+4
-4
4 additions, 4 deletions
hallgrim/IliasXMLCreator/packer.py
scripts/param_example.py
+24
-0
24 additions, 0 deletions
scripts/param_example.py
with
87 additions
and
15 deletions
gen.py
+
59
−
11
View file @
33a13d4a
...
...
@@ -11,7 +11,7 @@ from hallgrim.messages import *
from
hallgrim.parser
import
*
def
file
name
_to_module
(
name
):
def
file_to_module
(
name
):
return
name
.
rstrip
(
'
.py
'
).
replace
(
'
/
'
,
'
.
'
)
...
...
@@ -21,28 +21,73 @@ def type_selector(type):
if
'
single
'
in
type
:
return
'
SINGLE CHOICE QUESTION
'
def
file_exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
msg
=
'
The script
"
{}
"
does not exist.
'
.
format
(
path
)
raise
argparse
.
ArgumentTypeError
(
msg
)
return
path
def
parseme
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
subparsers
=
parser
.
add_subparsers
(
dest
=
"
command
"
)
parser_new
=
subparsers
.
add_parser
(
"
new
"
,
help
=
"
The utility the generate new scripts.
"
)
parser_new
.
add_argument
(
"
name
"
,
help
=
"
The name of the new script
"
)
parser_new
.
add_argument
(
"
-t
"
,
"
--type
"
,
choices
=
[
'
multi
'
,
'
single
'
,
'
gap
'
,
'
alignment
'
],
default
=
'
multi
'
,
metavar
=
'
TYPE
'
)
parser_new
.
add_argument
(
"
-a
"
,
"
--author
"
,
help
=
"
Name of the scripts author
"
,
default
=
'
ILIAS Author
'
,
metavar
=
'
AUTHOR
'
)
parser_new
.
add_argument
(
"
-p
"
,
"
--points
"
,
help
=
'
Points given for correct answer (different behavior for different questions)
'
,
type
=
float
,
metavar
=
'
POINTS
'
,
)
parser_gen
=
subparsers
.
add_parser
(
"
gen
"
,
help
=
"
Subcommand to convert from script to xml.
"
)
parser_gen
.
add_argument
(
'
-o
'
,
'
--out
'
,
help
=
'''
Specif
i
y different output file. If no argument is given the Name
help
=
'''
Specify different output file. If no argument is given the Name
of the script is used.
'''
,
type
=
argparse
.
FileType
(
'
w
'
),
metavar
=
'
FILE
'
)
parser
.
add_argument
(
parser
_gen
.
add_argument
(
'
input
'
,
help
=
'
Script to execute
'
,
type
=
file_exists
,
metavar
=
'
FILE
'
)
parser_gen
.
add_argument
(
'
-i
'
,
'
--instances
'
,
help
=
'
How many instances should be produced (Only for parametrized questions).
'
,
type
=
int
,
default
=
1
,
metavar
=
'
COUNT
'
)
args
=
parser
.
parse_args
()
return
args
.
out
,
args
.
input
if
args
.
command
==
'
gen
'
:
handle_choice_questions
(
args
.
out
,
args
.
input
,
args
.
instances
)
if
args
.
command
==
'
new
'
:
handle_new_script
(
args
.
name
,
args
.
type
,
args
.
author
,
args
.
points
)
def
main
():
output
,
script_name
=
parseme
()
script
=
importlib
.
import_module
(
file
name
_to_module
(
script_name
))
def
handle_choice_questions
(
output
,
script_name
,
instances
):
script
=
importlib
.
import_module
(
file_to_module
(
script_name
))
data
=
{
'
type
'
:
type_selector
(
script
.
meta
[
'
type
'
]),
'
description
'
:
"
_description
"
,
...
...
@@ -57,8 +102,11 @@ def main():
output
=
os
.
path
.
join
(
'
output
'
,
script
.
meta
[
'
title
'
])
+
'
.xml
'
if
not
output
else
output
packer
.
convert_and_print
(
data
,
output
)
packer
.
convert_and_print
(
data
,
output
,
instances
)
info
(
'
Processed
"
{}
"
and wrote xml to
"
{}
"
.
'
.
format
(
script_name
,
output
))
def
handle_new_script
(
name
,
type
,
author
,
points
):
raise
NotImplementedError
()
if
__name__
==
'
__main__
'
:
main
()
parseme
()
This diff is collapsed.
Click to expand it.
hallgrim/IliasXMLCreator/packer.py
+
4
−
4
View file @
33a13d4a
...
...
@@ -11,11 +11,11 @@ def create_xml_tree(item_list):
return
tree
def
convert_and_print
(
data
,
output
):
def
convert_and_print
(
data
,
output
,
instances
=
1
):
if
data
[
'
type
'
]
==
'
MULTIPLE CHOICE QUESTION
'
:
item
=
multi
.
MultipleChoiceQuestion
(
**
data
)()
item
_list
=
[
multi
.
MultipleChoiceQuestion
(
**
data
)()
for
_
in
range
(
instances
)]
if
data
[
'
type
'
]
==
'
SINGLE CHOICE QUESTION
'
:
item
=
single
.
SingleChoiceQuestion
(
**
data
)()
item
_list
=
[
single
.
SingleChoiceQuestion
(
**
data
)()
for
_
in
range
(
instances
)]
tree
=
create_xml_tree
(
[
item
]
)
tree
=
create_xml_tree
(
item
_list
)
tree
.
write
(
output
,
encoding
=
"
utf-8
"
,
xml_declaration
=
True
)
This diff is collapsed.
Click to expand it.
scripts/param_example.py
0 → 100644
+
24
−
0
View file @
33a13d4a
from
random
import
randint
,
sample
meta
=
{
'
author
'
:
'
Jan Maximilian Michal
'
,
'
title
'
:
'
Parameter example
'
,
'
type
'
:
'
single choice
'
,
'
points
'
:
4
,
# for correct answer
}
a
=
randint
(
-
50
,
49
)
b
=
randint
(
-
50
,
49
)
def
get_answers
(
right
,
count
=
4
):
possible
=
sample
(
range
(
-
100
,
a
+
b
),
count
//
2
)
+
\
sample
(
range
(
a
+
b
+
1
,
100
),
count
//
2
-
1
)
+
[
a
+
b
]
return
[(
'
X
'
if
answer
==
right
else
'
'
,
answer
)
for
answer
in
possible
]
task
=
"""
What is the answer to the question {} + {}?
"""
.
format
(
a
,
b
)
choices
=
'
\n
'
.
join
(
'
[%s] a + b = %d
'
%
c
for
c
in
get_answers
(
a
+
b
))
feedback
=
"
[[a + b = {}]]
"
.
format
(
a
+
b
)
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