Skip to content

Commit

Permalink
adjustment to reduced credit date extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Jul 28, 2024
1 parent a0dbe04 commit 44dded1
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/WeBWorK/AchievementItems/ReducedCred.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ 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',
Expand All @@ -39,7 +41,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 +82,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)) {
my @probIDs = $db->listUserProblems($userName, $setID);
for my $probID (@probIDs) {
my $problem = $db->getUserProblem($userName, $setID, $probID);
$problem->problem_seed($problem->problem_seed + 100);
$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

0 comments on commit 44dded1

Please sign in to comment.