Annotation of loncom/interface/statistics/lonpercentage.pm, revision 1.1

1.1     ! stredwic    1: # The LearningOnline Network with CAPA
        !             2: # (Publication Handler
        !             3: #
        !             4: # $Id: $
        !             5: #
        !             6: # Copyright Michigan State University Board of Trustees
        !             7: #
        !             8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             9: #
        !            10: # LON-CAPA is free software; you can redistribute it and/or modify
        !            11: # it under the terms of the GNU General Public License as published by
        !            12: # the Free Software Foundation; either version 2 of the License, or
        !            13: # (at your option) any later version.
        !            14: #
        !            15: # LON-CAPA is distributed in the hope that it will be useful,
        !            16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            18: # GNU General Public License for more details.
        !            19: #
        !            20: # You should have received a copy of the GNU General Public License
        !            21: # along with LON-CAPA; if not, write to the Free Software
        !            22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            23: #
        !            24: # /home/httpd/html/adm/gpl.txt
        !            25: #
        !            26: # http://www.lon-capa.org/
        !            27: #
        !            28: ###
        !            29: 
        !            30: package Apache::lonpercentage;
        !            31: 
        !            32: use strict;
        !            33: use Apache::lonhtmlcommon;
        !            34: use Apache::loncoursedata;
        !            35: use GDBM_File;
        !            36: 
        !            37: #my $jr;
        !            38: 
        !            39: sub BuildPercentageGraph {
        !            40:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
        !            41: 
        !            42:     my %cache;
        !            43:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        !            44:         $r->print('Unable to tie database.6');
        !            45:         return;
        !            46:     }
        !            47: 
        !            48:     $r->print(&CreateInterface(\%cache));
        !            49:     $r->rflush();
        !            50:     untie(%cache);
        !            51: 
        !            52:     my ($result) = &InitializeSelectedStudents($cacheDB, $students, 
        !            53: 					       $courseID, $c, $r);
        !            54:     if($result ne 'OK' || $c->aborted()) {
        !            55:         return;
        !            56:     }
        !            57: 
        !            58:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        !            59:         $r->print('Unable to tie database.6');
        !            60:         return;
        !            61:     }
        !            62: 
        !            63:     my ($Ptr, $percentage) = &GraphData(\%cache, $students);
        !            64:     $r->print($Ptr.'<br><br>');
        !            65: 
        !            66:     $r->print(&TableData(\%cache, $percentage));
        !            67: 
        !            68:     untie(%cache);
        !            69: 
        !            70:     return;
        !            71: }
        !            72: 
        !            73: sub CreateInterface {
        !            74:     my ($cache)=@_;
        !            75: 
        !            76:     my $Ptr = '';
        !            77:     $Ptr .= '<table border="0" cellspacing="5"><tbody>';
        !            78:     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
        !            79:     $Ptr .= '<td align="left">';
        !            80:     $Ptr .= &Apache::lonhtmlcommon::MapOptions($cache, 'Statistics',
        !            81:                                                'Statistics');
        !            82:     $Ptr .= '</td>'."\n";
        !            83: 
        !            84:     my $sequence = $cache->{'StatisticsMaps'};
        !            85:     if($sequence ne 'All Maps') {
        !            86: 	$Ptr .= '<td align="right">'."\n";
        !            87: 	$Ptr .= &Apache::lonhtmlcommon::ProblemOptions($cache,
        !            88: 						       'Statistics',
        !            89: 						       $sequence,
        !            90: 						       'Statistics');
        !            91: 	$Ptr .= '<td>'."\n";
        !            92: 
        !            93: 	my $problem = $cache->{'StatisticsProblemSelect'};
        !            94: 	if($problem ne 'All Problems') {
        !            95: 	    my $parts = &GetParts($cache, $sequence, $problem);
        !            96: 	    if(scalar(@$parts) > 0) {
        !            97: 		$Ptr .= '<td align="right">'."\n";
        !            98: 		$Ptr .= &Apache::lonhtmlcommon::PartOptions($cache,
        !            99: 							'Statistics',
        !           100: 							$parts,
        !           101: 							'Statistics');
        !           102: 		$Ptr .= '</td>'."\n";
        !           103: 	    }
        !           104: 	}
        !           105:     }
        !           106: 
        !           107:     $Ptr .= '</tr>'."\n";
        !           108: 
        !           109:     $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
        !           110:     $Ptr .= '</td>'."\n";
        !           111:     $Ptr .= '<td align="left">'."\n";
        !           112:     my @sections = split(':',$cache->{'sectionList'});
        !           113:     my @sectionsSelected = split(':',$cache->{'sectionsSelected'});
        !           114:     $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
        !           115:                                                           \@sectionsSelected,
        !           116:                                                           'Statistics');
        !           117:     $Ptr .= '</td></tr>'."\n";
        !           118:     $Ptr .= '</table>';
        !           119: 
        !           120:     return $Ptr;
        !           121: }
        !           122: 
        !           123: sub GetParts {
        !           124:     my ($cache,$sequence,$problem)=@_;
        !           125:     my @parts = ();
        !           126: 
        !           127:     foreach my $sequenceNumber (split(':',$cache->{'orderedSequences'})) {
        !           128: 	if($cache->{$sequenceNumber.':title'} eq $sequence) {
        !           129: 	    foreach my $problemNumber (split(':', 
        !           130: 				     $cache->{$sequenceNumber.':problems'})) {
        !           131: 		if($cache->{$problemNumber.':title'} eq $problem) {
        !           132: 		    @parts = split(':', 
        !           133: 		       $cache->{$sequenceNumber.':'.$problemNumber.':parts'});
        !           134: 		}
        !           135: 	    }
        !           136: 	}
        !           137:     }
        !           138:     
        !           139:     return \@parts;
        !           140: }
        !           141: 
        !           142: sub InitializeSelectedStudents {
        !           143:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
        !           144:     my %cache;
        !           145: 
        !           146:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        !           147:         $r->print('Unable to tie database1.1.');
        !           148:         return ('ERROR');
        !           149:     }
        !           150: 
        !           151:     # Remove students who don't have the proper section.
        !           152:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
        !           153:     for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
        !           154:         $studentIndex--) {
        !           155:         my $value = $cache{$students->[$studentIndex].':section'};
        !           156:         my $found = 0;
        !           157:         foreach (@sectionsSelected) {
        !           158:             if($_ eq 'none') {
        !           159:                 if($value eq '' || !defined($value) || $value eq ' ') {
        !           160:                     $found = 1;
        !           161:                     last;
        !           162:                 }
        !           163:             } else {
        !           164:                 if($value eq $_) {
        !           165:                     $found = 1;
        !           166:                     last;
        !           167:                 }
        !           168:             }
        !           169:         }
        !           170:         if($found == 0) {
        !           171:             splice(@$students, $studentIndex, 1);
        !           172:         }
        !           173:     }
        !           174: 
        !           175:     untie(%cache);
        !           176: 
        !           177:     &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
        !           178: 							      'true',
        !           179: 							      $cacheDB,
        !           180: 							      'true', 
        !           181: 							      'true',
        !           182: 							      $courseID,
        !           183: 							      $r, $c);
        !           184: 
        !           185:     return ('OK');
        !           186: }
        !           187: 
        !           188: sub GraphData {
        !           189:     my ($cache,$students)=@_;
        !           190: 
        !           191:     my $sequenceSelected = $cache->{'StatisticsMaps'};
        !           192:     my $problemSelected  = $cache->{'StatisticsProblemSelect'};
        !           193:     my $partSelected     = $cache->{'StatisticsPartSelect'};
        !           194: 
        !           195:     my %percentages;
        !           196:     my $Ptr = '';
        !           197: 
        !           198:     foreach(@$students) {
        !           199: 	my $totalCorrect = 0;
        !           200: 	my $totalProblems = 0;
        !           201: 
        !           202: 	foreach my $sequence (split(':',$cache->{'orderedSequences'})) {
        !           203: 	    next if($cache->{$sequence.':title'} ne $sequenceSelected &&
        !           204: 		    $sequenceSelected ne 'All Maps');
        !           205: 	    foreach my $problem (split(':',$cache->{$sequence.':problems'})) {
        !           206: 		next if($cache->{$problem.':title'} ne $problemSelected &&
        !           207: 			$problemSelected ne 'All Problems' && 
        !           208: 			$sequenceSelected ne 'All Maps');
        !           209: 		foreach my $part (split(':',$cache->{$sequence.':'.$problem.
        !           210: 						     ':parts'})) {
        !           211: 		    next if($part ne $partSelected && 
        !           212: 			    $partSelected ne 'All Parts' &&
        !           213: 			    $problemSelected ne 'All Problems' && 
        !           214: 			    $sequenceSelected ne 'All Maps');
        !           215: 		    my $code = $cache->{$_.':'.$problem.':'.$part.':code'};
        !           216: 		    if($code eq '*' || $code eq '+') {
        !           217: 			$totalCorrect++;
        !           218: 			$totalProblems++;
        !           219: 		    } elsif($code ne 'x') {
        !           220: 			$totalProblems++;
        !           221: 		    }
        !           222: 		}
        !           223: 	    }
        !           224: 	}
        !           225: 
        !           226: 	my $percent = sprintf("%d", ($totalProblems) ?
        !           227: 			      (($totalCorrect/$totalProblems)*100) : 0);
        !           228: 	if(defined($percentages{$percent})) {
        !           229: 	    $percentages{$percent} .= ':::'.$_;
        !           230: 	} else {
        !           231: 	    $percentages{$percent} = $_;
        !           232: 	}
        !           233:     }
        !           234: 
        !           235:     my @percent = ();
        !           236:     my @percentCount = ();
        !           237:     my $max = 0;
        !           238:     foreach my $key (sort(keys(%percentages))) {
        !           239: 	push(@percent, $key);
        !           240: 	my $count = scalar(split(':::', $percentages{$key}));
        !           241: 	if($count > $max) {
        !           242: 	    $max = $count;
        !           243: 	}
        !           244: 	push(@percentCount, $count);
        !           245:     }
        !           246: 
        !           247:     my @GData = ('', 'Percentage', 'Number_of_Students', 
        !           248: 		 $max, scalar(@percent), 
        !           249:                  join(',',@percent), join(',', @percentCount));
        !           250: 
        !           251:     $Ptr .= '</form>'."\n";
        !           252:     $Ptr .= '<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData));
        !           253:     $Ptr .= '" border="1" />';
        !           254:     $Ptr .= '<form>'."\n";
        !           255: 
        !           256:     return ($Ptr, \%percentages);
        !           257: }
        !           258: 
        !           259: sub TableData {
        !           260:     my($cache,$percentage)=@_;
        !           261:     my $Ptr;
        !           262: 
        !           263:     $Ptr .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
        !           264:     $Ptr .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
        !           265: 
        !           266:     $Ptr .= '<tr>'."\n";
        !           267:     $Ptr .= '<td>Percent Correct</td><td>Students</td>';
        !           268:     $Ptr .= '</tr>'."\n";
        !           269: 
        !           270:     my $alternate=0;
        !           271:     foreach (sort(keys(%$percentage))) {
        !           272:         if($alternate) {
        !           273:             $Ptr .= '<tr bgcolor="#ffffe6">';
        !           274:         } else {
        !           275:             $Ptr .= '<tr bgcolor="#ffffc6">';
        !           276:         }
        !           277:         $alternate = ($alternate + 1) % 2;
        !           278: 
        !           279: 	$Ptr .= '<td>'.$_.'</td><td>';
        !           280: 
        !           281: 	foreach my $name (sort(split(':::', $percentage->{$_}))) {
        !           282: 	    $Ptr .= '<a href="/adm/statistics?reportSelected=';
        !           283: 	    $Ptr .= &Apache::lonnet::escape('Student Assessment');
        !           284: 	    $Ptr .= '&StudentAssessmentStudent=';
        !           285: 	    $Ptr .= &Apache::lonnet::escape($cache->{$name.':fullname'}).'">';
        !           286: 	    $Ptr .= $cache->{$name.':fullname'};
        !           287: 	    $Ptr .= '</a>,&nbsp&nbsp';
        !           288:         }
        !           289: 
        !           290: 	$Ptr .= '</td></tr>'."\n";
        !           291:     }
        !           292: 
        !           293:     $Ptr .= '</tr>'."\n";
        !           294:     $Ptr .= '</table></td></tr></table>'."\n";
        !           295: 
        !           296:     return $Ptr;
        !           297: }
        !           298: 
        !           299: 1;
        !           300: __END__

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