--- loncom/interface/loncoursedata.pm 2004/02/02 21:45:12 1.114 +++ loncom/interface/loncoursedata.pm 2004/02/18 20:48:21 1.120 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.114 2004/02/02 21:45:12 matthew Exp $ +# $Id: loncoursedata.pm,v 1.120 2004/02/18 20:48:21 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1235,11 +1235,7 @@ sub update_full_student_data { # However, there is one wrinkle: submissions which end in # and odd number of '\' cause insert errors to occur. # Best trap this somehow... - $value =~ s/\'/\\\'/g; - my ($offensive_string) = ($value =~ /(\\+)$/); - if (length($offensive_string) % 2) { - $value =~ s/\\$/\\\\/; - } + $value = $dbh->quote($value); } if ($field eq 'submissiongrading' || $field eq 'molecule') { @@ -1919,7 +1915,7 @@ able to answer it correctly. ################################################ ################################################ sub get_problem_statistics { - my ($students,$symb,$part,$courseid) = @_; + my ($Sections,$status,$symb,$part,$courseid) = @_; return if (! defined($symb) || ! defined($part)); $courseid = $ENV{'request.course.id'} if (! defined($courseid)); # @@ -1933,18 +1929,22 @@ sub get_problem_statistics { # $dbh->do('DROP TABLE '.$stats_table); # May return an error my $request = - 'CREATE TEMPORARY TABLE '.$stats_table. - ' SELECT student_id,solved,award,awarded,tries FROM '.$performance_table. - ' WHERE symb_id='.$symb_id.' AND part_id='.$part_id; - if (defined($students)) { + 'CREATE TEMPORARY TABLE '.$stats_table.' '. + 'SELECT a.student_id,a.solved,a.award,a.awarded,a.tries '. + 'FROM '.$performance_table.' AS a '; + if ((defined($Sections) && lc($Sections->[0]) ne 'all') || + (defined($status) && lc($status) ne 'any')) { + $request .= 'NATURAL LEFT JOIN '.$student_table.' AS b '; + } + $request .= ' WHERE a.symb_id='.$symb_id.' AND a.part_id='.$part_id; + if (defined($Sections) && lc($Sections->[0]) ne 'all') { $request .= ' AND ('. - join(' OR ', map {'student_id='. - &get_student_id($_->{'username'}, - $_->{'domain'}) - } @$students + join(' OR ', map { "b.section='".$_."'" } @$Sections ).')'; } -# &Apache::lonnet::logthis($request); + if (defined($status) && lc($status) ne 'any') { + $request .= " AND b.status='".$status."'"; + } $dbh->do($request); # &Apache::lonnet::logthis('request = '.$/.$request); $request = 'SELECT COUNT(*),SUM(tries),MAX(tries),AVG(tries),STD(tries) '. @@ -2107,8 +2107,69 @@ sub get_response_data { } my $dataset = $sth->fetchall_arrayref(); if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { + # Clear the \'s from around the submission + for (my $i =0;$i[$i]->[3] =~ s/(\'$|^\')//g; + } + return $dataset; + } +} + + +sub RDs_awarddetail { return 3; } +sub RDs_submission { return 2; } +sub RDs_timestamp { return 1; } +sub RDs_tries { return 0; } +sub RDs_awarded { return 4; } + +sub get_response_data_by_student { + my ($student,$symb,$response,$courseid) = @_; + return undef 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 $student_id = &get_student_id($student->{'username'}, + $student->{'domain'}); + # + my $dbh = &Apache::lonmysql::get_dbh(); + return undef if (! defined($dbh)); + my $request = 'SELECT '. + 'c.tries, b.timestamp, a.submission, a.awarddetail, e.awarded '. + '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 '. + 'LEFT JOIN '.$student_table.' AS d '. + 'ON a.student_id=d.student_id '. + 'LEFT JOIN '.$performance_table.' AS e '. + 'ON a.symb_id=e.symb_id AND a.part_id=e.part_id AND '. + 'a.student_id=e.student_id AND c.tries=e.tries '. + 'WHERE '. + 'a.symb_id='.$symb_id.' AND a.response_id='.$response_id. + ' AND a.student_id='.$student_id.' ORDER BY b.timestamp'; + # &Apache::lonnet::logthis("request =\n".$request); + my $sth = $dbh->prepare($request); + $sth->execute(); + if ($dbh->err) { + &Apache::lonnet::logthis('error = '.$dbh->errstr()); + return undef; + } + my $dataset = $sth->fetchall_arrayref(); + if (ref($dataset) eq 'ARRAY' && scalar(@$dataset)>0) { + # Clear the \'s from around the submission + for (my $i =0;$i[$i]->[2] =~ s/(\'$|^\')//g; + } return $dataset; } + return undef; # error occurred } sub RT_student_id { return 0; } @@ -2164,7 +2225,7 @@ sub get_response_time_data { =pod -=item &get_student_scores($Students,$Symbs,$enrollment,$courseid) +=item &get_student_scores($Sections,$Symbs,$enrollment,$courseid) =cut