File:
[LON-CAPA] /
loncom /
homework /
grades.pm
Revision
1.20:
download - view:
text,
annotated -
select for diffs
Tue Apr 9 03:56:29 2002 UTC (22 years, 4 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- igot rid of the 1 (in a much earlier version listStudents returned a string to be printed, in a later rewrite it started doing it's own printing, thus no need to print the result of listStudents)
1: # The LearningOnline Network with CAPA
2: # The LON-CAPA Grading handler
3: #
4: # $Id: grades.pm,v 1.20 2002/04/09 03:56:29 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: # 2/9,2/13 Guy Albertelli
29: # 6/8 Gerd Kortemeyer
30: # 7/26 H.K. Ng
31: # 8/20 Gerd Kortemeyer
32:
33: package Apache::grades;
34: use strict;
35: use Apache::style;
36: use Apache::lonxml;
37: use Apache::lonnet;
38: use Apache::loncommon;
39: use Apache::lonhomework;
40: use Apache::Constants qw(:common);
41:
42: sub moreinfo {
43: my ($request,$reason) = @_;
44: $request->print("Unable to process request: $reason");
45: if ( $Apache::grades::viewgrades eq 'F' ) {
46: $request->print('<form action="/adm/grades" method="post">'."\n");
47: if ($ENV{'form.url'}) {
48: $request->print('<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />'."\n");
49: }
50: if ($ENV{'form.symb'}) {
51: $request->print('<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />'."\n");
52: }
53: $request->print('<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />'."\n");
54: $request->print("Student:".'<input type="text" name="student" value="'.$ENV{'form.student'}.'" />'."<br />\n");
55: $request->print("Domain:".'<input type="text" name="domain" value="'.$ENV{'user.domain'}.'" />'."<br />\n");
56: $request->print('<input type="submit" name="submit" value="ReSubmit" />'."<br />\n");
57: $request->print('</form>');
58: }
59: return '';
60: }
61:
62:
63: sub listStudents {
64: my ($request) = shift;
65: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
66: my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
67: $request->print ('<h1>Show Student Submissions on Assessment</h1>'.
68: '<table border="1"><tr><th>Username</th><th>Domain</th><th>Name</th><th> </th></tr>'
69: );
70: my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
71: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
72: my ($sname,$sdom) = split(/:/,$student);
73:
74: my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
75: ':environment:lastname&generation&firstname&middlename',
76: &Apache::lonnet::homeserver($sname,$sdom));
77: #print "reply=$reply<br>";
78: my (@nameparts) = split /&/,$reply;
79: # my $sfullname = $Apache::lonnet::unescape($nameparts[0]);
80:
81: if ( $Apache::grades::viewgrades eq 'F' ) {
82: $request->print(
83: "\n".'<tr><form action="/adm/grades" method="post">'.
84: "<td>$sname</td><td>$sdom</td><td>@nameparts</td><td>");
85: if ($ENV{'form.url'}) {
86: $request->print(
87: '<input type="hidden" name="url" value="'.$ENV{'form.url'}.'" />');
88: }
89: if ($ENV{'form.symb'}) {
90: $request->print(
91: '<input type="hidden" name="symb" value="'.$ENV{'form.symb'}.'" />');
92: }
93: $request->print(
94: '<input type="hidden" name="command" value="'.$ENV{'form.command'}.'" />');
95: $request->print(
96: '<input type="hidden" name="student" value="'.$sname.'" />');
97: $request->print(
98: '<input type="hidden" name="domain" value="'.$sdom.'" />');
99: $request->print(
100: '<input type="submit" name="submit" value="View" />');
101: $request->print('</td></form></tr>');
102: }
103: }
104: $request->print('</table>');
105: }
106:
107:
108: #FIXME - needs to handle multiple matches
109: sub finduser {
110: my ($name) = @_;
111: my $domain = '';
112:
113: if ( $Apache::grades::viewgrades eq 'F' ) {
114: #get classlist
115: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
116: my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
117: #print "Found $cdom:$cnum:$chome<br />";
118: my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
119: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
120: my ($posname,$posdomain) = split(/:/,$student);
121: if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
122: }
123: return ($name,$domain);
124: } else {
125: return ($ENV{'user.name'},$ENV{'user.domain'});
126: }
127: }
128:
129: sub getclasslist {
130: my ($coursedomain,$coursenum,$coursehome,$hideexpired) = @_;
131: my $classlist=&Apache::lonnet::reply("dump:$coursedomain:$coursenum:classlist",$coursehome);
132: my %classlist=();
133: my $now = time;
134: foreach my $record (split /&/, $classlist) {
135: my ($name,$value)=split(/=/,&Apache::lonnet::unescape($record));
136: my ($end,$start)=split(/:/,$value);
137: # still a student?
138: if (($hideexpired) && ($end) && ($end < $now)) {
139: #print "Skipping:$name:$end:$now<br />\n";
140: next;
141: }
142: #print "record=$record<br>";
143: push( @{ $classlist{'allids'} }, $name);
144: }
145: return (%classlist);
146: }
147:
148: sub getpartlist {
149: my ($url) = @_;
150: my @parts =();
151: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
152: foreach my $key (@metakeys) {
153: if ( $key =~ m/stores_([0-9]+)_.*/ ) {
154: push(@parts,$key);
155: }
156: }
157: return @parts;
158: }
159:
160: sub viewstudentgrade {
161: my ($url,$symb,$courseid,$student,@parts) = @_;
162: my $result ='';
163: my $cellclr = '"#ffffdd"';
164: my ($stuname,$domain) = split(/:/,$student);
165:
166: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
167:
168: $result.="<tr><td bgcolor=$cellclr>$stuname</td><td bgcolor=$cellclr align=\"middle\">$domain</td>\n";
169: foreach my $part (@parts) {
170: my ($temp,$part,$type)=split(/_/,$part);
171: #print "resource.$part.$type = ".$record{"resource.$part.$type"}." <br />\n";
172: if ($type eq 'awarded') {
173: my $score=$record{"resource.$part.$type"};
174: $result.="<td bgcolor=$cellclr align=\"middle\"><input type=\"text\" name=\"GRADE.$student.$part.$type\" value=\"$score\" size=\"4\" /></td>\n";
175: } elsif ($type eq 'tries') {
176: my $score=$record{"resource.$part.$type"};
177: $result.="<td bgcolor=$cellclr align=\"middle\"><input type=\"text\" name=\"GRADE.$student.$part.$type\" value=\"$score\" size=\"4\" /></td>\n"
178: } elsif ($type eq 'solved') {
179: my $score=$record{"resource.$part.$type"};
180: $result.="<td bgcolor=$cellclr align=\"middle\"><select name=\"GRADE.$student.$part.$type\">\n";
181: if ($score =~ /^correct/) {
182: $result.="<option selected=\"on\">correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
183: } elsif ($score =~ /^incorrect/) {
184: $result.="<option>correct</option>\n<option selected=\"on\">incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
185: } elsif ($score eq '') {
186: $result.="<option>correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option>ungraded</option>\n<option selected=\"on\">nothing</option>\n";
187: } elsif ($score =~ /^excused/) {
188: $result.="<option>correct</option>\n<option>incorrect</option>\n<option selected=\"on\">excused</option>\n<option>ungraded</option>\n<option>nothing</option>\n";
189: } elsif ($score =~ /^ungraded/) {
190: $result.="<option>correct</option>\n<option>incorrect</option>\n<option>excused</option>\n<option selected=\"on\">ungraded</option>\n<option>nothing</option>\n";
191: }
192: $result.="</select></td>\n";
193: }
194: }
195: $result.='</tr>';
196: return $result;
197: }
198: #FIXME need to look at the meatdata <stores> spec on what type of data to accept and provide an
199: #interface based on that, also do that to above function.
200: sub setstudentgrade {
201: my ($url,$symb,$courseid,$student,@parts) = @_;
202:
203: my $result ='';
204:
205: my ($stuname,$domain) = split(/:/,$student);
206:
207: my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
208:
209: my %newrecord;
210:
211: foreach my $part (@parts) {
212: my ($temp,$part,$type)=split(/_/,$part);
213: my $oldscore=$record{"resource.$part.$type"};
214: my $newscore=$ENV{"form.GRADE.$student.$part.$type"};
215: if ($type eq 'solved') {
216: my $update=0;
217: if ($newscore eq 'nothing' ) {
218: if ($oldscore ne '') {
219: $update=1;
220: $newscore = '';
221: }
222: } elsif ($oldscore !~ m/^$newscore/) {
223: $update=1;
224: $result.="Updating $stuname to $newscore<br />\n";
225: if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
226: if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
227: if ($newscore eq 'excused') { $newscore = 'excused'; }
228: if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
229: } else {
230: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
231: }
232: if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
233: } else {
234: if ($oldscore ne $newscore) {
235: $newrecord{"resource.$part.$type"}=$newscore;
236: $result.="Updating $student"."'s status for $part.$type to $newscore<br />\n";
237: } else {
238: #$result.="$stuname:$part:$type:unchanged $oldscore to $newscore:<br />\n";
239: }
240: }
241: }
242: if ( scalar(keys(%newrecord)) > 0 ) {
243: $newrecord{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
244: &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
245:
246: $result.="Stored away ".scalar(keys(%newrecord))." elements.<br />\n";
247: }
248: return $result;
249: }
250:
251: sub submission {
252: my ($request) = @_;
253: my $url=$ENV{'form.url'};
254: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
255: if ($ENV{'form.student'} eq '') { &moreinfo($request,"Need student login id"); return ''; }
256: # if ($ENV{'form.student'} eq '') { &listStudents($request); return ''; }
257: my ($uname,$udom) = &finduser($ENV{'form.student'});
258: if ($uname eq '') { &moreinfo($request,"Unable to find student"); return ''; }
259: my $symb;
260: if ($ENV{'form.symb'}) {
261: $symb=$ENV{'form.symb'};
262: } else {
263: $symb=&Apache::lonnet::symbread($url);
264: }
265: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
266: my $answer=&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
267: $ENV{'request.course.id'});
268: my $result="<h2> Submission Record </h2> $uname:$udom for $url <br />".$answer;
269: my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
270: $ENV{'request.course.id'});
271: $result.="Student's view of the problem:<br /> $rendered <br /> Correct answer:";
272:
273: my $answer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
274: $ENV{'request.course.id'});
275: $result.=$answer;
276: return $result;
277: }
278:
279: sub viewgrades {
280: my ($request) = @_;
281: my $result='';
282:
283: #get resource reference
284: my $url=$ENV{'form.url'};
285: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
286: my $symb=$ENV{'form.symb'};
287: if (!$symb) { $symb=&Apache::lonnet::symbread($url); }
288: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
289:
290: #get classlist
291: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
292: my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
293: #print "Found $cdom:$cnum:$chome<br />";
294: my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
295: my $headerclr = '"#ccffff"';
296: my $cellclr = '"#ffffcc"';
297:
298: #get list of parts for this problem
299: my (@parts) = &getpartlist($url);
300:
301: $request->print ("<h2><font color=\"#339966\">Manual Grading</font></h2>");
302:
303: #start the form
304: $result = '<form action="/adm/grades" method="post">'."\n".
305: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
306: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
307: '<input type="hidden" name="command" value="editgrades" />'."\n".
308: '<input type="submit" name="submit" value="Submit Changes" />'."\n".
309: '<table border=0><tr><td bgcolor="#999999">'."\n".
310: '<table border=0>'."\n".
311: '<tr><td bgcolor='.$headerclr.'>UserId</td><td bgcolor='.$headerclr.'>Domain</td>'."\n";
312: foreach my $part (@parts) {
313: my $display=&Apache::lonnet::metadata($url,$part.'.display');
314: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
315: $result.='<td bgcolor='.$headerclr.'>'.$display.'</td>'."\n";
316: }
317: $result.="</tr>";
318: #get info for each student
319: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
320: $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
321: }
322: $result.='</table></td></tr></table><input type="submit" name="submit" value="Submit Changes" /></form>';
323:
324: return $result;
325: }
326:
327: sub editgrades {
328: my ($request) = @_;
329: my $result='';
330:
331: my $symb=$ENV{'form.symb'};
332: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
333: my $url=$ENV{'form.url'};
334: #get classlist
335: my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
336: my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
337: #print "Found $cdom:$cnum:$chome<br />";
338: my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
339:
340: #get list of parts for this problem
341: my (@parts) = &getpartlist($url);
342:
343: $result.='<form action="/adm/grades" method="post">'."\n".
344: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
345: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
346: '<input type="hidden" name="command" value="viewgrades" />'."\n".
347: '<input type="submit" name="submit" value="See Grades" /> <br />'."\n";
348:
349: foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
350: $result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
351: }
352:
353: $result.='<input type="submit" name="submit" value="See Grades" /></table></form>';
354: return $result;
355: }
356:
357: sub send_header {
358: my ($request)= @_;
359: $request->print(&Apache::lontexconvert::header());
360: # $request->print("
361: #<script>
362: #remotewindow=open('','homeworkremote');
363: #remotewindow.close();
364: #</script>");
365: $request->print('<body bgcolor="#FFFFFF">');
366: }
367:
368: sub send_footer {
369: my ($request)= @_;
370: $request->print('</body>');
371: $request->print(&Apache::lontexconvert::footer());
372: }
373:
374: sub handler {
375: my $request=$_[0];
376:
377: if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
378:
379: if ($ENV{'browser.mathml'}) {
380: $request->content_type('text/xml');
381: } else {
382: $request->content_type('text/html');
383: }
384: $request->send_http_header;
385: return OK if $request->header_only;
386: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
387: my $url=$ENV{'form.url'};
388: my $symb=$ENV{'form.symb'};
389: my $command=$ENV{'form.command'};
390: if (!$url) {
391: my ($temp1,$temp2);
392: ($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
393: $url = $ENV{'form.url'};
394: }
395: &send_header($request);
396: if ($url eq '' && $symb eq '') {
397: if ($ENV{'user.adv'}) {
398: if (($ENV{'form.codeone'}) && ($ENV{'form.codetwo'}) &&
399: ($ENV{'form.codethree'})) {
400: my $token=$ENV{'form.codeone'}.'*'.$ENV{'form.codetwo'}.'*'.
401: $ENV{'form.codethree'};
402: my ($tsymb,$tuname,$tudom,$tcrsid)=
403: &Apache::lonnet::checkin($token);
404: if ($tsymb) {
405: my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
406: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
407: $request->print(
408: &Apache::lonnet::ssi('/res/'.$url,
409: ('grade_username' => $tuname,
410: 'grade_domain' => $tudom,
411: 'grade_courseid' => $tcrsid,
412: 'grade_symb' => $tsymb)));
413: } else {
414: $request->print('<h1>Not authorized: '.$token.'</h1>');
415: }
416: } else {
417: $request->print('<h1>Not a valid DocID: '.$token.'</h1>');
418: }
419: } else {
420: $request->print(&Apache::lonxml::tokeninputfield());
421: }
422: }
423: } else {
424: $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
425: if ($command eq 'submission') {
426: &listStudents($request) if ($ENV{'form.student'} eq '');
427: $request->print(&submission($request)) if ($ENV{'form.student'} ne '');
428: } elsif ($command eq 'viewgrades') {
429: $request->print(&viewgrades($request));
430: } elsif ($command eq 'editgrades') {
431: $request->print(&editgrades($request));
432: } else {
433: $request->print("Unknown action:$command:");
434: }
435: }
436: &send_footer($request);
437: return OK;
438: }
439:
440: 1;
441:
442: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>