--- loncom/interface/loncoursedata.pm 2003/03/20 19:58:37 1.59 +++ loncom/interface/loncoursedata.pm 2003/03/21 16:04:10 1.60 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.59 2003/03/20 19:58:37 matthew Exp $ +# $Id: loncoursedata.pm,v 1.60 2003/03/21 16:04:10 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1828,6 +1828,8 @@ sub init_dbs { type => 'TINYTEXT' }, { name => 'timestamp', type => 'INT UNSIGNED'}, + { name => 'weight', + type => 'INT UNSIGNED'}, ], 'PRIMARY KEY' => ['symb_id','student_id','part_id'], 'KEY' => [{ columns=>['student_id'] }, @@ -2107,14 +2109,14 @@ available the second time. CYA. sub update_student_data { my ($sname,$sdom,$courseid) = @_; # + # Set up database names + &setup_table_names($courseid); + # my $student_id = &get_student_id($sname,$sdom); my $student = $sname.':'.$sdom; # my $returnstatus = 'okay'; # - # Set up database names - &setup_table_names($courseid); - # # Download students data my $time_of_retrieval = time; my @tmp = &Apache::lonnet::currentdump($courseid,$sdom,$sname); @@ -2131,8 +2133,11 @@ sub update_student_data { my %student_data = @tmp; # # Remove all of the students data from the table - &Apache::lonmysql::remove_from_table($performance_table,'student_id', - $student_id); + my $dbh = &Apache::lonmysql::get_dbh(); + $dbh->do('DELETE FROM '.$performance_table.' WHERE student_id='. + $student_id); + $dbh->do('DELETE FROM '.$parameters_table.' WHERE student_id='. + $student_id); # # Store away the data # @@ -2140,10 +2145,9 @@ sub update_student_data { my $elapsed = 0; my $rows_stored; my $store_parameters_command = 'INSERT INTO '.$parameters_table. - ' VALUES '; + ' VALUES '."\n"; my $store_performance_command = 'INSERT INTO '.$performance_table. - ' VALUES '; - my $dbh = &Apache::lonmysql::get_dbh(); + ' VALUES '."\n"; return 'error' if (! defined($dbh)); while (my ($current_symb,$param_hash) = each(%student_data)) { # @@ -2156,7 +2160,7 @@ sub update_student_data { if ($parameter !~ /(timestamp|resource\.(.*)\.(solved|tries|awarded|award|awarddetail|previous))/) { $newstring = "('".join("','", $symb_id,$student_id, - $parameter,$value)."'),"; + $parameter,$value)."'),\n"; if ($newstring !~ /''/) { $store_parameters_command .= $newstring; $rows_stored++; @@ -2173,6 +2177,12 @@ sub update_student_data { my $award = $param_hash->{'resource.'.$part.'.award'}; my $awarddetail = $param_hash->{'resource.'.$part.'.awarddetail'}; my $timestamp = $param_hash->{'timestamp'}; + # use EXT to get the weight + my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight', + $current_symb,$sdom,$sname); + # Give the weight back to the user + $param_hash->{'resource.'.$part.'.weight'}=$weight; + # $solved = '' if (! defined($awarded)); $tries = '' if (! defined($tries)); $awarded = '' if (! defined($awarded)); @@ -2180,12 +2190,14 @@ sub update_student_data { $awarddetail = '' if (! defined($awarddetail)); $newstring = "('".join("','",$symb_id,$student_id,$part_id, $solved,$tries,$awarded,$award, - $awarddetail,$timestamp)."'),"; + $awarddetail,$timestamp,$weight)."'),\n"; $store_performance_command .= $newstring; $rows_stored++; } } chop $store_parameters_command; + chop $store_parameters_command; + chop $store_performance_command; chop $store_performance_command; my $start = Time::HiRes::time; $dbh->do($store_parameters_command); @@ -2259,7 +2271,9 @@ sub ensure_current_data { # # Get the update time for the user my $updatetime = 0; - my $modifiedtime = 1; + my $modifiedtime = &Apache::lonnet::GetFileTimestamp + ($sdom,$sname,$courseid.'.db', + $Apache::lonnet::perlvar{'lonUsersDir'}); # my $student = $sname.':'.$sdom; my @Result = &Apache::lonmysql::get_rows($updatetime_table, @@ -2316,7 +2330,7 @@ sub get_student_data_from_performance_ca my $dbh = &Apache::lonmysql::get_dbh(); my $request = "SELECT ". "d.symb,c.part,a.solved,a.tries,a.awarded,a.award,a.awarddetail,". - "a.timestamp "; + "a.timestamp,a.weight "; if (defined($student)) { $request .= "FROM $student_table AS b ". "LEFT JOIN $performance_table AS a ON b.student_id=a.student_id ". @@ -2345,7 +2359,7 @@ sub get_student_data_from_performance_ca } foreach my $row (@{$sth->fetchall_arrayref}) { $rows_retrieved++; - my ($symb,$part,$solved,$tries,$awarded,$award,$awarddetail,$time) = + my ($symb,$part,$solved,$tries,$awarded,$award,$awarddetail,$time,$weight) = (@$row); my $base = 'resource.'.$part; $studentdata->{$symb}->{$base.'.solved'} = $solved; @@ -2354,6 +2368,7 @@ sub get_student_data_from_performance_ca $studentdata->{$symb}->{$base.'.award'} = $award; $studentdata->{$symb}->{$base.'.awarddetail'} = $awarddetail; $studentdata->{$symb}->{'timestamp'} = $time if (defined($time) && $time ne ''); + $studentdata->{$symb}->{'resource.'.$part.'.weight'}=$weight; } return $studentdata; } @@ -2495,7 +2510,10 @@ sub get_classlist { # my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); while (my ($student,$info) = each(%classlist)) { - return undef if ($student =~ /^(con_lost|error|no_such_host)/i); + if ($student =~ /^(con_lost|error|no_such_host)/i) { + &Apache::lonnet::logthis('get_classlist error for '.$cid.':'.$student); + return undef; + } my ($sname,$sdom) = split(/:/,$student); my @Values = split(/:/,$info); my ($end,$start,$id,$section,$fullname);