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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 23 Aug 2004 15:03:15 -0000


This is a MIME encoded message

--matthew1093273395
Content-Type: text/plain

matthew		Mon Aug 23 11:03:15 2004 EDT

  Modified files:              
    /loncom/interface	lontrackstudent.pm 
  Log:
  Color coding of output, modified query to not request ALL data.  Query and
  table structure needs a good deal more work....
  
  
--matthew1093273395
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040823110315.txt"

Index: loncom/interface/lontrackstudent.pm
diff -u loncom/interface/lontrackstudent.pm:1.3 loncom/interface/lontrackstudent.pm:1.4
--- loncom/interface/lontrackstudent.pm:1.3	Thu Aug 19 17:07:35 2004
+++ loncom/interface/lontrackstudent.pm	Mon Aug 23 11:03:15 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lontrackstudent.pm,v 1.3 2004/08/19 21:07:35 matthew Exp $
+# $Id: lontrackstudent.pm,v 1.4 2004/08/23 15:03:15 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -71,16 +71,18 @@
     my $activity_table = $prefix.'activity';
     #
     $query = qq{
-        select B.resource,A.time,C.student,D.action,E.machine,A.action_values 
+        SELECT B.resource,A.time,C.student,D.action,E.machine,A.action_values 
             FROM $activity_table AS A
-            LEFT JOIN $res_table AS B ON B.res_id=A.res_id 
+            LEFT JOIN $res_table      AS B ON B.res_id=A.res_id 
             LEFT JOIN $student_table  AS C ON C.student_id=A.student_id 
             LEFT JOIN $action_table   AS D ON D.action_id=A.action_id 
             LEFT JOIN $machine_table  AS E ON E.machine_id=A.machine_id
-            LIMIT 500
+            WHERE A.student_id>10
+            ORDER BY A.time ASC
+            LIMIT 5000
     };
     $query =~ s|$/||g;
-    # &Apache::lonnet::logthis($query);
+    &Apache::lonnet::logthis($query);
     ##
     ## Send it along
     my $reply=&Apache::lonnet::metadata_query($query,undef,undef,[$home]);
@@ -100,9 +102,10 @@
     my $maxtime = 500;
     my $starttime = time;
     while (! -e $endfile && (time-$starttime < $maxtime)) {
-        sleep(1);
         &Apache::lonhtmlcommon::Update_PrgWin
-            ($r,$prog_state,&mt('Waiting for results'));
+            ($r,$prog_state,&mt('Waiting up to [_1] seconds for results',
+                                $starttime+$maxtime-time));
+        sleep(1);
     }
     if (! -e $endfile) {
         $r->print('<h2>'.
@@ -112,10 +115,21 @@
     }
     &Apache::lonhtmlcommon::Update_PrgWin
         ($r,$prog_state,&mt('Parsing results'));
+    &output_results($r,$results_file,$navmap);
+    &Apache::lonhtmlcommon::Update_PrgWin
+        ($r,$prog_state,&mt('Finished!'));
+    return;
+}
+
+sub output_results {
+    my ($r,$results_file,$navmap) = @_;
     if (! open(ACTIVITYDATA,$results_file)) {
-        $r->print('<h2>'.
-                  &mt('Unable to read results file.  This is a serious error and has been logged.  You should contact your system administrator to resolve this issue.  If you are the system administrator, I feel sorry for you.').
-                  '</h2>');
+        $r->print('<h2>'.&mt('Unable to read results file.').'</h2>'.
+                  '<p>'.
+                  &mt('This is a serious error and has been logged.  '.
+                      'You should contact your system administrator '.
+                      'to resolve this issue.').
+                  '</p>');
         return;
     }
     my $tableheader = 
@@ -127,7 +141,7 @@
         '<th>'.&mt('Originating Server').'</th>'.
         '<th>'.&mt('Data').'</th>'.
         '</tr>'.$/;
-    my $count =0;
+    my $count = 0;
     $r->print($tableheader);
     $r->rflush();
     while (my $line = <ACTIVITYDATA>) {
@@ -140,34 +154,51 @@
         my ($symb,$timestamp,$student,$action,$machine,$values) =
             map { &Apache::lonnet::unescape($_); } split(',',$line,6);
         my ($title,$src);
-        if ($symb =~ m:^/(res|adm)/:) {
+        if ($symb =~ m:^/adm/:) {
             $title = $symb;
             $src = $symb;
+        } elsif ($symb eq '/prtspool/') {
+            $title = "Printout";
+            $src = undef;
         } else {
-            # We may need to add 'uploaded/' to the symb
-            # 
-            # Hey, guess what - navmaps->getBySymb 
-            # does not work with uploaded resources/new style courses/something
-            # The fact that our symbs do not have uploaded/ prepended to them
-            # then they (most often but not always) should, is likely to be
-            # a puzzle too.
-            #&Apache::lonnet::logthis('trackstudent:symb = '.$symb);
-            # my $nav_res = $navmap->getBySymb($symb);
-            $title = 'resource title goes here'; # $nav_res->title();
-            $src   = '/dev/null'; # $nav_res->src();
+            my $nav_res = $navmap->getBySymb($symb);
+            if (defined($nav_res)) {
+                $title = $nav_res->title();
+                $src   = $nav_res->src();
+            } else {
+                $title = 'unable to retrieve title';
+                $src   = '/dev/null';
+            }
         }
-        $r->print('<tr>'.
-                  '<td>'.'<a href="'.$src.'">'.$title.'</a>'.'</td>'.
+        my $class = '';
+        #
+        if ($symb eq '/printout/') {
+            $class = 'print';
+            $title = 'retrieve printout';
+        } elsif ($symb =~ m|^/adm/([^/]+)|) {
+            $class = $1;
+        } elsif ($symb =~ m|^/adm/|) {
+            $class = 'adm';
+        }
+        if ($title eq 'unable to retrieve title') {
+            $title =~ s/ /\&nbsp;/g;
+            $class = 'warning';
+        }
+        if (! defined($title) || $title eq '') {
+            $title = 'untitled';
+            $class = 'warning';
+        }
+        $r->print('<tr class="'.$class.'">'.
+                  '<td><a href="'.$src.'">'.$title.'</a>'.'</td>'.
                   '<td><nobr>'.$timestamp.'</nobr></td>'.
                   '<td>'.$student.'</td>'.
                   '<td>'.$action.'</td>'.
                   '<td>'.$machine.'</td>'.
-                  '<td>'.$values.'</td>'.'</tr>'.$/);
+                  '<td>'.($class?$symb:'').'</td>'.'</tr>'.$/);
+#                  '<td>'.$symb.'</td>'.'</tr>'.$/);
     }
     $r->print('</table>'.$/);
     close(ACTIVITYDATA);
-    &Apache::lonhtmlcommon::Update_PrgWin
-        ($r,$prog_state,&mt('Finished!'));
     return;
 }
 
@@ -190,6 +221,21 @@
 ###################################################################
 ###################################################################
 
+sub styles {
+    return <<END;
+<STYLE TYPE="text/css">
+    tr.warning   { background-color: red; }
+    tr.chat      { background-color: yellow; }
+    tr.chatfetch { background-color: yellow; }
+    tr.navmaps   { background-color: \#777777; }
+    tr.roles     { background-color: \#999999; }
+    tr.flip      { background-color: \#BBBBBB; }
+    tr.adm       { background-color: green; }
+    tr.print     { background-color: blue; }
+    tr.printout  { background-color: blue; }
+</STYLE>
+END
+}
 
 ###################################################################
 ###################################################################
@@ -241,7 +287,7 @@
                                             bug=>'instructor interface'});
     #
     # Give the LON-CAPA page header
-    $r->print('<html><head><title>'.
+    $r->print('<html><head>'.&styles.'<title>'.
               &mt('Student Activity').
               "</title></head>\n".
               &Apache::loncommon::bodytag('Student Activity').
@@ -267,21 +313,19 @@
     if (ref($result) eq 'HASH') {
         $result = join(' ',map { $_.'=>'.$result->{$_}; } keys(%$result));
     }
-    $r->print('<h2>'.$result.'</h2>');
+    &Apache::lonnet::logthis('result from request_data_update: '.$result);
     #
     if (! exists($ENV{'form.selected_student'})) {
-        # Choose a student
-        $r->print('If you worked here you would be done by now');
+        # For now, just show all the data, in the future allow selection of
+        # a student
+        &get_all_data($r,\%prog_state,$navmap);
     } else {
-        # Show a students activity
-        $r->print('I would like to have something to show you but I do not.');
+        # For now, just show all the data instead of limiting it to one student
+        &get_all_data($r,\%prog_state,$navmap);
     }
     #
-    &get_all_data($r,\%prog_state,$navmap);
-
-#    &Apache::lonhtmlcommon::Update_PrgWin
-#        ($r,\%prog_state,&mt('Done'));
-
+    &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Done'));
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
     #
     $r->print("</form>\n");
     $r->print("</body>\n</html>\n");

--matthew1093273395--