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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 02 Oct 2003 20:48:57 -0000


matthew		Thu Oct  2 16:48:57 2003 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  Removed 'tries' from $fulldump_response_table as 'tries' only applies to
  parts, not responses.
  Added &get_optionresponse_data to retrieve option response data.  This
  routine is evolving, which is my excuse for not documenting it futher
  and continuing to log the MySQL request.
  Added paranoid call to &setup_table_names in &get_problem_statistics which
  is completely unneccessary and utterly benign.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.99 loncom/interface/loncoursedata.pm:1.100
--- loncom/interface/loncoursedata.pm:1.99	Thu Oct  2 13:07:41 2003
+++ loncom/interface/loncoursedata.pm	Thu Oct  2 16:48:57 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.99 2003/10/02 17:07:41 matthew Exp $
+# $Id: loncoursedata.pm,v 1.100 2003/10/02 20:48:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -711,9 +711,6 @@
                     { name => 'transaction',
                       type => 'MEDIUMINT UNSIGNED',
                       restrictions => 'NOT NULL' },
-                    { name => 'tries',
-                      type => 'SMALLINT UNSIGNED',
-                      restrictions => 'NOT NULL' },
                     { name => 'awarddetail',
                       type => 'TINYTEXT' },
 #                    { name => 'message',
@@ -1215,8 +1212,7 @@
             }
             # deal with response specific data
             if (defined($resp_id) &&
-                $field =~ /^(tries|
-                             awarddetail|
+                $field =~ /^(awarddetail|
                              submission|
                              submissiongrading|
                              molecule)$/x) {
@@ -1252,7 +1248,6 @@
                 $store_command .= "('".join("','",$symb_id,$part_id,
                                             $student_id,
                                             $transaction,
-                                            $data->{'tries'},
                                             $data->{'award'},
                                             $data->{'awarded'},
                                             $data->{'previous'})."'),";
@@ -1884,6 +1879,7 @@
     return if (! defined($symb) || ! defined($part));
     $courseid = $ENV{'request.course.id'} if (! defined($courseid));
     #
+    &setup_table_names($courseid);
     my $symb_id = &get_symb_id($symb);
     my $part_id = &get_part_id($part);
     my $stats_table = $courseid.'_problem_stats';
@@ -1990,6 +1986,46 @@
     return ();
 }
 
+sub get_optionresponse_data {
+    my ($students,$symb,$response,$courseid) = @_;
+    return if (! defined($symb) || 
+               ! defined($response));
+    $courseid = $ENV{'request.course.id'} if (! defined($courseid));
+    #
+    &setup_table_names($courseid);
+    my $symb_id = &get_symb_id($symb);
+    my $response_id = &get_part_id($response);
+    #
+    my $dbh = &Apache::lonmysql::get_dbh();
+    return undef if (! defined($dbh));
+    my $request = 'SELECT '.
+        'a.response_specific_value, a.submission, b.timestamp, c.tries '.
+        'FROM '.$fulldump_response_table.' AS a '.
+        'LEFT JOIN '.$fulldump_timestamp_table.' AS b '.
+        'ON a.symb_id=b.symb_id AND a.student_id=b.student_id AND '.
+        'a.transaction = b.transaction '.
+        'LEFT JOIN '.$fulldump_part_table.' AS c '.
+        'ON a.symb_id=c.symb_id AND a.student_id=c.student_id AND '.        
+        'a.part_id=c.part_id AND a.transaction = c.transaction '.
+        'WHERE '.
+        'a.symb_id='.$symb_id.' AND a.response_id='.$response_id;
+    if (defined($students)) {
+        $request .= ' AND ('.
+            join(' OR ', map {'student_id='.
+                                  &get_student_id($_->{'username'},
+                                                  $_->{'domain'})
+                              } @$students
+                 ).')';
+    }
+    $request .= ' ORDER BY b.timestamp';
+    &Apache::lonnet::logthis("request =\n".$request);
+    my $sth = $dbh->prepare($request);
+    $sth->execute();
+    my $dataset = $sth->fetchall_arrayref();
+    if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) {
+        return @$dataset;
+    }
+}
 
 ################################################
 ################################################