File:
[LON-CAPA] /
loncom /
interface /
lonpickcode.pm
Revision
1.1:
download - view:
text,
annotated -
select for diffs
Thu Apr 22 22:57:53 2004 UTC (20 years, 4 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- most of the work for allowing a user to pcik a new code is doen
- also addin interface fore allwoing downloads of datafiles (not acutally workign yet)
- add in the possibility to 'redo skipped' or 'ignore previous corrections', not working yet but the interface is there
1: # The LearningOnline Network
2: # Pick a CODE from the list of possible CODEs
3: #
4: # $Id: lonpickcode.pm,v 1.1 2004/04/22 22:57:53 albertel Exp $
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: package Apache::lonpickcode;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon();
34: use Apache::grades();
35: use Apache::lonlocal;
36:
37: sub get_code_freq {
38: my ($r)=@_;
39: my %codes;
40: my %scantron_config=
41: &Apache::grades::get_scantron_config($ENV{'form.scantron_format'});
42: $r->rflush();
43: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
44: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
45: my $line=&Apache::grades::scantron_get_line($scanlines,$i);
46: if ($line=~/^[\s\cz]*$/) { next; }
47: my $scan_record=
48: &Apache::grades::scantron_parse_scanline($line,$i,
49: \%scantron_config,
50: $scan_data,1);
51: $codes{$$scan_record{'scantron.CODE'}}++;
52:
53: }
54: return %codes;
55: }
56:
57: sub get_codes {
58: my $old_name=$ENV{'form.scantron_CODElist'};
59: my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
60: my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
61: my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
62: my %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
63: return %allcodes;
64: }
65:
66: sub num_matches {
67: my ($code) = @_;
68: my $orig=$ENV{'form.curCODE'};
69: my @code=split(//,$code);
70: my @orig=split(//,$orig);
71: my $same=0;
72: for (my $i=0;$i<scalar(@code);$i++) {
73: if ($code[$i] eq $orig[$i]) { $same++; }
74: }
75: return $same;
76: }
77:
78: sub handler {
79: my $r = shift;
80: &Apache::loncommon::content_type($r,'text/html');
81: $r->send_http_header;
82: return OK if $r->header_only;
83:
84: $r->print(<<ENDDOCUMENT);
85: <html>
86: <head>
87: <title>The LearningOnline Network with CAPA</title>
88: </head>
89: ENDDOCUMENT
90:
91:
92: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
93: ['curCODE','scantron_selectfile',
94: 'form','scantron_format',
95: 'scantron_CODElist']);
96:
97: if (!
98: ($ENV{'request.course.id'}) &&
99: (&Apache::lonnet::allowed('usc',$ENV{'request.course.id'}))) {
100: $r->print('<body>Access not allowed.</body>');
101: return OK;
102: }
103:
104: $r->print(&Apache::loncommon::bodytag("Selecting a CODE"));
105: $r->print(<<ENDSCRIPT);
106: <script>
107: function gochoose(uname,udom) {
108: opener.document.$ENV{'form.form'}.$ENV{'form.unameelement'}.value=uname;
109: var slct=opener.document.$ENV{'form.form'}.$ENV{'form.udomelement'};
110: var i;
111: for (i=0;i<slct.length;i++) {
112: if (slct.options[i].value==udom) { slct.selectedIndex=i; }
113: }
114: self.close();
115: }
116: </script>
117: ENDSCRIPT
118:
119:
120: $r->print("<p>The CODE on the paper is <tt><b>".$ENV{'form.curCODE'}.
121: "</b></tt>. Please Select a new one.</p>\n".'<form>');
122: my %codes=&get_codes();
123: my %code_freq=&get_code_freq($r);
124: my $num_matches=&num_matches($ENV{'form.curCODE'});
125: for (my $i=$num_matches;$i>=0;$i--) {
126: my $to_print="<p> CODEs with $i matches</p>";
127: $to_print.='<table border="1"><tr><td></td><td>CODE</td><td># of exams using this CODE</td>';
128: my $print;
129: foreach my $code (sort(keys(%codes))) {
130: if (&num_matches($code) != $i) { next; }
131: $print=1;
132: my $count=$code_freq{$code};
133: if (!$count) { $count=0; }
134: $to_print.='<tr><td>'.
135: '<input type="button" value="'.&mt('Select').
136: '" onClick="gochoose(\''.$code.'\')" /></td>'.
137: '<td><tt>'.$code.'</tt></td><td> <tt>'.$count.
138: '</tt></td></tr>';
139: delete($codes{$code});
140: }
141: $to_print.='</table>';
142: if ($print) { $r->print($to_print); }
143: }
144: $r->print('</form></body></html>');
145: return OK;
146: }
147:
148: 1;
149: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>