From 7fbc183825cb8280ac514c5b4bc88f0bb4318981 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Sat, 27 Jul 2024 17:05:08 -0700 Subject: [PATCH 1/7] adjustments to date extension achievement items --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 25 +++++++++++++++---- .../AchievementItems/ExtendDueDateGW.pm | 14 ++++++----- .../AchievementItems/SuperExtendDueDate.pm | 25 +++++++++++++++---- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index f20aba7474..7a40e39996 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -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 => 'ExtendDueDate', @@ -35,7 +37,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; @@ -71,10 +74,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)) { + 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); + } + } + + # 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} }--; diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm index 3d99f661f7..3a990ff343 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm @@ -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', @@ -78,10 +80,10 @@ 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. @@ -89,10 +91,10 @@ sub use_item ($self, $userName, $c) { 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); } diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index 28ee31a660..40a9b5007b 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -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 TWO_DAYS => 172800; + sub new ($class) { return bless { id => 'SuperExtendDueDate', @@ -35,7 +37,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; @@ -71,10 +74,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)) { + 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); + } + } + + # 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} }--; From 4cc3d5cbc2fe8673dcd9354dc8a8bfefe3c33eb9 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Sun, 28 Jul 2024 00:01:35 -0700 Subject: [PATCH 2/7] adjustment to reduced credit date extension --- lib/WeBWorK/AchievementItems/ReducedCred.pm | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 9ff714ecb8..35949c14ad 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -23,6 +23,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 => 'ReducedCred', @@ -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; @@ -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} }--; From be2fe03bbe5b9500e88f711bff4a6d19756141ba Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Fri, 22 Nov 2024 16:29:42 -0800 Subject: [PATCH 3/7] remove unnecessary parentheses --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 8 ++++---- lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm | 12 ++++++------ lib/WeBWorK/AchievementItems/ReducedCred.pm | 4 ++-- lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index 7a40e39996..b22326996d 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -37,7 +37,7 @@ 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 + ONE_DAY()) + if (between($sets->[$i]->open_date, $sets->[$i]->due_date + ONE_DAY) && $sets->[$i]->assignment_type eq 'default'); } @@ -85,11 +85,11 @@ sub use_item ($self, $userName, $c) { } # 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; + $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()); + $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); + $userSet->answer_date($userSet->due_date) if $userSet->due_date > $set->answer_date; $db->putUserSet($userSet); $globalData->{ $self->{id} }--; diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm index 3a990ff343..cccefc6f12 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm @@ -80,10 +80,10 @@ 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() + ONE_DAY()) + $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() + ONE_DAY()); - $userSet->answer_date($set->answer_date() + ONE_DAY()); + $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. @@ -91,10 +91,10 @@ sub use_item ($self, $userName, $c) { for my $version (@versions) { $set = $db->getSetVersion($userName, $setID, $version); - $set->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY()) + $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() + ONE_DAY()); - $set->answer_date($set->answer_date() + ONE_DAY()); + $set->due_date($set->due_date() + ONE_DAY); + $set->answer_date($set->answer_date() + ONE_DAY); $db->putSetVersion($set); } diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 35949c14ad..f624231627 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -41,7 +41,7 @@ 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 + ONE_DAY()) + if (between($sets->[$i]->open_date, $sets->[$i]->due_date + ONE_DAY) && $sets->[$i]->assignment_type eq 'default'); } @@ -97,7 +97,7 @@ sub use_item ($self, $userName, $c) { unless ($set->reduced_scoring_date && ($set->reduced_scoring_date < $set->due_date)); $userSet->enable_reduced_scoring(1); # Add time to the close date - $userSet->due_date($set->due_date + ONE_DAY()); + $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); diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index 40a9b5007b..02fc2bed82 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -37,7 +37,7 @@ 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 + TWO_DAYS()) + if (between($sets->[$i]->open_date, $sets->[$i]->due_date + TWO_DAYS) && $sets->[$i]->assignment_type eq 'default'); } @@ -85,9 +85,9 @@ sub use_item ($self, $userName, $c) { } # 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; + $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()); + $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); From c43a10501ccd1408b7c940dae30d464ac5e5e311 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Fri, 22 Nov 2024 16:48:39 -0800 Subject: [PATCH 4/7] ensure seed does not overflow --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 2 +- lib/WeBWorK/AchievementItems/ReducedCred.pm | 2 +- lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index b22326996d..e68e975511 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -79,7 +79,7 @@ sub use_item ($self, $userName, $c) { my @probIDs = $db->listUserProblems($userName, $setID); for my $probID (@probIDs) { my $problem = $db->getUserProblem($userName, $setID, $probID); - $problem->problem_seed($problem->problem_seed + 100); + $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); } } diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index f624231627..3e5f6a8e06 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -87,7 +87,7 @@ sub use_item ($self, $userName, $c) { my @probIDs = $db->listUserProblems($userName, $setID); for my $probID (@probIDs) { my $problem = $db->getUserProblem($userName, $setID, $probID); - $problem->problem_seed($problem->problem_seed + 100); + $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); } } diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index 02fc2bed82..0caca25ebb 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -79,7 +79,7 @@ sub use_item ($self, $userName, $c) { my @probIDs = $db->listUserProblems($userName, $setID); for my $probID (@probIDs) { my $problem = $db->getUserProblem($userName, $setID, $probID); - $problem->problem_seed($problem->problem_seed + 100); + $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); } } From 5799ccc0ef94f8647a591268d4f0e5ace3d1c0e1 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 17 Dec 2024 12:52:37 -0800 Subject: [PATCH 5/7] Tell users about achievements that will randomize problems if used after the close date --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 5 ++++- lib/WeBWorK/AchievementItems/ReducedCred.pm | 3 ++- lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index e68e975511..5d20f67e78 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -28,7 +28,10 @@ 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; } diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 3e5f6a8e06..f1fc835ea3 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -31,7 +31,8 @@ sub new ($class) { 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; } diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index 0caca25ebb..c3d9529899 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -28,7 +28,10 @@ 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; } From f455e391478c1f6280c71ef294e5f3bb34c3af54 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 17 Dec 2024 14:27:15 -0800 Subject: [PATCH 6/7] import after in achievement items where needed --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 2 +- lib/WeBWorK/AchievementItems/ReducedCred.pm | 2 +- lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index 5d20f67e78..ecc5816b0e 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -19,7 +19,7 @@ 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; diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index f1fc835ea3..23a8ff0dc2 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -20,7 +20,7 @@ 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; diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index c3d9529899..eb9cf88da1 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -19,7 +19,7 @@ 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; From e34631cbe1cf1096bf282cb64115e35078174741 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 17 Dec 2024 15:24:20 -0800 Subject: [PATCH 7/7] more efficient database accessing Co-authored-by: Glenn Rice <47527406+drgrice1@users.noreply.github.com> --- lib/WeBWorK/AchievementItems/ExtendDueDate.pm | 4 +--- lib/WeBWorK/AchievementItems/ReducedCred.pm | 4 +--- lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index ecc5816b0e..f645c59734 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -79,9 +79,7 @@ sub use_item ($self, $userName, $c) { # 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); + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); } diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 23a8ff0dc2..297c275d7e 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -85,9 +85,7 @@ sub use_item ($self, $userName, $c) { # 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); + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); } diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index eb9cf88da1..ccf960321d 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -79,9 +79,7 @@ sub use_item ($self, $userName, $c) { # 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); + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { $problem->problem_seed($problem->problem_seed % 2**31 + 1); $db->putUserProblem($problem); }