Skip to content

Commit

Permalink
Merge pull request openwebwork#2467 from Alex-Jordan/achievement-date…
Browse files Browse the repository at this point in the history
…-extensions

adjustments to date extension achievement items
  • Loading branch information
drgrice1 authored Jan 17, 2025
2 parents fe3e59f + e34631c commit 3219060
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 28 deletions.
30 changes: 23 additions & 7 deletions lib/WeBWorK/AchievementItems/ExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
# Item to extend a close date by 24 hours.

use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64);
use WeBWorK::Utils::DateTime qw(between);
use WeBWorK::Utils::DateTime qw(after between);
use WeBWorK::Utils::Sets qw(format_set_name_display);

use constant ONE_DAY => 86400;

sub new ($class) {
return bless {
id => 'ExtendDueDate',
name => x('Tunic of Extension'),
description => x('Adds 24 hours to the close date of a homework.')
description => x(
'Adds 24 hours to the close date of a homework. '
. 'This will randomize problem details if used after the original close date.'
)
}, $class;
}

Expand All @@ -35,7 +40,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
if (between($sets->[$i]->open_date, $sets->[$i]->due_date + ONE_DAY)
&& $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;
Expand Down Expand Up @@ -71,10 +77,20 @@ sub use_item ($self, $userName, $c) {
my $userSet = $db->getUserSet($userName, $setID);
return q{Couldn't find that set!} unless $set && $userSet;

# Add time to the reduced scoring date, due date, and answer date.
$userSet->reduced_scoring_date($set->reduced_scoring_date() + 86400) if $set->reduced_scoring_date;
$userSet->due_date($set->due_date() + 86400);
$userSet->answer_date($set->answer_date() + 86400);
# Change the seed for all of the problems if the set is currently closed.
if (after($set->due_date)) {
for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) {
$problem->problem_seed($problem->problem_seed % 2**31 + 1);
$db->putUserProblem($problem);
}
}

# Add time to the reduced scoring date if it was defined in the first place
$userSet->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY) if $set->reduced_scoring_date;
# Add time to the close date
$userSet->due_date($set->due_date + ONE_DAY);
# This may require also extending the answer date.
$userSet->answer_date($userSet->due_date) if $userSet->due_date > $set->answer_date;
$db->putUserSet($userSet);

$globalData->{ $self->{id} }--;
Expand Down
14 changes: 8 additions & 6 deletions lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64);
use WeBWorK::Utils::DateTime qw(between);
use WeBWorK::Utils::Sets qw(format_set_name_display);

use constant ONE_DAY => 86400;

sub new ($class) {
return bless {
id => 'ExtendDueDateGW',
Expand Down Expand Up @@ -78,21 +80,21 @@ sub use_item ($self, $userName, $c) {
return q{Couldn't find that set!} unless $set && $userSet;

# Add time to the reduced scoring date, due date, and answer date.
$userSet->reduced_scoring_date($set->reduced_scoring_date() + 86400)
$userSet->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY)
if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date();
$userSet->due_date($set->due_date() + 86400);
$userSet->answer_date($set->answer_date() + 86400);
$userSet->due_date($set->due_date() + ONE_DAY);
$userSet->answer_date($set->answer_date() + ONE_DAY);
$db->putUserSet($userSet);

# Add time to the reduced scoring date, due date, and answer date for all versions.
my @versions = $db->listSetVersions($userName, $setID);

for my $version (@versions) {
$set = $db->getSetVersion($userName, $setID, $version);
$set->reduced_scoring_date($set->reduced_scoring_date() + 86400)
$set->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY)
if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date();
$set->due_date($set->due_date() + 86400);
$set->answer_date($set->answer_date() + 86400);
$set->due_date($set->due_date() + ONE_DAY);
$set->answer_date($set->answer_date() + ONE_DAY);
$db->putSetVersion($set);
}

Expand Down
30 changes: 22 additions & 8 deletions lib/WeBWorK/AchievementItems/ReducedCred.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
# Reduced scoring needs to be enabled for this item to work.

use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64);
use WeBWorK::Utils::DateTime qw(between);
use WeBWorK::Utils::DateTime qw(after between);
use WeBWorK::Utils::Sets qw(format_set_name_display);

use constant ONE_DAY => 86400;

sub new ($class) {
return bless {
id => 'ReducedCred',
name => x('Ring of Reduction'),
description => x(
'Enable reduced scoring for a homework set. This will allow you to submit answers '
. 'for partial credit for 24 hours after the close date.'
. 'for partial credit for 24 hours after the close date. '
. 'This will randomize problem details if used after the original close date.'
)
}, $class;
}
Expand All @@ -39,7 +42,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
if (between($sets->[$i]->open_date, $sets->[$i]->due_date + ONE_DAY)
&& $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;
Expand Down Expand Up @@ -79,12 +83,22 @@ sub use_item ($self, $userName, $c) {
my $userSet = $db->getUserSet($userName, $setID);
return "Couldn't find that set!" unless $set && $userSet;

# Enable reduced scoring on the set and add the reduced scoring period to the due date.
my $additionalTime = 60 * $ce->{pg}{ansEvalDefaults}{reducedScoringPeriod};
# Change the seed for all of the problems if the set is currently closed.
if (after($set->due_date)) {
for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) {
$problem->problem_seed($problem->problem_seed % 2**31 + 1);
$db->putUserProblem($problem);
}
}

# Either there is already a valid reduced scoring date, or set the reduced scoring date to the close date.
$userSet->reduced_scoring_date($set->due_date)
unless ($set->reduced_scoring_date && ($set->reduced_scoring_date < $set->due_date));
$userSet->enable_reduced_scoring(1);
$userSet->reduced_scoring_date($set->due_date());
$userSet->due_date($set->due_date() + $additionalTime);
$userSet->answer_date($set->answer_date() + $additionalTime);
# Add time to the close date
$userSet->due_date($set->due_date + ONE_DAY);
# This may require also extending the answer date.
$userSet->answer_date($userSet->due_date) if ($userSet->due_date > $set->answer_date);
$db->putUserSet($userSet);

$globalData->{ $self->{id} }--;
Expand Down
30 changes: 23 additions & 7 deletions lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
# Item to extend a close date by 48 hours.

use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64);
use WeBWorK::Utils::DateTime qw(between);
use WeBWorK::Utils::DateTime qw(after between);
use WeBWorK::Utils::Sets qw(format_set_name_display);

use constant TWO_DAYS => 172800;

sub new ($class) {
return bless {
id => 'SuperExtendDueDate',
name => x('Robe of Longevity'),
description => x('Adds 48 hours to the close date of a homework.')
description => x(
'Adds 48 hours to the close date of a homework. '
. 'This will randomize problem details if used after the original close date.'
)
}, $class;
}

Expand All @@ -35,7 +40,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
if (between($sets->[$i]->open_date, $sets->[$i]->due_date + TWO_DAYS)
&& $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;
Expand Down Expand Up @@ -71,10 +77,20 @@ sub use_item ($self, $userName, $c) {
my $userSet = $db->getUserSet($userName, $setID);
return q{Couldn't find that set!} unless $set && $userSet;

# Add time to the reduced scoring date, due date, and answer date.
$userSet->reduced_scoring_date($set->reduced_scoring_date() + 172800) if $set->reduced_scoring_date;
$userSet->due_date($set->due_date() + 172800);
$userSet->answer_date($set->answer_date() + 172800);
# Change the seed for all of the problems if the set is currently closed.
if (after($set->due_date)) {
for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) {
$problem->problem_seed($problem->problem_seed % 2**31 + 1);
$db->putUserProblem($problem);
}
}

# Add time to the reduced scoring date if it was defined in the first place
$userSet->reduced_scoring_date($set->reduced_scoring_date + TWO_DAYS) if $set->reduced_scoring_date;
# Add time to the close date
$userSet->due_date($set->due_date + TWO_DAYS);
# This may require also extending the answer date.
$userSet->answer_date($userSet->due_date) if ($userSet->due_date > $set->answer_date);
$db->putUserSet($userSet);

$globalData->{ $self->{id} }--;
Expand Down

0 comments on commit 3219060

Please sign in to comment.