Diff for /loncom/interface/loncoursedata.pm between versions 1.81.2.2 and 1.88

version 1.81.2.2, 2003/10/03 15:33:25 version 1.88, 2003/09/24 18:01:01
Line 104  sub get_sequence_assessment_data { Line 104  sub get_sequence_assessment_data {
     my $fn=$ENV{'request.course.fn'};      my $fn=$ENV{'request.course.fn'};
     ##      ##
     ## use navmaps      ## use navmaps
     my $navmap = Apache::lonnavmaps::navmap->new($fn.".db",      my $navmap = Apache::lonnavmaps::navmap->new();
                                                  $fn."_parms.db",1,0);  
     if (!defined($navmap)) {      if (!defined($navmap)) {
         return 'Can not open Coursemap';          return 'Can not open Coursemap';
     }      }
Line 159  sub get_sequence_assessment_data { Line 158  sub get_sequence_assessment_data {
             }              }
             # get the map itself, instead of BEGIN_MAP              # get the map itself, instead of BEGIN_MAP
             $title = $previous->title();              $title = $previous->title();
               $title =~ s/\:/\&\#058;/g;
             $symb  = $previous->symb();              $symb  = $previous->symb();
             $src   = $previous->src();              $src   = $previous->src();
             # pick up the filename if there is no title available              # pick up the filename if there is no title available
Line 187  sub get_sequence_assessment_data { Line 187  sub get_sequence_assessment_data {
         next if (! $curRes->is_problem());# && !$curRes->randomout);          next if (! $curRes->is_problem());# && !$curRes->randomout);
         # Okay, from here on out we only deal with assessments          # Okay, from here on out we only deal with assessments
         $title = $curRes->title();          $title = $curRes->title();
           $title =~ s/\:/\&\#058;/g;
         $symb  = $curRes->symb();          $symb  = $curRes->symb();
         $src   = $curRes->src();          $src   = $curRes->src();
         my $parts = $curRes->parts();          my $parts = $curRes->parts();
           my %partdata;
           foreach my $part (@$parts) {
               my @Responses = $curRes->responseType($part);
               my @Ids       = $curRes->responseIds($part);
               $partdata{$part}->{'ResponseTypes'}= \@Responses;
               $partdata{$part}->{'ResponseIds'}  = \@Ids;
           }
         my $assessment = { title => $title,          my $assessment = { title => $title,
                            src   => $src,                             src   => $src,
                            symb  => $symb,                             symb  => $symb,
                            type  => 'assessment',                             type  => 'assessment',
                            parts => $parts,                             parts => $parts,
                            num_parts => scalar(@$parts),                             num_parts => scalar(@$parts),
                              partdata => \%partdata,
                        };                         };
         push(@Assessments,$assessment);          push(@Assessments,$assessment);
         push(@{$currentmap->{'contents'}},$assessment);          push(@{$currentmap->{'contents'}},$assessment);
Line 387  internally to the MySQL database and is Line 396  internally to the MySQL database and is
 (stored in the students environment).  This table has its PRIMARY KEY on the  (stored in the students environment).  This table has its PRIMARY KEY on the
 'student' (100 characters).  'student' (100 characters).
   
 =item $updatetime_table  =item $studentdata_table
   
 The updatetime_table has two columns.  The first is 'student' (100 characters,  The studentdata_table has four columns.  The first is 'student_id', the unique
 typically username:domain).  The second is 'updatetime', which is an unsigned  id of the student.  The second is the time the students data was last updated.
 integer, NOT a MySQL date.  This table has its PRIMARY KEY on 'student' (100  The third is the students section.  The fourth is the students current
 characters).  classification.  This table has its PRIMARY KEY on 'student_id'.
   
 =item $performance_table  =item $performance_table
   
Line 450  my $current_course =''; Line 459  my $current_course ='';
 my $symb_table;  my $symb_table;
 my $part_table;  my $part_table;
 my $student_table;  my $student_table;
 my $updatetime_table;  my $studentdata_table;
 my $performance_table;  my $performance_table;
 my $parameters_table;  my $parameters_table;
   
Line 478  sub init_dbs { Line 487  sub init_dbs {
     #      #
     # Drop any of the existing tables      # Drop any of the existing tables
     foreach my $table ($symb_table,$part_table,$student_table,      foreach my $table ($symb_table,$part_table,$student_table,
                        $updatetime_table,$performance_table,                         $studentdata_table,$performance_table,
                        $parameters_table) {                         $parameters_table) {
         &Apache::lonmysql::drop_table($table);          &Apache::lonmysql::drop_table($table);
     }      }
Line 525  sub init_dbs { Line 534  sub init_dbs {
                     { name => 'student',                      { name => 'student',
                       type => 'VARCHAR(100)',                        type => 'VARCHAR(100)',
                       restrictions => 'NOT NULL'},                        restrictions => 'NOT NULL'},
                       { name => 'classification',
                         type => 'varchar(100)', },
                     ],                      ],
         'PRIMARY KEY' => ['student (100)'],          'PRIMARY KEY' => ['student (100)'],
         'KEY' => [{ columns => ['student_id']},],          'KEY' => [{ columns => ['student_id']},],
     };      };
     #      #
     my $updatetime_table_def = {      my $studentdata_table_def = {
         id => $updatetime_table,          id => $studentdata_table,
         permanent => 'no',          permanent => 'no',
         columns => [{ name => 'student',          columns => [{ name => 'student_id',
                       type => 'VARCHAR(100)',                        type => 'MEDIUMINT UNSIGNED',
                       restrictions => 'NOT NULL UNIQUE',},                        restrictions => 'NOT NULL UNIQUE',},
                     { name => 'updatetime',                      { name => 'updatetime',
                       type => 'INT UNSIGNED',                        type => 'INT UNSIGNED',
                       restrictions => 'NOT NULL' },                        restrictions => 'NOT NULL' },
                       { name => 'section',
                         type => 'VARCHAR(100)'},
                       { name => 'classification',
                         type => 'VARCHAR(100)', },
                     ],                      ],
         'PRIMARY KEY' => ['student (100)'],          'PRIMARY KEY' => ['student_id'],
     };      };
     #      #
     my $performance_table_def = {      my $performance_table_def = {
Line 617  sub init_dbs { Line 632  sub init_dbs {
         return 3;          return 3;
     }      }
     #      #
     $tableid = &Apache::lonmysql::create_table($updatetime_table_def);      $tableid = &Apache::lonmysql::create_table($studentdata_table_def);
     if (! defined($tableid)) {      if (! defined($tableid)) {
         &Apache::lonnet::logthis("error creating updatetime_table: ".          &Apache::lonnet::logthis("error creating studentdata_table: ".
                                  &Apache::lonmysql::get_error());                                   &Apache::lonmysql::get_error());
         return 4;          return 4;
     }      }
Line 659  sub delete_caches { Line 674  sub delete_caches {
     #      #
     my $dbh = &Apache::lonmysql::get_dbh();      my $dbh = &Apache::lonmysql::get_dbh();
     foreach my $table ($symb_table,$part_table,$student_table,      foreach my $table ($symb_table,$part_table,$student_table,
                        $updatetime_table,$performance_table,                         $studentdata_table,$performance_table,
                        $parameters_table ){                         $parameters_table ){
         my $command = 'DROP TABLE '.$table.';';          my $command = 'DROP TABLE '.$table.';';
         $dbh->do($command);          $dbh->do($command);
Line 842  sub get_student_id { Line 857  sub get_student_id {
         $have_read_student_table = 1;          $have_read_student_table = 1;
     }      }
     if (! exists($ids_by_student{$student})) {      if (! exists($ids_by_student{$student})) {
         &Apache::lonmysql::store_row($student_table,[undef,$student]);          &Apache::lonmysql::store_row($student_table,[undef,$student,undef]);
         undef(%ids_by_student);          undef(%ids_by_student);
         my @Result = &Apache::lonmysql::get_rows($student_table);          my @Result = &Apache::lonmysql::get_rows($student_table);
         foreach (@Result) {          foreach (@Result) {
Line 872  sub get_student { Line 887  sub get_student {
   
 =pod  =pod
   
 =item &clear_internal_caches()  
   
 Causes the internal caches used in get_student_id, get_student,  
 get_symb_id, get_symb, get_part_id, and get_part to be undef'd.  
   
 Needs to be called before the first operation with the MySQL database  
 for a given Apache request.  
   
 =cut  
   
 ################################################  
 ################################################  
 sub clear_internal_caches {  
     $have_read_part_table = 0;  
     undef(%ids_by_part);  
     undef(%parts_by_id);  
     $have_read_symb_table = 0;  
     undef(%ids_by_symb);  
     undef(%symbs_by_id);  
     $have_read_student_table = 0;  
     undef(%ids_by_student);  
     undef(%students_by_id);  
 }  
   
   
 ################################################  
 ################################################  
   
 =pod  
   
 =item &update_student_data()  =item &update_student_data()
   
 Input: $sname, $sdom, $courseid  Input: $sname, $sdom, $courseid
Line 1027  sub update_student_data { Line 1012  sub update_student_data {
     if ($dbh->err()) {      if ($dbh->err()) {
         &Apache::lonnet::logthis(' bigass insert error:'.$dbh->errstr());          &Apache::lonnet::logthis(' bigass insert error:'.$dbh->errstr());
         &Apache::lonnet::logthis('command = '.$store_parameters_command);          &Apache::lonnet::logthis('command = '.$store_parameters_command);
           &Apache::lonnet::logthis('rows_stored = '.$rows_stored);
           &Apache::lonnet::logthis('student_id = '.$student_id);
         $returnstatus = 'error: unable to insert parameters into database';          $returnstatus = 'error: unable to insert parameters into database';
         return ($returnstatus,\%student_data);          return ($returnstatus,\%student_data);
     }      }
Line 1040  sub update_student_data { Line 1027  sub update_student_data {
     $elapsed += Time::HiRes::time - $start;      $elapsed += Time::HiRes::time - $start;
     #      #
     # Set the students update time      # Set the students update time
     &Apache::lonmysql::replace_row($updatetime_table,      &Apache::lonmysql::replace_row($studentdata_table,
                                    [$student,$time_of_retrieval]);                                     [$student_id,$time_of_retrieval,undef,undef]);
     return ($returnstatus,\%student_data);      return ($returnstatus,\%student_data);
 }  }
   
Line 1057  Input: $sname, $sdom, $courseid Line 1044  Input: $sname, $sdom, $courseid
 Output: $status, $data  Output: $status, $data
   
 This routine ensures the data for a given student is up to date.  It calls  This routine ensures the data for a given student is up to date.  It calls
 &init_dbs() if the tables do not exist.  The $updatetime_table is queried  &init_dbs() if the tables do not exist.  The $studentdata_table is queried
 to determine the time of the last update.  If the students data is out of  to determine the time of the last update.  If the students data is out of
 date, &update_student_data() is called.  The return values from the call  date, &update_student_data() is called.  The return values from the call
 to &update_student_data() are returned.  to &update_student_data() are returned.
Line 1077  sub ensure_current_data { Line 1064  sub ensure_current_data {
     #      #
     # if the tables do not exist, make them      # if the tables do not exist, make them
     my @CurrentTable = &Apache::lonmysql::tables_in_db();      my @CurrentTable = &Apache::lonmysql::tables_in_db();
     my ($found_symb,$found_student,$found_part,$found_update,      my ($found_symb,$found_student,$found_part,$found_studentdata,
         $found_performance,$found_parameters);          $found_performance,$found_parameters);
     foreach (@CurrentTable) {      foreach (@CurrentTable) {
         $found_symb        = 1 if ($_ eq $symb_table);          $found_symb        = 1 if ($_ eq $symb_table);
         $found_student     = 1 if ($_ eq $student_table);          $found_student     = 1 if ($_ eq $student_table);
         $found_part        = 1 if ($_ eq $part_table);          $found_part        = 1 if ($_ eq $part_table);
         $found_update      = 1 if ($_ eq $updatetime_table);          $found_studentdata = 1 if ($_ eq $studentdata_table);
         $found_performance = 1 if ($_ eq $performance_table);          $found_performance = 1 if ($_ eq $performance_table);
         $found_parameters  = 1 if ($_ eq $parameters_table);          $found_parameters  = 1 if ($_ eq $parameters_table);
     }      }
     if (!$found_symb        || !$found_update ||       if (!$found_symb        || !$found_studentdata || 
         !$found_student     || !$found_part   ||          !$found_student     || !$found_part   ||
         !$found_performance || !$found_parameters) {          !$found_performance || !$found_parameters) {
         if (&init_dbs($courseid)) {          if (&init_dbs($courseid)) {
Line 1101  sub ensure_current_data { Line 1088  sub ensure_current_data {
         ($sdom,$sname,$courseid.'.db',          ($sdom,$sname,$courseid.'.db',
          $Apache::lonnet::perlvar{'lonUsersDir'});           $Apache::lonnet::perlvar{'lonUsersDir'});
     #      #
     my $student = $sname.':'.$sdom;      my $student_id = &get_student_id($sname,$sdom);
     my @Result = &Apache::lonmysql::get_rows($updatetime_table,      my @Result = &Apache::lonmysql::get_rows($studentdata_table,
                                              "student ='$student'");                                               "student_id ='$student_id'");
     my $data = undef;      my $data = undef;
     if (@Result) {      if (@Result) {
         $updatetime = $Result[0]->[1];          $updatetime = $Result[0]->[1];
Line 1195  sub get_student_data_from_performance_ca Line 1182  sub get_student_data_from_performance_ca
         $studentdata->{$symb}->{$base.'.awarddetail'} = $awarddetail;          $studentdata->{$symb}->{$base.'.awarddetail'} = $awarddetail;
         $studentdata->{$symb}->{'timestamp'} = $time if (defined($time) && $time ne '');          $studentdata->{$symb}->{'timestamp'} = $time if (defined($time) && $time ne '');
     }      }
     ## Get misc parameters  
     $request = 'SELECT c.symb,a.parameter,a.value '.  
         "FROM $student_table AS b ".  
         "LEFT JOIN $parameters_table AS a ON b.student_id=a.student_id ".  
         "LEFT JOIN $symb_table AS c ON c.symb_id = a.symb_id ".  
         "WHERE student='$student'";  
     if (defined($symb) && $symb ne '') {  
         $request .= " AND c.symb=".$dbh->quote($symb);  
     }  
     $sth = $dbh->prepare($request);  
     $sth->execute();  
     if ($sth->err()) {  
         &Apache::lonnet::logthis("Unable to execute MySQL request:");  
         &Apache::lonnet::logthis("\n".$request."\n");  
         &Apache::lonnet::logthis("error is:".$sth->errstr());  
         if (defined($symb) && $symb ne '') {  
             $studentdata = $studentdata->{$symb};  
         }  
         return $studentdata;  
     }  
     #  
     foreach my $row (@{$sth->fetchall_arrayref}) {  
         $rows_retrieved++;  
         my ($symb,$parameter,$value) = (@$row);  
         $studentdata->{$symb}->{$parameter}  = $value;  
     }  
     #  
     if (defined($symb) && $symb ne '') {      if (defined($symb) && $symb ne '') {
         $studentdata = $studentdata->{$symb};          $studentdata = $studentdata->{$symb};
     }      }
Line 1438  sub get_problem_statistics { Line 1398  sub get_problem_statistics {
     if ($num) {      if ($num) {
  my %storestats=();   my %storestats=();
   
         my $urlres=(split(/\_\_\_/,$symb))[2];          my $urlres=(&Apache::lonnet::decode_symb($symb))[2];
   
  $storestats{$courseid.'___'.$urlres.'___timestamp'}=time;          $storestats{$courseid.'___'.$urlres.'___timestamp'}=time;       
  $storestats{$courseid.'___'.$urlres.'___stdno'}=$num;   $storestats{$courseid.'___'.$urlres.'___stdno'}=$num;
Line 1519  sub setup_table_names { Line 1479  sub setup_table_names {
     $symb_table        = $base_id.'_'.'symb';      $symb_table        = $base_id.'_'.'symb';
     $part_table        = $base_id.'_'.'part';      $part_table        = $base_id.'_'.'part';
     $student_table     = $base_id.'_'.'student';      $student_table     = $base_id.'_'.'student';
     $updatetime_table  = $base_id.'_'.'updatetime';      $studentdata_table = $base_id.'_'.'studentdata';
     $performance_table = $base_id.'_'.'performance';      $performance_table = $base_id.'_'.'performance';
     $parameters_table  = $base_id.'_'.'parameters';      $parameters_table  = $base_id.'_'.'parameters';
     return;      return;

Removed from v.1.81.2.2  
changed lines
  Added in v.1.88


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>