Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
4473cf68
Commit
4473cf68
authored
13 years ago
by
Tim Hunt
Browse files
Options
Downloads
Patches
Plain Diff
Fix the quetiontype to make the deferred feedback tests pass.
parent
388520af
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
question.php
+31
-32
31 additions, 32 deletions
question.php
renderer.php
+10
-6
10 additions, 6 deletions
renderer.php
stack/questiontest.php
+1
-1
1 addition, 1 deletion
stack/questiontest.php
with
42 additions
and
39 deletions
question.php
+
31
−
32
View file @
4473cf68
...
...
@@ -345,24 +345,13 @@ class qtype_stack_question extends question_graded_automatically {
}
public
function
is_gradable_response
(
array
$response
)
{
// The following code requires all *inputs* to be non-empty and valid.
$allblank
=
true
;
foreach
(
$this
->
inputs
as
$name
=>
$input
)
{
$status
=
$this
->
get_input_state
(
$name
,
$response
)
->
status
;
if
(
stack_input
::
INVALID
==
$status
)
{
return
false
;
}
$allblank
=
$allblank
&&
(
$status
==
stack_input
::
BLANK
);
}
return
!
$allblank
;
/*
// I think this is closer to the mark....
$anyprtgradable = false;
// If any PRT is gradable, then we can grade the question.
foreach
(
$this
->
prts
as
$index
=>
$prt
)
{
$anyprtgradable = $anyprtgradable || $this->can_execute_prt($prt, $response);
if
(
$this
->
can_execute_prt
(
$prt
,
$response
,
true
))
{
return
true
;
}
return $anyprtgradable;
*/
}
return
false
;
}
public
function
get_validation_error
(
array
$response
)
{
...
...
@@ -374,7 +363,7 @@ class qtype_stack_question extends question_graded_automatically {
$fraction
=
0
;
foreach
(
$this
->
prts
as
$index
=>
$prt
)
{
$results
=
$this
->
get_prt_result
(
$index
,
$response
);
$results
=
$this
->
get_prt_result
(
$index
,
$response
,
true
);
$fraction
+=
$results
[
'fraction'
];
}
return
array
(
$fraction
,
question_state
::
graded_state_for_fraction
(
$fraction
));
...
...
@@ -384,11 +373,16 @@ class qtype_stack_question extends question_graded_automatically {
* Do we have all the necessary inputs to execute one of the potential response trees?
* @param stack_potentialresponse_tree $prt the tree in question.
* @param array $response the response.
* @param bool $acceptvalid if this is true, then we will grade things even
* if the corresponding inputs are only VALID, and not SCORE.
* @return bool can this PRT be executed for that response.
*/
protected
function
can_execute_prt
(
stack_potentialresponse_tree
$prt
,
$response
)
{
protected
function
can_execute_prt
(
stack_potentialresponse_tree
$prt
,
$response
,
$acceptvalid
)
{
foreach
(
$prt
->
get_required_variables
(
array_keys
(
$this
->
inputs
))
as
$name
)
{
if
(
stack_input
::
SCORE
!=
$this
->
get_input_state
(
$name
,
$response
)
->
status
)
{
$status
=
$this
->
get_input_state
(
$name
,
$response
)
->
status
;
if
(
stack_input
::
SCORE
==
$status
||
(
$acceptvalid
&&
stack_input
::
VALID
==
$status
))
{
// This input is in an OK state.
}
else
{
return
false
;
}
}
...
...
@@ -399,29 +393,21 @@ class qtype_stack_question extends question_graded_automatically {
* Evaluate a PRT for a particular response.
* @param string $index the index of the PRT to evaluate.
* @param array $response the response to process.
* @param bool $acceptvalid if this is true, then we will grade things even
* if the corresponding inputs are only VALID, and not SCORE.
* @return array the result from $prt->evaluate_response(), or a fake array
* if the tree cannot be executed.
*/
public
function
get_prt_result
(
$index
,
$response
)
{
public
function
get_prt_result
(
$index
,
$response
,
$acceptvalid
)
{
$this
->
validate_cache
(
$response
);
if
(
array_key_exists
(
$index
,
$this
->
prtresults
))
{
return
$this
->
prtresults
[
$index
];
}
// Make sure we use modified inputs
$modifiedresponse
=
array
();
foreach
(
$response
as
$name
=>
$val
)
{
if
(
array_key_exists
(
$name
,
$this
->
inputstates
))
{
$modifiedresponse
[
$name
]
=
$this
->
inputstates
[
$name
]
->
contentsmodified
;
}
}
$prt
=
$this
->
prts
[
$index
];
if
(
$this
->
can_execute_prt
(
$prt
,
$response
))
{
$this
->
prtresults
[
$index
]
=
$prt
->
evaluate_response
(
$this
->
session
,
$this
->
options
,
$modifiedresponse
,
$this
->
seed
);
}
else
{
if
(
!
$this
->
can_execute_prt
(
$prt
,
$response
,
$acceptvalid
))
{
$this
->
prtresults
[
$index
]
=
array
(
'feedback'
=>
''
,
'answernote'
=>
null
,
...
...
@@ -431,7 +417,20 @@ class qtype_stack_question extends question_graded_automatically {
'penalty'
=>
null
,
'fraction'
=>
null
,
);
return
$this
->
prtresults
[
$index
];
}
// Make sure we use modified inputs
$modifiedresponse
=
array
();
foreach
(
$prt
->
get_required_variables
(
array_keys
(
$this
->
inputs
))
as
$name
)
{
$state
=
$this
->
get_input_state
(
$name
,
$response
);
if
(
stack_input
::
SCORE
==
$state
->
status
||
(
$acceptvalid
&&
stack_input
::
VALID
==
$state
->
status
))
{
$modifiedresponse
[
$name
]
=
$state
->
contentsmodified
;
}
}
$this
->
prtresults
[
$index
]
=
$prt
->
evaluate_response
(
$this
->
session
,
$this
->
options
,
$modifiedresponse
,
$this
->
seed
);
return
$this
->
prtresults
[
$index
];
}
...
...
This diff is collapsed.
Click to expand it.
renderer.php
+
10
−
6
View file @
4473cf68
...
...
@@ -55,11 +55,12 @@ class qtype_stack_renderer extends qtype_renderer {
}
foreach
(
$question
->
prts
as
$index
=>
$prt
)
{
$feedback
=
''
;
if
(
$options
->
feedback
)
{
$result
=
$question
->
get_prt_result
(
$index
,
$response
);
$result
=
$question
->
get_prt_result
(
$index
,
$response
,
$qa
->
get_state
()
->
is_finished
());
if
(
!
is_null
(
$result
[
'valid'
]))
{
$feedback
=
$this
->
prt_feedback
(
$index
,
$qa
,
$question
,
$result
);
}
else
{
$feedback
=
''
;
}
}
$questiontext
=
str_replace
(
"[[feedback:
{
$index
}
]]"
,
$feedback
,
$questiontext
);
}
...
...
@@ -101,8 +102,11 @@ class qtype_stack_renderer extends qtype_renderer {
// Replace any PRT feedback.
foreach
(
$question
->
prts
as
$index
=>
$prt
)
{
$result
=
$question
->
get_prt_result
(
$index
,
$response
);
$feedback
=
''
;
$result
=
$question
->
get_prt_result
(
$index
,
$response
,
$qa
->
get_state
()
->
is_finished
());
if
(
!
is_null
(
$result
[
'valid'
]))
{
$feedback
=
$this
->
prt_feedback
(
$index
,
$qa
,
$question
,
$result
);
}
$feedbacktext
=
str_replace
(
"[[feedback:
{
$index
}
]]"
,
$feedback
,
$feedbacktext
);
}
...
...
This diff is collapsed.
Click to expand it.
stack/questiontest.php
+
1
−
1
View file @
4473cf68
...
...
@@ -85,7 +85,7 @@ class stack_question_test {
}
foreach
(
$this
->
expectedresults
as
$prtname
=>
$expectedresult
)
{
$result
=
$question
->
get_prt_result
(
$prtname
,
$response
);
$result
=
$question
->
get_prt_result
(
$prtname
,
$response
,
false
);
$results
->
set_prt_result
(
$prtname
,
new
stack_potentialresponse_tree_state
(
''
,
$result
[
'feedback'
],
explode
(
' | '
,
$result
[
'answernote'
]),
$result
[
'valid'
],
$result
[
'score'
],
$result
[
'penalty'
]));
...
...
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