File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.1: download - view: text, annotated - select for diffs
Wed Jul 24 14:52:32 2002 UTC (21 years, 11 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Broke lonstatistics up.  Now the bulk of the code that generate the
html pages for the different forms have there own module.  Some minor
modifications were necessary to accomplish this.

Also added default student selected on student assessment page is now
all students.  The full name links on the classlist page now take
you to the student assessment page with that student selected.  I
had forgotten to put the post data in the get_unprocessed_cgi
function call.

# The LearningOnline Network with CAPA
# (Publication Handler
#
# $Id: lonstudentassessment.pm,v 1.1 2002/07/24 14:52:32 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# (Navigate problems for statistical reports
# YEAR=2001
# 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
# 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
# YEAR=2002
# 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
# 5/12,5/14,5/15,5/19,5/26,7/16  Behrouz Minaei
#
###

package Apache::lonstudentassessment; 

use strict;
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;

sub BuildStudentAssessmentPage {
    my ($cacheDB, $students, $courseID, $c)=@_;

    my %cache;

    my $Ptr = '';
    $Ptr .= '<table border="0"><tbody>';

    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
        return '<html><body>Unable to tie database.</body></html>';
    }

    my $selectedName = $cache{'StudentAssessmentStudent'};
    for(my $index=0; 
        ($selectedName ne 'All Students') && ($index<(scalar @$students)); 
        $index++) {
        my $fullname = $cache{$students->[$index].':fullname'};
        if($fullname eq $selectedName) {
            if($cache{'StudentAssessmentMove'} eq 'next') {
                if($index == ((scalar @$students) - 1)) {
                    $selectedName = $students->[0];
                } else {
                    $selectedName = $students->[$index+1];
                }
            } elsif($cache{'StudentAssessmentMove'} eq 'previous') {
                if($index == 0) {
                    $selectedName = $students->[-1];
                } else {
                    $selectedName = $students->[$index-1];
                }
            } else {
                $selectedName = $students->[$index];
            }
            last;
        }
    }

    $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
    $Ptr .= '<td align="left">';
    $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'StudentAssessment');
    $Ptr .= '</td></tr>'."\n";
    $Ptr .= '<tr><td align="right"><b>Select Student</b></td>'."\n";
    $Ptr .= '<td align="left">'."\n";
    $Ptr .= &Apache::lonhtmlcommon::StudentOptions(\%cache, $students, 
                                                   $selectedName, 
                                                   'StudentAssessment');
    $Ptr .= '</td></tr>'."\n";
    untie(%cache);

    $Ptr .= '<tr><td></td><td align="left">';
    $Ptr .= '<input type="submit" name="CreateStudentAssessment" ';
    $Ptr .= 'value="Create Student Report" />';
    $Ptr .= '&nbsp&nbsp&nbsp';
    $Ptr .= '<input type="submit" name="PreviousStudent" ';
    $Ptr .= 'value="Previous Student" />';
    $Ptr .= '&nbsp&nbsp&nbsp';
    $Ptr .= '<input type="submit" name="NextStudent" ';
    $Ptr .= 'value="Next Student" />';
    $Ptr .= '&nbsp&nbsp&nbsp';
    $Ptr .= '</td></tr></tbody></table>'."\n";

    if($selectedName eq 'No Student Selected') {
	$Ptr .= '<h3><font color=blue>WARNING: ';
        $Ptr .= 'Please select a student</font></h3>';
        return $Ptr;
    }

    my $selected=0;
    foreach (@$students) {
        next if ($_ ne $selectedName && 
                 $selectedName ne 'All Students');
        $selected = 1;
        my $courseData = 
            &Apache::loncoursedata::DownloadCourseInformation($_, $courseID);
        last if ($c->aborted());
        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
            &Apache::loncoursedata::ProcessStudentData(\%cache, 
                                                       $courseData, $_);
            if(!$c->aborted()) { $Ptr .= &StudentReport(\%cache, $_); }
            untie(%cache);
        }
    }
    if($selected == 0) {
	$Ptr .= '<h3><font color=blue>WARNING: ';
        $Ptr .= 'Please select a student</font></h3>';
    }

    return $Ptr;
}

#---- Student Assessment Web Page --------------------------------------------

# ------ Create different Student Report 
sub StudentReport {
    my ($cache, $name)=@_;

    my $Str = '';
    if($cache->{$name.':error'} =~ /course/) {
        my ($username)=split(':',$name);
        $Str .= '<b><font color="blue">No course data for student </font>';
        $Str .= '<font color="red">'.$username.'.</font></b><br>';
        return $Str;
    }

    $Str .= "<table border=2><tr><th> \# </th><th> Set Title </th>";
    $Str .= '<th> Results </th><th> Tries </th></tr>'."\n";

    my $codes;
    my $attempts;
    foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
        if($cache->{'StudentAssessmentMap'} ne 'All Maps'  &&
           $cache->{'StudentAssessmentMap'} ne $cache->{$sequence.':title'}) {
            next;
        }

        $Str .= '<tr><td>'.$sequence.'</td>';
        $Str .= '<td>'.$cache->{$sequence.':title'}.'</td>';

        $codes = '';
        $attempts = '';
        foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
            my $problem = $cache->{$problemID.':problem'};
            my $LatestVersion = $cache->{$name.':version:'.$problem};

            # Output dashes for all the parts of this problem if there
            # is no version information about the current problem.
            if(!$LatestVersion) {
                foreach my $part (split(/\:/,$cache->{$sequence.':'.
                                                      $problemID.
                                                      ':parts'})) {
		    $codes    .= "-,";
                    $attempts .= "0,"; 
                }
                next;
            }

            my %partData=undef;
            # Initialize part data, display skips correctly
            # Skip refers to when a student made no submissions on that
            # part/problem.
            foreach my $part (split(/\:/,$cache->{$sequence.':'.
                                                  $problemID.
                                                  ':parts'})) {
                $partData{$part.':tries'}=0;
                $partData{$part.':code'}='-';
            }

            # Looping through all the versions of each part, starting with the
            # oldest version.  Basically, it gets the most recent 
            # set of grade data for each part.
	    for(my $Version=1; $Version<=$LatestVersion; $Version++) {
                foreach my $part (split(/\:/,$cache->{$sequence.':'.
                                                      $problemID.
                                                      ':parts'})) {

                    if(!defined($cache->{$name.":$Version:$problem".
                                               ":resource.$part.solved"})) {
                        # No grade for this submission, so skip
                        next;
                    }

                    my $tries=0;
                    my $code='U';

                    $tries = $cache->{$name.":$Version:$problem".
                                      ":resource.$part.tries"};
                    $partData{$part.':tries'}=($tries) ? $tries : 0;

                    my $val = $cache->{$name.":$Version:$problem".
                                       ":resource.$part.solved"};
                    if    ($val eq 'correct_by_student')   {$code = 'Y';} 
                    elsif ($val eq 'correct_by_override')  {$code = 'y';}
                    elsif ($val eq 'incorrect_attempted')  {$code = 'N';} 
                    elsif ($val eq 'incorrect_by_override'){$code = 'N';}
                    elsif ($val eq 'excused')              {$code = 'x';}
                    $partData{$part.':code'}=$code;
                }
            }

            # Loop through all the parts for the current problem in the 
            # correct order and prepare the output
            foreach (split(/\:/,$cache->{$sequence.':'.$problemID.
                                         ':parts'})) {
                $codes    .= $partData{$_.':code'}.',';
                $attempts .= $partData{$_.':tries'}.','; 
            }
        }
        $codes    =~ s/,$//;
        $attempts =~ s/,$//;
        $Str .= '<td>'.$codes.'</td>';
        $Str .= '<td>'.$attempts.'</td>';
        $Str .= '</tr>'."\n";
    }

    $Str .= '</table>'."\n";

    return $Str;
}

#---- END Student Assessment Web Page ----------------------------------------
1;
__END__

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