[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 07 Mar 2003 19:09:11 -0000


albertel		Fri Mar  7 14:09:11 2003 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  - pt in matthew minute/seconds code, change hash indices to be clearer
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.15 loncom/interface/lonhtmlcommon.pm:1.16
--- loncom/interface/lonhtmlcommon.pm:1.15	Mon Mar  3 17:00:03 2003
+++ loncom/interface/lonhtmlcommon.pm	Fri Mar  7 14:09:11 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.15 2003/03/03 22:00:03 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.16 2003/03/07 19:09:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -653,10 +653,10 @@
     "</script>");
 
     my %prog_state;
-    $prog_state{'now'}=0;
-    $prog_state{'since'}=time;
-    $prog_state{'started'}=time;
-    $prog_state{'total'}=$number_to_do;
+    $prog_state{'done'}=0;
+    $prog_state{'firststart'}=time;
+    $prog_state{'laststart'}=time;
+    $prog_state{'max'}=$number_to_do;
 
     $r->rflush();
     return %prog_state;
@@ -667,21 +667,35 @@
     my ($r,$prog_state,$displayString)=@_;
     $r->print('<script>popwin.document.popremain.remaining.value="'.
               $displayString.'";</script>');
-    $$prog_state{'started'}=time;
+    $$prog_state{'laststart'}=time;
     $r->rflush();
 }
 
 # increment progress state
 sub Increment_PrgWin {
     my ($r,$prog_state,$extraInfo)=@_;
-    $$prog_state{'now'}++;
+    $$prog_state{'done'}++;
+    my $time_est= (time - $$prog_state{'firststart'})/$$prog_state{'done'} *
+	($$prog_state{'max'}-$$prog_state{'done'});
+    $time_est = int($time_est);
+    if (int ($time_est/60) > 0) {
+	my $min = int($time_est/60);
+	my $sec = $time_est % 60;
+	$time_est = $min.' minutes';
+	if ($sec > 1) {
+	    $time_est.= ', '.$sec.' seconds';
+	} elsif ($sec > 0) {
+	    $time_est.= ', '.$sec.' second';
+	}
+    } else {
+	$time_est .= ' seconds';
+    }
+
     $r->print('<script>popwin.document.popremain.remaining.value="'.
-	      $$prog_state{'now'}.'/'.$$prog_state{'total'}.
-	      ': '.int((time-$$prog_state{'since'})/
-	      $$prog_state{'now'}*($$prog_state{'total'}-$$prog_state{'now'})).
-	      ' secs remaining ('.(time-$$prog_state{'started'}).
+	      $$prog_state{'done'}.'/'.$$prog_state{'max'}.
+	      ': '.$time_est.' remaining ('.(time-$$prog_state{'laststart'}).
 	      ' seconds for '.$extraInfo.')";'.'</script>');
-    $$prog_state{'started'}=time;
+    $$prog_state{'laststart'}=time;
     $r->rflush();
 }