[LON-CAPA-cvs] cvs: loncom /interface/statistics lonstathelpers.pm lonsubmissiontimeanalysis.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 28 Feb 2005 20:16:03 -0000


This is a MIME encoded message

--matthew1109621763
Content-Type: text/plain

matthew		Mon Feb 28 15:16:03 2005 EDT

  Modified files:              
    /loncom/interface/statistics	lonstathelpers.pm 
                                	lonsubmissiontimeanalysis.pm 
  Log:
  Continue switch to navmaps.
  lonstathelpers: &render_resource now expects navmaps resource
      renamed ProblemSelector to problem_selector and refactored it to use
      navmaps.
      refactored get_prev_curr_next to use navmaps AND modified it to return
      the navmap object.
  lonsubmissiontimeanalysis: refactored to use navmaps and to pass new 
      parameters to loncoursedata::get_response_time_data
  
  
--matthew1109621763
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20050228151603.txt"

Index: loncom/interface/statistics/lonstathelpers.pm
diff -u loncom/interface/statistics/lonstathelpers.pm:1.39 loncom/interface/statistics/lonstathelpers.pm:1.40
--- loncom/interface/statistics/lonstathelpers.pm:1.39	Wed Feb 23 18:51:18 2005
+++ loncom/interface/statistics/lonstathelpers.pm	Mon Feb 28 15:16:03 2005
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstathelpers.pm,v 1.39 2005/02/23 23:51:18 matthew Exp $
+# $Id: lonstathelpers.pm,v 1.40 2005/02/28 20:16:03 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -85,8 +85,8 @@
     my $base;
     ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
     $base = "http://".$ENV{'SERVER_NAME'}.$base;
-    my $rendered_problem = 
-        &Apache::lonnet::ssi_body($resource->{'src'}.'?symb='.&Apache::lonnet::escape($resource->{'symb'}));
+    my ($src,$symb)=($resource->src,&Apache::lonnet::escape($resource->symb));
+    my $rendered_problem = &Apache::lonnet::ssi_body($src.'?symb='.$symb);
     $rendered_problem =~ s/<\s*form\s*/<nop /g;
     $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
     return '<table bgcolor="ffffff"><tr><td>'.
@@ -100,7 +100,26 @@
 
 =pod
 
-=item &ProblemSelector($AcceptedResponseTypes)
+=item &get_resources
+
+=cut
+
+####################################################
+####################################################
+sub get_resources {
+    my ($navmap,$sequence) = @_;
+    my @resources = $navmap->retrieveResources($sequence,
+                                               sub { shift->is_problem(); },
+                                               0,0,0);
+    return @resources;
+}
+
+####################################################
+####################################################
+
+=pod
+
+=item &problem_selector($AcceptedResponseTypes)
 
 Input: scalar containing regular expression which matches response
 types to show.  '.' will yield all, '(option|radiobutton)' will match
@@ -114,23 +133,25 @@
 
 ####################################################
 ####################################################
-sub ProblemSelector {
+sub problem_selector {
     my ($AcceptedResponseTypes) = @_;
     my $Str;
     $Str = "\n<table>\n";
     my $rb_count =0;
-    foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess('all')) {
-        next if ($seq->{'num_assess'}<1);
+    my ($navmap,@sequences) = 
+        &Apache::lonstatistics::selected_sequences_with_assessments('all');
+    return $navmap if (! ref($navmap)); # error
+    foreach my $seq (@sequences) {
         my $seq_str = '';
-        foreach my $res (@{$seq->{'contents'}}) {
-            next if ($res->{'type'} ne 'assessment');
-            foreach my $part (@{$res->{'parts'}}) {
-                my $partdata = $res->{'partdata'}->{$part};
-                for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
-                    my $respid = $partdata->{'ResponseIds'}->[$i];
-                    my $resptype = $partdata->{'ResponseTypes'}->[$i];
+        foreach my $res (&get_resources($navmap,$seq)) {
+            foreach my $part (@{$res->parts}) {
+                my @response_ids   = $res->responseIds($part);
+                my @response_types = $res->responseType($part);
+                for (my $i=0;$i<scalar(@response_types);$i++){
+                    my $respid = $response_ids[$i];
+                    my $resptype = $response_types[$i];
                     if ($resptype =~ m/$AcceptedResponseTypes/) {
-                        my $value = &make_target_id({symb=>$res->{'symb'},
+                        my $value = &make_target_id({symb=>$res->symb,
                                                      part=>$part,
                                                      respid=>$respid,
                                                      resptype=>$resptype});
@@ -138,19 +159,19 @@
                         if ($ENV{'form.problemchoice'} eq $value) {
                             $checked = 'checked ';
                         }
-                        my $title = $res->{'title'};
+                        my $title = $res->compTitle;
                         if (! defined($title) || $title eq '') {
-                            ($title) = ($res->{'src'} =~ m:/([^/]*)$:);
+                            ($title) = ($res->src =~ m:/([^/]*)$:);
                         }
                         $seq_str .= '<tr>'.
                             qq{<td><input type="radio" id="$rb_count" name="problemchoice" value="$value" $checked /></td>}.
                             '<td><label for="'.$rb_count.'">'.$resptype.'</label></td>'.
                             '<td><label for="'.$rb_count.'">'.$title.'</label>';
-                        if (scalar(@{$partdata->{'ResponseIds'}}) > 1) {
+                        if (scalar(@response_ids) > 1) {
                             $seq_str .= &mt('response').' '.$respid;
                         }
                         my $link = $res->{'src'}.'?symb='.
-                            &Apache::lonnet::escape($res->{'symb'});
+                            &Apache::lonnet::escape($res->symb);
                         $seq_str .= ('&nbsp;'x2).
                             qq{<a target="preview" href="$link">view</a>};
                         $seq_str .= "</td></tr>\n";
@@ -160,7 +181,7 @@
             }
         }
         if ($seq_str ne '') {
-            $Str .= '<tr><td>&nbsp</td><td colspan="2"><b>'.$seq->{'title'}.'</b></td>'.
+            $Str .= '<tr><td>&nbsp</td><td colspan="2"><b>'.$seq->compTitle.'</b></td>'.
                 "</tr>\n".$seq_str;
         }
     }
@@ -433,36 +454,40 @@
     #
     # Build an array with the data we need to search through
     my @Resource;
-    foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess('all')) {
-        foreach my $res (@{$seq->{'contents'}}) {
-            next if ($res->{'type'} ne 'assessment');
-            foreach my $part (@{$res->{'parts'}}) {
-                my $partdata = $res->{'partdata'}->{$part};
-                if ($partdata->{'Survey'} && ($granularity eq 'part_survey')){
+    my ($navmap,@sequences) = 
+        &Apache::lonstatistics::selected_sequences_with_assessments('all');
+    return $navmap if (! ref($navmap));
+    foreach my $seq (@sequences) {
+        my @resources = &get_resources($navmap,$seq);
+        foreach my $res (@resources) {
+            foreach my $part (@{$res->parts}) {
+                if ($res->is_survey($part) && ($granularity eq 'part_survey')){
                     push (@Resource,
-                          { symb     => $res->{symb},
+                          { symb     => $res->symb,
                             part     => $part,
                             resource => $res,
                         } );
                 } elsif ($granularity eq 'part') {
                     push (@Resource,
-                          { symb     => $res->{symb},
+                          { symb     => $res->symb,
                             part     => $part,
                             resource => $res,
                         } );
                 } elsif ($granularity eq 'response') {
+                    my @response_ids   = $res->responseIds($part);
+                    my @response_types = $res->responseType($part);
                     for (my $i=0;
-                         $i<scalar(@{$partdata->{'ResponseTypes'}});
+                         $i<scalar(@response_ids);
                          $i++){
-                        my $respid = $partdata->{'ResponseIds'}->[$i];
-                        my $resptype = $partdata->{'ResponseTypes'}->[$i];
+                        my $respid   = $response_ids[$i];
+                        my $resptype = $response_types[$i];
                         next if ($resptype !~ m/$AcceptableResponseTypes/);
                         push (@Resource,
-                              { symb     => $res->{symb},
+                              { symb     => $res->symb,
                                 part     => $part,
-                                respid   => $partdata->{'ResponseIds'}->[$i],
+                                respid   => $respid,
+                                resptype => $resptype,
                                 resource => $res,
-                                resptype => $resptype
                                 } );
                     }
                 }
@@ -520,7 +545,7 @@
         $curr = $Resource[$curr_idx  ];
         $next = $Resource[$curr_idx+1];
     }
-    return ($prev,$curr,$next);
+    return ($navmap,$prev,$curr,$next);
 }
 
 
@@ -1331,6 +1356,9 @@
         if (defined($update_message)) {
             $r->print($update_message);
         }
+        if (0) {
+            &Apache::lonnet::logthis('Updating mysql student data caches');
+        }
         &gather_full_student_data($r,$formname,$inputname);
     }
     #
Index: loncom/interface/statistics/lonsubmissiontimeanalysis.pm
diff -u loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.17 loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.18
--- loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.17	Tue Jul  6 12:01:48 2004
+++ loncom/interface/statistics/lonsubmissiontimeanalysis.pm	Mon Feb 28 15:16:03 2005
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonsubmissiontimeanalysis.pm,v 1.17 2004/07/06 16:01:48 matthew Exp $
+# $Id: lonsubmissiontimeanalysis.pm,v 1.18 2005/02/28 20:16:03 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -85,7 +85,7 @@
                   &mt('Graph Problem Submission Times').'" />');
         $r->print('&nbsp;'x5);
         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
-        $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
+        $r->print(&Apache::lonstathelpers::problem_selector('.'));
     } else {
         foreach my $button (@SubmitButtons) {
             $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
@@ -101,7 +101,7 @@
         my $current_problem = &Apache::lonstathelpers::get_target_from_id
             ($ENV{'form.problemchoice'});
         #
-        my ($prev,$curr,$next) = 
+        my ($navmap,$prev,$curr,$next) = 
             &Apache::lonstathelpers::get_prev_curr_next($current_problem,
                                                         '.',
                                                         'part');
@@ -126,13 +126,13 @@
         if (! defined($resource)) {
             $r->print('resource is undefined');
         } else {
-            $r->print('<h1>'.$resource->{'title'}.'</h1>');
-            $r->print('<h3>'.$resource->{'src'}.'</h3>');
+            $r->print('<h1>'.$resource->compTitle.'</h1>');
+            $r->print('<h3>'.$resource->src.'</h3>');
             $r->rflush();
             $r->print(&Apache::lonstathelpers::render_resource($resource));
             $r->print('<br />');
             $r->rflush();
-            $r->print(&analyze_times($r,$resource,\@Students,
+            $r->print(&analyze_times($r,$resource->symb,\@Students,
                                      $current_problem->{'part'}));
         }
         $r->print('<hr />');
@@ -158,7 +158,7 @@
 }
 
 sub analyze_times {
-    my ($r,$resource,$students,$part) = @_;
+    my ($r,$symb,$students,$part) = @_;
     my $htmltable;
     #
     # Convenience arrays
@@ -170,9 +170,11 @@
     my $html; # holds results of analysis
     # Get the data
     my $SubData = &Apache::loncoursedata::get_response_time_data
-        ($students,$resource->{'symb'},$part);
+        (\@Apache::lonstatistics::SelectedSections,
+         $Apache::lonstatistics::enrollment_status,
+         $symb,$part);
     if (! defined($SubData) || ! ref($SubData)) {
-        $html.= '<h2>There is no submission data for this problem</h2>';
+        $html.= '<h2>There is no submission data for this problem at all</h2>';
         return $html;
     }
     my $NumSub = scalar(@{$SubData});

--matthew1109621763--