Skip to content

Commit

Permalink
Toward removing the attempts table.
Browse files Browse the repository at this point in the history
The table is actually removed, but the results summary is still output
by the now inappropriately named AttemptsTable module.
  • Loading branch information
drgrice1 committed Sep 27, 2023
1 parent 674625f commit a784d39
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 418 deletions.
24 changes: 7 additions & 17 deletions lib/FormatRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,14 @@ sub formatRenderedProblem {
my $answerTemplate = '';

# Do not produce an AttemptsTable when we had a rendering error.
if (!$renderErrorOccurred) {
my $tbl = WeBWorK::HTML::AttemptsTable->new(
if (!$renderErrorOccurred && !$previewMode) {
$answerTemplate = WeBWorK::HTML::AttemptsTable->new(
$rh_result->{answers} // {}, $ws->c,
answersSubmitted => $ws->{inputs_ref}{answersSubmitted} // 0,
answerOrder => $rh_result->{flags}{ANSWER_ENTRY_ORDER} // [],
displayMode => $displayMode,
showAnswerNumbers => $showAnswerNumbers,
ce => $ce,
showAttemptPreviews => $previewMode || $submitMode || $showCorrectMode,
showAttemptResults => $submitMode || $showCorrectMode,
showCorrectAnswers => $showCorrectMode,
showMessages => $previewMode || $submitMode || $showCorrectMode,
showSummary => (($showSummary && ($submitMode || $showCorrectMode)) // 0) ? 1 : 0,
maketext => WeBWorK::Localize::getLoc($formLanguage),
summary => $problemResult->{summary} // '', # can be set by problem grader
);
$answerTemplate = $tbl->answerTemplate;
$tbl->imgGen->render(refresh => 1) if $tbl->displayMode eq 'images';
answersSubmitted => $ws->{inputs_ref}{answersSubmitted} // 0,
answerOrder => $rh_result->{flags}{ANSWER_ENTRY_ORDER} // [],
showSummary => (($showSummary && ($submitMode || $showCorrectMode)) // 0) ? 1 : 0,
summary => $problemResult->{summary} // '' # can be set by problem grader
)->answerTemplate;
}

# Answer hash in XML format used by the PTX format.
Expand Down
84 changes: 28 additions & 56 deletions lib/WeBWorK/ContentGenerator/GatewayQuiz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,42 +238,17 @@ sub can_useMathQuill ($c) {
}

# Output utility
sub attemptResults ($c, $pg, $showCorrectAnswers, $showAttemptResults, $showSummary) {
sub attemptResults ($c, $pg, $showSummary) {
my $ce = $c->ce;

# Create AttemptsTable object
my $tbl = WeBWorK::HTML::AttemptsTable->new(
return WeBWorK::HTML::AttemptsTable->new(
$pg->{answers},
$c,
answersSubmitted => 1,
answerOrder => $pg->{flags}{ANSWER_ENTRY_ORDER},
displayMode => $c->{displayMode},
showHeadline => 0,
showAnswerNumbers => 0,
showAttemptAnswers => $ce->{pg}{options}{showEvaluatedAnswers},
showAttemptPreviews => 1,
showAttemptResults => $showAttemptResults,
showCorrectAnswers => $showCorrectAnswers,
showMessages => 1,
showSummary => $showSummary,
imgGen => WeBWorK::PG::ImageGenerator->new(
tempDir => $ce->{webworkDirs}{tmp},
latex => $ce->{externalPrograms}{latex},
dvipng => $ce->{externalPrograms}{dvipng},
useCache => 1,
cacheDir => $ce->{webworkDirs}{equationCache},
cacheURL => $ce->{webworkURLs}{equationCache},
cacheDB => $ce->{webworkFiles}{equationCacheDB},
useMarkers => 1,
dvipng_align => $ce->{pg}{displayModeOptions}{images}{dvipng_align},
dvipng_depth_db => $ce->{pg}{displayModeOptions}{images}{dvipng_depth_db},
),
);

my $answerTemplate = $tbl->answerTemplate;
$tbl->imgGen->render(body_text => $answerTemplate) if $tbl->displayMode eq 'images';

return $answerTemplate;
answersSubmitted => 1,
answerOrder => $pg->{flags}{ANSWER_ENTRY_ORDER},
showHeadline => 0,
showSummary => $showSummary,
)->answerTemplate;
}

sub get_instructor_comment ($c, $problem) {
Expand Down Expand Up @@ -1482,18 +1457,6 @@ sub warningMessage ($c) {
# hash of parameters from the input form that need to be passed to the translator, and $mergedProblem
# is what we'd expect.
async sub getProblemHTML ($c, $effectiveUser, $set, $formFields, $mergedProblem) {
my $setID = $set->set_id;
my $setVersionNumber = $set->version_id;

# Figure out solutions are allowed and call renderPG accordingly.
my $showCorrectAnswers = $c->{will}{showCorrectAnswers};
my $showHints = $c->{will}{showHints};
my $showSolutions = $c->{will}{showSolutions};
my $processAnswers = $c->{will}{checkAnswers};

# FIXME: I'm not sure that problem_id is what we want here.
my $problemNumber = $mergedProblem->problem_id;

my $pg = await renderPG(
$c,
$effectiveUser,
Expand All @@ -1502,17 +1465,26 @@ async sub getProblemHTML ($c, $effectiveUser, $set, $formFields, $mergedProblem)
$set->psvn,
$formFields,
{
displayMode => $c->{displayMode},
showHints => $showHints,
showSolutions => $showSolutions,
refreshMath2img => $showHints || $showSolutions,
processAnswers => 1,
QUIZ_PREFIX => 'Q' . sprintf('%04d', $problemNumber) . '_',
useMathQuill => $c->{will}{useMathQuill},
useMathView => $c->{will}{useMathView},
forceScaffoldsOpen => 1,
isInstructor => $c->authz->hasPermissions($c->{userID}, 'view_answers'),
debuggingOptions => getTranslatorDebuggingOptions($c->authz, $c->{userID})
displayMode => $c->{displayMode},
showHints => $c->{will}{showHints},
showSolutions => $c->{will}{showSolutions},
refreshMath2img => $c->{will}{showHints} || $c->{will}{showSolutions},
processAnswers => 1,
QUIZ_PREFIX => 'Q' . sprintf('%04d', $mergedProblem->problem_id) . '_',
useMathQuill => $c->{will}{useMathQuill},
useMathView => $c->{will}{useMathView},
forceScaffoldsOpen => 1,
isInstructor => $c->authz->hasPermissions($c->{userID}, 'view_answers'),
showFeedback => $c->{submitAnswers} || $c->{previewAnswers} || $c->{will}{checkAnswers},
showAttemptAnswers => $c->ce->{pg}{options}{showEvaluatedAnswers},
showAttemptPreviews => 1,
showAttemptResults => !$c->{previewAnswers} && $c->{can}{showProblemScores},
forceShowAttemptResults => $c->{will}{showProblemGrader},
showMessages => 1,
showCorrectAnswers => ($c->{submitAnswers} || $c->{will}{checkAnswers} || $c->{will}{showProblemGrader})
? $c->{will}{showCorrectAnswers}
: 0,
debuggingOptions => getTranslatorDebuggingOptions($c->authz, $c->{userID})
},
);

Expand All @@ -1523,7 +1495,7 @@ async sub getProblemHTML ($c, $effectiveUser, $set, $formFields, $mergedProblem)
if ($pg->{flags}{error_flag}) {
push @{ $c->{errors} },
{
set => "$setID,v$setVersionNumber",
set => $set->set_id . ',v' . $set->version_id,
problem => $mergedProblem->problem_id,
message => $pg->{errors},
context => $pg->{body_text},
Expand Down
103 changes: 38 additions & 65 deletions lib/WeBWorK/ContentGenerator/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -246,42 +246,16 @@ sub can_showMeAnother ($c, $user, $effectiveUser, $set, $problem, $submitAnswers
return 0;
}

sub attemptResults ($c, $pg, $showCorrectAnswers, $showAttemptResults, $showSummary) {
sub attemptResults ($c, $pg, $showSummary) {
my $ce = $c->ce;

# Create AttemptsTable object
my $tbl = WeBWorK::HTML::AttemptsTable->new(
return WeBWorK::HTML::AttemptsTable->new(
$pg->{answers},
$c,
answersSubmitted => 1,
answerOrder => $pg->{flags}{ANSWER_ENTRY_ORDER},
displayMode => $c->{displayMode},
showAnswerNumbers => 0,
showAttemptAnswers => $ce->{pg}{options}{showEvaluatedAnswers},
showAttemptPreviews => 1,
showAttemptResults => $showAttemptResults,
showCorrectAnswers => $showCorrectAnswers,
showMessages => 1,
showSummary => $showSummary,
imgGen => WeBWorK::PG::ImageGenerator->new(
tempDir => $ce->{webworkDirs}{tmp},
latex => $ce->{externalPrograms}{latex},
dvipng => $ce->{externalPrograms}{dvipng},
useCache => 1,
cacheDir => $ce->{webworkDirs}{equationCache},
cacheURL => $ce->{webworkURLs}{equationCache},
cacheDB => $ce->{webworkFiles}{equationCacheDB},
useMarkers => 1,
dvipng_align => $ce->{pg}{displayModeOptions}{images}{dvipng_align},
dvipng_depth_db => $ce->{pg}{displayModeOptions}{images}{dvipng_depth_db},
),
);

# Render equation images
my $answerTemplate = $tbl->answerTemplate;
$tbl->imgGen->render(body_text => \$answerTemplate) if $tbl->displayMode eq 'images';

return $answerTemplate;
answersSubmitted => 1,
answerOrder => $pg->{flags}{ANSWER_ENTRY_ORDER},
showSummary => $showSummary,
)->answerTemplate;
}

async sub pre_header_initialize ($c) {
Expand Down Expand Up @@ -451,6 +425,7 @@ async sub pre_header_initialize ($c) {
{
$c->{submitAnswers} = 0;
$c->{resubmitDetected} = 1;
delete $formFields->{submitAnswers};
}

$c->{displayMode} = $displayMode;
Expand Down Expand Up @@ -581,6 +556,24 @@ async sub pre_header_initialize ($c) {
# Final values for options
my %will = map { $_ => $can{$_} && ($want{$_} || $must{$_}) } keys %must;

if ($prEnabled && $problem->{prCount} >= $rerandomizePeriod && !after($c->{set}->due_date, $c->submitTime)) {
$showMeAnother{active} = 0;
$must{requestNewSeed} = 1;
$can{requestNewSeed} = 1;
$want{requestNewSeed} = 1;
$will{requestNewSeed} = 1;
$c->{showCorrectOnRandomize} = $ce->{pg}{options}{showCorrectOnRandomize};
# If this happens, it means that the page was refreshed. So prevent the answers from
# being recorded and the number of attempts from being increased.
if ($problem->{prCount} > $rerandomizePeriod) {
$c->{resubmitDetected} = 1;
$must{recordAnswers} = 0;
$can{recordAnswers} = 0;
$want{recordAnswers} = 0;
$will{recordAnswers} = 0;
}
}

# Sticky answers
if (!($c->{submitAnswers} || $previewAnswers || $checkAnswers) && $will{showOldAnswers}) {
my %oldAnswers = decodeAnswers($problem->last_answer);
Expand Down Expand Up @@ -615,7 +608,16 @@ async sub pre_header_initialize ($c) {
useMathView => $will{useMathView},
forceScaffoldsOpen => 0,
isInstructor => $authz->hasPermissions($userID, 'view_answers'),
debuggingOptions => getTranslatorDebuggingOptions($authz, $userID)
showFeedback => $c->{submitAnswers} || $c->{previewAnswers},
showAttemptAnswers => $ce->{pg}{options}{showEvaluatedAnswers},
showAttemptPreviews => 1,
showAttemptResults => $c->{submitAnswers},
forceShowAttemptResults => $will{checkAnswers} || $will{showProblemGrader},
showMessages => 1,
showCorrectAnswers => $c->{submitAnswers} ? ($c->{showCorrectOnRandomize} // $will{showCorrectAnswers})
: $will{checkAnswers} || $will{showProblemGrader} ? $will{showCorrectAnswers}
: 0,
debuggingOptions => getTranslatorDebuggingOptions($authz, $userID)
}
);

Expand All @@ -630,24 +632,6 @@ async sub pre_header_initialize ($c) {
id => 'num_attempts'
);

if ($prEnabled && $problem->{prCount} >= $rerandomizePeriod && !after($c->{set}->due_date, $c->submitTime)) {
$showMeAnother{active} = 0;
$must{requestNewSeed} = 1;
$can{requestNewSeed} = 1;
$want{requestNewSeed} = 1;
$will{requestNewSeed} = 1;
$c->{showCorrectOnRandomize} = $ce->{pg}{options}{showCorrectOnRandomize};
# If this happens, it means that the page was refreshed. So prevent the answers from
# being recorded and the number of attempts from being increased.
if ($problem->{prCount} > $rerandomizePeriod) {
$c->{resubmitDetected} = 1;
$must{recordAnswers} = 0;
$can{recordAnswers} = 0;
$want{recordAnswers} = 0;
$will{recordAnswers} = 0;
}
}

# Update and fix hint/solution options after PG processing
$can{showHints} &&= $pg->{flags}{hintExists};
$can{showSolutions} &&= $pg->{flags}{solutionExists};
Expand Down Expand Up @@ -1484,18 +1468,8 @@ sub output_summary ($c) {
my $output = $c->c;

# Attempt summary
if (defined $pg->{flags}{showPartialCorrectAnswers}
&& $pg->{flags}{showPartialCorrectAnswers} >= 0
&& $c->{submitAnswers})
{
push(
@$output,
$c->attemptResults(
$pg,
$c->{showCorrectOnRandomize} // $will{showCorrectAnswers},
$pg->{flags}{showPartialCorrectAnswers}, 1
)
);
if ($c->{submitAnswers}) {
push(@$output, $c->attemptResults($pg, 1));
} elsif ($will{checkAnswers} || $c->{will}{showProblemGrader}) {
push(
@$output,
Expand All @@ -1504,7 +1478,7 @@ sub output_summary ($c) {
class => 'ResultsWithError d-inline-block mb-3',
$c->maketext('ANSWERS ONLY CHECKED -- ANSWERS NOT RECORDED')
),
$c->attemptResults($pg, $will{showCorrectAnswers}, 1, 1)
$c->attemptResults($pg, 1)
);
} elsif ($c->{previewAnswers}) {
push(
Expand All @@ -1514,7 +1488,6 @@ sub output_summary ($c) {
class => 'ResultsWithError d-inline-block mb-3',
$c->maketext('PREVIEW ONLY -- ANSWERS NOT RECORDED')
),
$c->attemptResults($pg, 0, 0, 0)
);
}

Expand Down
Loading

0 comments on commit a784d39

Please sign in to comment.