Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjustments to date extension achievement items #2467

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions lib/WeBWorK/AchievementItems/ExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ 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 => '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,22 @@ 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)) {
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
my @probIDs = $db->listUserProblems($userName, $setID);
for my $probID (@probIDs) {
my $problem = $db->getUserProblem($userName, $setID, $probID);
Alex-Jordan marked this conversation as resolved.
Show resolved Hide resolved
$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: 23 additions & 7 deletions lib/WeBWorK/AchievementItems/ReducedCred.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ 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 => '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,24 @@ 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)) {
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
my @probIDs = $db->listUserProblems($userName, $setID);
for my $probID (@probIDs) {
my $problem = $db->getUserProblem($userName, $setID, $probID);
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
$problem->problem_seed($problem->problem_seed % 2**31 + 1);
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
$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: 24 additions & 6 deletions lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ 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 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,22 @@ 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)) {
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
my @probIDs = $db->listUserProblems($userName, $setID);
for my $probID (@probIDs) {
my $problem = $db->getUserProblem($userName, $setID, $probID);
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
$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