# The LearningOnline Network # Pick a CODE from the list of possible CODEs # # $Id: lonpickcode.pm,v 1.2 2004/04/24 08:31:57 albertel 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/ # package Apache::lonpickcode; use strict; use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::grades(); use Apache::lonlocal; sub get_code_freq { my ($r)=@_; my %codes; my %scantron_config= &Apache::grades::get_scantron_config($ENV{'form.scantron_format'}); $r->rflush(); my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile(); for (my $i=0;$i<=$scanlines->{'count'};$i++) { my $line=&Apache::grades::scantron_get_line($scanlines,$i); if ($line=~/^[\s\cz]*$/) { next; } my $scan_record= &Apache::grades::scantron_parse_scanline($line,$i, \%scantron_config, $scan_data,1); $codes{$$scan_record{'scantron.CODE'}}++; } return %codes; } sub get_codes { my $old_name=$ENV{'form.scantron_CODElist'}; my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum); my %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name}); return %allcodes; } sub num_matches { my ($code) = @_; my $orig=$ENV{'form.curCODE'}; my @code=split(//,$code); my @orig=split(//,$orig); my $same=0; for (my $i=0;$isend_http_header; return OK if $r->header_only; $r->print(< The LearningOnline Network with CAPA ENDDOCUMENT &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['curCODE','scantron_selectfile', 'form','scantron_format', 'scantron_CODElist']); if (!($ENV{'request.course.id'}) && (&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) { $r->print('Access not allowed.'); return OK; } $r->print(&Apache::loncommon::bodytag("Selecting a CODE")); $r->print(< function gochoose(newcode) { opener.document.$ENV{'form.form'}.scan_CODE_selectedvalue.value=newcode; var slct=opener.document.$ENV{'form.form'}.scan_CODE_resolution; var i; for (i=0;i ENDSCRIPT $r->print("

The CODE on the paper is ".$ENV{'form.curCODE'}. ". Please Select a new one.

\n".'
'); my %codes=&get_codes(); my %code_freq=&get_code_freq($r); my $num_matches=&num_matches($ENV{'form.curCODE'}); for (my $i=$num_matches;$i>=0;$i--) { my $to_print="

CODEs with $i matches

"; $to_print.=''; my $print; foreach my $code (sort(keys(%codes))) { if (&num_matches($code) != $i) { next; } $print=1; my $count=$code_freq{$code}; if (!$count) { $count=0; } $to_print.=''. ''; delete($codes{$code}); } $to_print.='
CODE# of exams using this CODE
'. ''.$code.' '.$count. '
'; if ($print) { $r->print($to_print); } } $r->print('
'); return OK; } 1; __END__