--- loncom/interface/loncoursedata.pm 2003/10/03 15:33:25 1.81.2.2 +++ loncom/interface/loncoursedata.pm 2003/09/24 15:14:41 1.87 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.81.2.2 2003/10/03 15:33:25 albertel Exp $ +# $Id: loncoursedata.pm,v 1.87 2003/09/24 15:14:41 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -104,8 +104,7 @@ sub get_sequence_assessment_data { my $fn=$ENV{'request.course.fn'}; ## ## use navmaps - my $navmap = Apache::lonnavmaps::navmap->new($fn.".db", - $fn."_parms.db",1,0); + my $navmap = Apache::lonnavmaps::navmap->new(); if (!defined($navmap)) { return 'Can not open Coursemap'; } @@ -159,6 +158,7 @@ sub get_sequence_assessment_data { } # get the map itself, instead of BEGIN_MAP $title = $previous->title(); + $title =~ s/\:/\&\#058;/g; $symb = $previous->symb(); $src = $previous->src(); # pick up the filename if there is no title available @@ -187,15 +187,22 @@ sub get_sequence_assessment_data { next if (! $curRes->is_problem());# && !$curRes->randomout); # Okay, from here on out we only deal with assessments $title = $curRes->title(); + $title =~ s/\:/\&\#058;/g; $symb = $curRes->symb(); $src = $curRes->src(); my $parts = $curRes->parts(); + my %partdata; + foreach my $part (@$parts) { + $partdata{$part}->{'ResponseTypes'}= $curRes->responseType($part); + $partdata{$part}->{'ResponseIds'} = $curRes->responseIds($part); + } my $assessment = { title => $title, src => $src, symb => $symb, type => 'assessment', parts => $parts, num_parts => scalar(@$parts), + partdata => \%partdata, }; push(@Assessments,$assessment); push(@{$currentmap->{'contents'}},$assessment); @@ -387,12 +394,12 @@ internally to the MySQL database and is (stored in the students environment). This table has its PRIMARY KEY on the 'student' (100 characters). -=item $updatetime_table +=item $studentdata_table -The updatetime_table has two columns. The first is 'student' (100 characters, -typically username:domain). The second is 'updatetime', which is an unsigned -integer, NOT a MySQL date. This table has its PRIMARY KEY on 'student' (100 -characters). +The studentdata_table has four columns. The first is 'student_id', the unique +id of the student. The second is the time the students data was last updated. +The third is the students section. The fourth is the students current +classification. This table has its PRIMARY KEY on 'student_id'. =item $performance_table @@ -450,7 +457,7 @@ my $current_course =''; my $symb_table; my $part_table; my $student_table; -my $updatetime_table; +my $studentdata_table; my $performance_table; my $parameters_table; @@ -478,7 +485,7 @@ sub init_dbs { # # Drop any of the existing tables foreach my $table ($symb_table,$part_table,$student_table, - $updatetime_table,$performance_table, + $studentdata_table,$performance_table, $parameters_table) { &Apache::lonmysql::drop_table($table); } @@ -525,22 +532,28 @@ sub init_dbs { { name => 'student', type => 'VARCHAR(100)', restrictions => 'NOT NULL'}, + { name => 'classification', + type => 'varchar(100)', }, ], 'PRIMARY KEY' => ['student (100)'], 'KEY' => [{ columns => ['student_id']},], }; # - my $updatetime_table_def = { - id => $updatetime_table, + my $studentdata_table_def = { + id => $studentdata_table, permanent => 'no', - columns => [{ name => 'student', - type => 'VARCHAR(100)', + columns => [{ name => 'student_id', + type => 'MEDIUMINT UNSIGNED', restrictions => 'NOT NULL UNIQUE',}, { name => 'updatetime', type => 'INT UNSIGNED', 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 = { @@ -617,9 +630,9 @@ sub init_dbs { return 3; } # - $tableid = &Apache::lonmysql::create_table($updatetime_table_def); + $tableid = &Apache::lonmysql::create_table($studentdata_table_def); if (! defined($tableid)) { - &Apache::lonnet::logthis("error creating updatetime_table: ". + &Apache::lonnet::logthis("error creating studentdata_table: ". &Apache::lonmysql::get_error()); return 4; } @@ -659,7 +672,7 @@ sub delete_caches { # my $dbh = &Apache::lonmysql::get_dbh(); foreach my $table ($symb_table,$part_table,$student_table, - $updatetime_table,$performance_table, + $studentdata_table,$performance_table, $parameters_table ){ my $command = 'DROP TABLE '.$table.';'; $dbh->do($command); @@ -842,7 +855,7 @@ sub get_student_id { $have_read_student_table = 1; } 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); my @Result = &Apache::lonmysql::get_rows($student_table); foreach (@Result) { @@ -872,36 +885,6 @@ sub get_student { =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() Input: $sname, $sdom, $courseid @@ -1027,6 +1010,8 @@ sub update_student_data { if ($dbh->err()) { &Apache::lonnet::logthis(' bigass insert error:'.$dbh->errstr()); &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'; return ($returnstatus,\%student_data); } @@ -1040,8 +1025,8 @@ sub update_student_data { $elapsed += Time::HiRes::time - $start; # # Set the students update time - &Apache::lonmysql::replace_row($updatetime_table, - [$student,$time_of_retrieval]); + &Apache::lonmysql::replace_row($studentdata_table, + [$student_id,$time_of_retrieval,undef,undef]); return ($returnstatus,\%student_data); } @@ -1057,7 +1042,7 @@ Input: $sname, $sdom, $courseid Output: $status, $data 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 date, &update_student_data() is called. The return values from the call to &update_student_data() are returned. @@ -1077,17 +1062,17 @@ sub ensure_current_data { # # if the tables do not exist, make them 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); foreach (@CurrentTable) { $found_symb = 1 if ($_ eq $symb_table); $found_student = 1 if ($_ eq $student_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_parameters = 1 if ($_ eq $parameters_table); } - if (!$found_symb || !$found_update || + if (!$found_symb || !$found_studentdata || !$found_student || !$found_part || !$found_performance || !$found_parameters) { if (&init_dbs($courseid)) { @@ -1101,9 +1086,9 @@ sub ensure_current_data { ($sdom,$sname,$courseid.'.db', $Apache::lonnet::perlvar{'lonUsersDir'}); # - my $student = $sname.':'.$sdom; - my @Result = &Apache::lonmysql::get_rows($updatetime_table, - "student ='$student'"); + my $student_id = &get_student_id($sname,$sdom); + my @Result = &Apache::lonmysql::get_rows($studentdata_table, + "student_id ='$student_id'"); my $data = undef; if (@Result) { $updatetime = $Result[0]->[1]; @@ -1195,33 +1180,6 @@ sub get_student_data_from_performance_ca $studentdata->{$symb}->{$base.'.awarddetail'} = $awarddetail; $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 '') { $studentdata = $studentdata->{$symb}; } @@ -1438,7 +1396,7 @@ sub get_problem_statistics { if ($num) { my %storestats=(); - my $urlres=(split(/\_\_\_/,$symb))[2]; + my $urlres=(&Apache::lonnet::decode_symb($symb))[2]; $storestats{$courseid.'___'.$urlres.'___timestamp'}=time; $storestats{$courseid.'___'.$urlres.'___stdno'}=$num; @@ -1519,7 +1477,7 @@ sub setup_table_names { $symb_table = $base_id.'_'.'symb'; $part_table = $base_id.'_'.'part'; $student_table = $base_id.'_'.'student'; - $updatetime_table = $base_id.'_'.'updatetime'; + $studentdata_table = $base_id.'_'.'studentdata'; $performance_table = $base_id.'_'.'performance'; $parameters_table = $base_id.'_'.'parameters'; return;