Bolt: added mechanism to view old answer pages

svn path=/trunk/boinc/; revision=14396
This commit is contained in:
David Anderson 2007-12-18 23:37:26 +00:00
parent 2cd5dba886
commit 2f3d70a228
4 changed files with 46 additions and 19 deletions

View File

@ -24,9 +24,11 @@ create table bolt_enrollment (
mastery double not null
);
-- represents a view of an item;
-- Represents a view of an item;
-- created when we show the item,
-- and finalized when the user clicks on something to leave the page
-- A special view is used to represent the end of a course;
-- its mode is BOLT_MODE_FINISHED.
--
create table bolt_view (
id integer not null auto_increment,
@ -37,7 +39,7 @@ create table bolt_view (
state text not null,
-- course state
mode integer not null,
-- distnguishes exercise show/answer
-- distinguishes exercise show/answer
action integer not null,
-- what the user clicked
start_time integer not null,

View File

@ -9,7 +9,6 @@ function bolt_exclusive_choice($choices) {
global $bolt_ex_mode; // input
global $bolt_ex_index; // input
global $bolt_ex_score; // incremental output if SCORE
global $bolt_ex_response; // output if SCORE
switch ($bolt_ex_mode) {
case BOLT_MODE_SHOW:
@ -31,9 +30,6 @@ function bolt_exclusive_choice($choices) {
if ($choices[$response] == $right_ans) {
$bolt_ex_score += 1;
}
$bolt_ex_response = "$bolt_ex_index: $choices[$response]";
} else {
$bolt_ex_response = "";
}
break;
case BOLT_MODE_ANSWER:
@ -64,7 +60,6 @@ function bolt_inclusive_choice($choices) {
global $bolt_ex_mode; // input
global $bolt_ex_index; // input
global $bolt_ex_score; // incremental output if SCORE
global $bolt_ex_response; // output if SCORE
switch ($bolt_ex_mode) {
case BOLT_MODE_SHOW:
@ -91,7 +86,6 @@ function bolt_inclusive_choice($choices) {
if ($correct) $score += 1./$n;
$i++;
}
$bolt_ex_response = "$bolt_ex_index: $choices[$response]";
$bolt_ex_score += $score;
break;
case BOLT_MODE_ANSWER:

View File

@ -35,15 +35,16 @@ function show_view($view) {
if ($view->result_id) {
$result = BoltResult::lookup_id($view->result_id);
$x = "Score: $result->score
<br>Answer: $result->response";
$qs = str_replace("action=answer", "action=answer_page", $result->response);
$x = "<br>Score: $result->score
<br><a href=bolt_sched.php?$qs>Answer page</a>";
}
echo "<tr>
<td>".time_str($view->start_time)."</td>
<td>$dur</td>
<td>$view->item_name</td>
<td>".mode_name($view->mode)." $x</td>
<td>".action_name($view->action)."</td>
<td valign=top>".time_str($view->start_time)."</td>
<td valign=top>$dur</td>
<td valign=top>$view->item_name</td>
<td valign=top>".mode_name($view->mode)." $x</td>
<td valign=top>".action_name($view->action)."</td>
</tr>
";
}
@ -57,7 +58,7 @@ page_head("Your history in $course->name");
$views = BoltView::enum("user_id=$user->id and course_id=$course_id order by id desc");
start_table();
table_header("Time", "Duration", "Name", "Type", "Action");
table_header("Time", "Duration", "Item", "Type", "Action");
foreach ($views as $view) {
show_view($view);
}

View File

@ -148,6 +148,25 @@ function show_item($iter, $user, $course, $view_id, $prev_view_id, $mode) {
$e->update("last_view_id=$view_id");
}
// Show the student the results of an old exercise; no navigation items
//
function show_answer_page($iter, $score) {
global $bolt_ex_mode;
global $bolt_ex_index;
$bolt_ex_mode = BOLT_MODE_ANSWER;
$bolt_ex_index = 0;
$item = $iter->item;
page_head(null);
if (function_exists('bolt_header')) bolt_header($item->title);
require_once($item->filename);
if (function_exists('bolt_divide')) bolt_divide();
$score_pct = number_format($score*100);
echo "Score: $score_pct%";
if (function_exists('bolt_footer')) bolt_footer();
}
function start_course($user, $course, $course_doc) {
BoltEnrollment::delete($user->id, $course->id);
$iter = new BoltIter($course_doc);
@ -237,24 +256,35 @@ case 'answer': // submit answer in exercise
$bolt_ex_mode = BOLT_MODE_SCORE;
$bolt_ex_index = 0;
$bolt_ex_score = 0;
$bolt_ex_response = "";
srand($view_id);
ob_start(); // turn on output buffering
require($item->filename);
ob_end_clean();
$bolt_ex_response = BoltDb::escape_string($bolt_ex_response);
$bolt_ex_score /= $bolt_ex_index;
$qs = BoltDb::escape_string($_SERVER['QUERY_STRING']);
$result_id = BoltResult::insert(
"(view_id, score, response)
values ($view->id, $bolt_ex_score, '$bolt_ex_response')"
values ($view->id, $bolt_ex_score, '$qs')"
);
$view->update("result_id=$result_id");
srand($view_id);
$view_id = create_view($user, $course, $iter, BOLT_MODE_ANSWER, $view->id);
show_item($iter, $user, $course, $view_id, $view->id, BOLT_MODE_ANSWER);
break;
case 'answer_page':
$view = BoltView::lookup_id($view_id);
$iter = new BoltIter($course_doc);
$iter->decode_state($view->state);
$iter->at();
if ($iter->item->name != $view->item_name) {
error_page("Exercise no longer exists in course");
}
$result = BoltResult::lookup_id($view->result_id);
srand($view_id);
show_answer_page($iter, $result->score);
break;
default:
$view = $e?BoltView::lookup_id($e->last_view_id):null;
if (!$view) {