--- loncom/interface/loncoursedata.pm 2004/02/03 20:44:06 1.115 +++ loncom/interface/loncoursedata.pm 2004/03/07 21:42:19 1.122 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.115 2004/02/03 20:44:06 matthew Exp $ +# $Id: loncoursedata.pm,v 1.122 2004/03/07 21:42:19 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -182,7 +182,7 @@ sub get_sequence_assessment_data { next; } next if (! ref($curRes)); - next if (! $curRes->is_problem());# && !$curRes->randomout); + next if (! $curRes->is_problem() && $curRes->src() !~ /\.survey$/); # Okay, from here on out we only deal with assessments $title = $curRes->title(); $title =~ s/\:/\&\#058;/g; @@ -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') { @@ -1871,7 +1867,7 @@ populated and all local caching variable properly. This means you need to call &ensure_current_data for the students you are concerned with prior to calling this routine. -Inputs: $students, $symb, $part, $courseid +Inputs: $students, $symb, $part, $courseid, $starttime, $endtime =over 4 @@ -1884,6 +1880,9 @@ Each hash must contain at least the 'use =item $courseid is the course id, of course! +=item $starttime and $endtime are unix times which to use to limit +the statistical data. + =back Outputs: See the code for up to date information. A hash reference is @@ -1919,7 +1918,7 @@ able to answer it correctly. ################################################ ################################################ sub get_problem_statistics { - my ($Sections,$status,$symb,$part,$courseid) = @_; + my ($Sections,$status,$symb,$part,$courseid,$starttime,$endtime) = @_; return if (! defined($symb) || ! defined($part)); $courseid = $ENV{'request.course.id'} if (! defined($courseid)); # @@ -1949,6 +1948,20 @@ sub get_problem_statistics { if (defined($status) && lc($status) ne 'any') { $request .= " AND b.status='".$status."'"; } + # + &Apache::lonnet::logthis('starttime = '.$starttime); + my $time_requirements = undef; + if (defined($starttime)) { + $time_requirements .= 'a.timestamp>='.$starttime; + if (defined($endtime)) { + $time_requirements .= ' AND a.timestamp<='.$endtime; + } + } elsif (defined($endtime)) { + $time_requirements .= 'a.timestamp<='.$endtime; + } + if (defined($time_requirements)) { + $request .= ' AND '.$time_requirements; + } $dbh->do($request); # &Apache::lonnet::logthis('request = '.$/.$request); $request = 'SELECT COUNT(*),SUM(tries),MAX(tries),AVG(tries),STD(tries) '. @@ -2111,8 +2124,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; } @@ -2168,14 +2242,14 @@ sub get_response_time_data { =pod -=item &get_student_scores($Students,$Symbs,$enrollment,$courseid) +=item &get_student_scores($Sections,$Symbs,$enrollment,$courseid) =cut ################################################ ################################################ sub get_student_scores { - my ($Sections,$Symbs,$enrollment,$courseid) = @_; + my ($Sections,$Symbs,$enrollment,$courseid,$starttime,$endtime) = @_; $courseid = $ENV{'request.course.id'} if (! defined($courseid)); &setup_table_names($courseid); my $dbh = &Apache::lonmysql::get_dbh(); @@ -2186,8 +2260,8 @@ sub get_student_scores { if (defined($Symbs) && @$Symbs) { $symb_requirements = '('. join(' OR ', map{ "(a.symb_id='".&get_symb_id($_->{'symb'}). - "' AND a.part_id='".&get_part_id($_->{'part'}). - "')" + "' AND a.part_id='".&get_part_id($_->{'part'}). + "')" } @$Symbs).')'; } # @@ -2202,6 +2276,16 @@ sub get_student_scores { if (defined($enrollment) && $enrollment ne 'Any') { $enrollment_requirements = "b.status='".$enrollment."'"; } + # + my $time_requirements = undef; + if (defined($starttime)) { + $time_requirements .= "a.timestamp>='".$starttime."'"; + if (defined($endtime)) { + $time_requirements .= " AND a.timestamp<='".$endtime."'"; + } + } elsif (defined($endtime)) { + $time_requirements .= "a.timestamp<='".$endtime."'"; + } ## ## my $request = 'CREATE TEMPORARY TABLE IF NOT EXISTS '.$tmptable. @@ -2224,7 +2308,10 @@ sub get_student_scores { if (defined($enrollment_requirements)) { $request .= $enrollment_requirements.' AND '; } - $request =~ s/ AND $//; + if (defined($time_requirements)) { + $request .= $time_requirements.' AND '; + } + $request =~ s/ AND $//; # Strip of the trailing ' AND '. $request .= ' GROUP BY a.student_id'; # &Apache::lonnet::logthis("request = \n".$request); my $sth = $dbh->prepare($request);