[LON-CAPA-cvs] cvs: rat / lonpage.pm loncom/homework lonhomework.pm loncom/interface loncommon.pm lonnavmaps.pm

raeburn raeburn at source.lon-capa.org
Mon Jul 18 15:29:24 EDT 2016


raeburn		Mon Jul 18 19:29:24 2016 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm loncommon.pm 
    /loncom/homework	lonhomework.pm 
    /rat	lonpage.pm 
  Log:
  - For resources already checked into a slot (now past its end time), 
    check for use of unique time periods in used slot, when checking for other 
    reservable (future) slots.
  
  
-------------- next part --------------
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.521 loncom/interface/lonnavmaps.pm:1.522
--- loncom/interface/lonnavmaps.pm:1.521	Thu Jun  2 16:03:57 2016
+++ loncom/interface/lonnavmaps.pm	Mon Jul 18 19:28:57 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.521 2016/06/02 16:03:57 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.522 2016/07/18 19:28:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5562,13 +5562,13 @@
         my $cnum=$env{'course.'.$cid.'.num'};
         my $now = time;
         my $num_usable_slots = 0;
+        my ($checkedin,$checkedinslot,%consumed_uniq,%slots);
         if (@slots > 0) {
-            my %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
+            %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
             if (&Apache::lonnet::error(%slots)) {
                 return (UNKNOWN);
             }
             my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
-            my ($checkedin,$checkedinslot);
             foreach my $slot_name (@sorted_slots) {
                 next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name}));
                 my $end = $slots{$slot_name}->{'endtime'};
@@ -5602,19 +5602,30 @@
                     $num_usable_slots ++;
                 }
             }
-            my ($is_correct,$got_grade);
+            my ($is_correct,$wait_for_grade);
             if ($self->is_task()) {
                 my $taskstatus = $self->taskstatus();
                 $is_correct = (($taskstatus eq 'pass') || 
                                ($self->solved() =~ /^correct_/));
-                $got_grade = ($taskstatus =~ /^(?:pass|fail)$/);
+                unless ($taskstatus =~ /^(?:pass|fail)$/) {
+                    $wait_for_grade = 1;
+                }
             } else {
-                $got_grade = 1;
-                $is_correct = ($self->solved() =~ /^correct_/);   
+                unless ($self->completable()) {
+                    $wait_for_grade = 1;
+                }
+                unless (($self->problemstatus($part) eq 'no') ||
+                        ($self->problemstatus($part) eq 'no_feedback_ever')) {
+                    $is_correct = ($self->solved($part) =~ /^correct_/);
+                    $wait_for_grade = 0;
+                }
             }
             ($checkedin,$checkedinslot) = $self->checkedin();
             if ($checkedin) {
-                if (!$got_grade) {
+                if (ref($slots{$checkedinslot}) eq 'HASH') {
+                    $consumed_uniq{$checkedinslot} = $slots{$checkedinslot}{'uniqueperiod'};
+                }
+                if ($wait_for_grade) {
                     return (WAITING_FOR_GRADE);
                 } elsif ($is_correct) {
                     return (CORRECT); 
@@ -5652,6 +5663,17 @@
                         }
                     }
                     if ($canuse) {
+                        if ($checkedin) {
+                            if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
+                                my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
+                                if ($reservable->{'now'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
+                                    my ($new_uniq_start,$new_uniq_end) = ($1,$2);
+                                    next if (!
+                                        ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
+                                        ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
+                                }
+                            }
+                        }
                         return(RESERVABLE,$reservable->{'now'}{$slot}{'endreserve'});
                     }
                 }
@@ -5682,6 +5704,17 @@
                         $canuse = 1;
                     }
                     if ($canuse) {
+                        if ($checkedin) {
+                            if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
+                                my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
+                                if ($reservable->{'future'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
+                                    my ($new_uniq_start,$new_uniq_end) = ($1,$2);
+                                    next if (!
+                                        ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
+                                        ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
+                                }
+                            }
+                        }
                         return(RESERVABLE_LATER,$reservable->{'future'}{$slot}{'startreserve'});
                     }
                 }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1249 loncom/interface/loncommon.pm:1.1250
--- loncom/interface/loncommon.pm:1.1249	Fri Jul  8 17:21:01 2016
+++ loncom/interface/loncommon.pm	Mon Jul 18 19:28:58 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1249 2016/07/08 17:21:01 damieng Exp $
+# $Id: loncommon.pm,v 1.1250 2016/07/18 19:28:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -10625,7 +10625,9 @@
 
     Keys in inner hash are:
     (a) symb: either blank or symb to which slot use is restricted.
-    (b) endreserve: end date of reservation period. 
+    (b) endreserve: end date of reservation period.
+    (c) uniqueperiod: start,end dates when slot is to be uniquely
+        selected.
 
 sorted_future - ref to array of student_schedulable slots reservable in
                 the future, ordered by start date of reservation period.
@@ -10635,7 +10637,9 @@
 
     Keys in inner hash are:
     (a) symb: either blank or symb to which slot use is restricted.
-    (b) startreserve:  start date of reservation period.
+    (b) startreserve: start date of reservation period.
+    (c) uniqueperiod: start,end dates when slot is to be uniquely
+        selected.
 
 =back
 
@@ -10711,6 +10715,10 @@
             my $startreserve = $slots{$slot}->{'startreserve'};
             my $endreserve = $slots{$slot}->{'endreserve'};
             my $symb = $slots{$slot}->{'symb'};
+            my $uniqueperiod;
+            if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
+                $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
+            }
             if (($startreserve < $now) &&
                 (!$endreserve || $endreserve > $now)) {
                 my $lastres = $endreserve;
@@ -10719,13 +10727,15 @@
                 }
                 $reservable_now{$slot} = {
                                            symb       => $symb,
-                                           endreserve => $lastres
+                                           endreserve => $lastres,
+                                           uniqueperiod => $uniqueperiod,
                                          };
             } elsif (($startreserve > $now) &&
                      (!$endreserve || $endreserve > $startreserve)) {
                 $future_reservable{$slot} = {
                                               symb         => $symb,
-                                              startreserve => $startreserve
+                                              startreserve => $startreserve,
+                                              uniqueperiod => $uniqueperiod,
                                             };
             }
         }
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.362 loncom/homework/lonhomework.pm:1.363
--- loncom/homework/lonhomework.pm:1.362	Mon May 30 02:45:32 2016
+++ loncom/homework/lonhomework.pm	Mon Jul 18 19:29:11 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.362 2016/05/30 02:45:32 raeburn Exp $
+# $Id: lonhomework.pm,v 1.363 2016/07/18 19:29:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -210,7 +210,7 @@
 }
 
 sub check_slot_access {
-    my ($id,$type,$symb)=@_;
+    my ($id,$type,$symb,$partlist)=@_;
 
     # does it pass normal muster
     my ($status,$datemsg)=&check_access($id,$symb);
@@ -228,13 +228,15 @@
         $checkin = "resource.$version.0.checkedin";
     }
     my $checkedin = $Apache::lonhomework::history{$checkin};
-    my ($returned_slot,$slot_name,$checkinslot,$ipused,$blockip,$now,$ip);
+    my ($returned_slot,$slot_name,$checkinslot,$ipused,$blockip,$now,$ip,
+        $consumed_uniq);
     $now = time;
     $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
 
     if ($checkedin) {
         $checkinslot = $Apache::lonhomework::history{"$checkin.slot"};
         my %slot=&Apache::lonnet::get_slot($checkinslot);
+        $consumed_uniq = $slot{'uniqueperiod'};
         if ($slot{'iptied'}) {
             $ipused = $Apache::lonhomework::history{"$checkin.ip"};
             unless (($ip ne '') && ($ipused eq $ip)) {
@@ -349,9 +351,48 @@
 	    ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass'
 	     || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );
     } elsif ($type eq 'problem') {
-	$got_grade  = 1;
-	$is_correct =
-	    ($Apache::lonhomework::history{"resource.0.solved"} =~/^correct_/);
+        if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) {
+            my ($numcorrect,$numgraded) = (0,0);
+            foreach my $part (@{$partlist}) {
+                my $currtries = $Apache::lonhomework::history{"resource.$part.tries"};
+                my $maxtries = &Apache::lonnet::EXT("resource.$part.maxtries",$symb);
+                my $probstatus = &Apache::structuretags::get_problem_status($part);
+                my $earlyout;
+                unless (($probstatus eq 'no') ||
+                        ($probstatus eq 'no_feedback_ever')) { 
+                    if ($Apache::lonhomework::history{"resource.$part.solved"} =~/^correct_/) {
+                        $numcorrect ++;
+                    } else {
+                        $earlyout = 1;
+                    }
+                }
+                if (($currtries == $maxtries) || ($is_correct)) {
+                    $earlyout = 1;
+                } else { 
+                    $numgraded ++;
+                }
+                last if ($earlyout);
+            }
+            my $numparts = scalar(@{$partlist});
+            if ($numparts == $numcorrect) {
+                $is_correct = 1;
+            }
+            if ($numparts == $numgraded) {
+                $got_grade = 1;
+            }
+        } else {
+            my $currtries = $Apache::lonhomework::history{"resource.0.tries"};
+            my $maxtries = &Apache::lonnet::EXT("resource.0.maxtries",$symb);
+            my $probstatus = &Apache::structuretags::get_problem_status('0');
+            unless (($probstatus eq 'no') ||
+                    ($probstatus eq 'no_feedback_ever')) {
+                $is_correct =
+                    ($Apache::lonhomework::history{"resource.0.solved"} =~/^correct_/);
+            }
+            unless (($currtries == $maxtries) || ($is_correct)) {
+                $got_grade = 1;
+            }
+        }
     }
     
     &Apache::lonxml::debug(" slot is $slotstatus checkedin ($checkedin) got_grade ($got_grade) is_correct ($is_correct)");
@@ -384,15 +425,57 @@
                         &Apache::loncommon::get_future_slots($cnum,$cdom,$now,$symb);
                     if ((ref($reservable_now_order) eq 'ARRAY') && (ref($reservable_now) eq 'HASH')) {
                         if (@{$reservable_now_order} > 0) {
-                            $slotstatus = 'RESERVABLE';
-                            $datemsg = $reservable_now->{$reservable_now_order->[-1]}{'endreserve'};
+                            if ((!$checkedin) || (ref($consumed_uniq) ne 'ARRAY')) {
+                                $slotstatus = 'RESERVABLE';
+                                $datemsg = $reservable_now->{$reservable_now_order->[-1]}{'endreserve'};
+                            } else {
+                                my ($uniqstart,$uniqend,$useslot);
+                                if (ref($consumed_uniq) eq 'ARRAY') {
+                                    ($uniqstart,$uniqend)=@{$consumed_uniq};
+                                }
+                                foreach my $slot (reverse(@{$reservable_now_order})) {
+                                    if ($reservable_now->{$slot}{'uniqueperiod'} =~ /^(\d+)\,(\d+)$/) {
+                                        my ($new_uniq_start,$new_uniq_end) = ($1,$2);
+                                        next if (!
+                                            ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
+                                            ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
+                                    }
+                                    $useslot = $slot;
+                                    last;
+                                }
+                                if ($useslot) {
+                                    $slotstatus = 'RESERVABLE';
+                                    $datemsg = $reservable_now->{$useslot}{'endreserve'};
+                                }
+                            }
                         }
                     }
                     unless ($slotstatus eq 'RESERVABLE') {
                         if ((ref($reservable_future_order) eq 'ARRAY') && (ref($reservable_future) eq 'HASH')) {
                             if (@{$reservable_future_order} > 0) {
-                                $slotstatus = 'RESERVABLE_LATER';
-                                $datemsg = $reservable_future->{$reservable_future_order->[0]}{'startreserve'};
+                                if ((!$checkedin) || (ref($consumed_uniq) ne 'ARRAY')) {
+                                    $slotstatus = 'RESERVABLE_LATER';
+                                    $datemsg = $reservable_future->{$reservable_future_order->[0]}{'startreserve'};
+                                } else {
+                                    my ($uniqstart,$uniqend,$useslot);
+                                    if (ref($consumed_uniq) eq 'ARRAY') {
+                                        ($uniqstart,$uniqend)=@{$consumed_uniq};
+                                    }
+                                    foreach my $slot (@{$reservable_future_order}) {
+                                        if ($reservable_future->{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
+                                            my ($new_uniq_start,$new_uniq_end) = ($1,$2);
+                                            next if (!
+                                               ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
+                                               ($uniqstart > $new_uniq_end   &&  $uniqend > $new_uniq_end  ));
+                                        }
+                                        $useslot = $slot;
+                                        last;
+                                    }
+                                    if ($useslot) {
+                                        $slotstatus = 'RESERVABLE_LATER';
+                                        $datemsg = $reservable_future->{$useslot}{'startreserve'};
+                                    }
+                                }
                             }
                         }
                     }
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.116 rat/lonpage.pm:1.117
--- rat/lonpage.pm:1.116	Mon May 30 09:27:35 2016
+++ rat/lonpage.pm	Mon Jul 18 19:29:24 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Page Handler
 #
-# $Id: lonpage.pm,v 1.116 2016/05/30 09:27:35 raeburn Exp $
+# $Id: lonpage.pm,v 1.117 2016/07/18 19:29:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -479,7 +479,7 @@
                                               $type = 'Task';
                                           }
                                           my ($status,$accessmsg,$slot_name,$slot) =
-                                              &Apache::lonhomework::check_slot_access('0',$type,$symb,$pagesymb);
+                                              &Apache::lonhomework::check_slot_access('0',$type,$symb);
                                           undef(%Apache::lonhomework::history);
                                           my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
                                           if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') && 


More information about the LON-CAPA-cvs mailing list