Annotation of loncom/interface/lonquickgrades.pm, revision 1.117
1.1 bowersj2 1: # The LearningOnline Network with CAPA
2: # Quick Student Grades Display
3: #
1.117 ! raeburn 4: # $Id: lonquickgrades.pm,v 1.116 2020/05/25 04:17:47 raeburn Exp $
1.1 bowersj2 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::lonquickgrades;
30:
31: use strict;
1.104 musolffc 32: use Apache::Constants qw(:common :http REDIRECT);
1.5 bowersj2 33: use POSIX;
1.25 www 34: use Apache::loncommon;
35: use Apache::lonlocal;
1.36 albertel 36: use Apache::lonnet;
1.38 bowersj2 37: use Apache::grades;
1.100 www 38: use Apache::loncoursedata;
1.101 www 39: use Apache::lonstudentassessment;
1.107 raeburn 40: use Apache::lonuserstate;
1.1 bowersj2 41:
1.102 www 42: use Time::HiRes;
43: use Spreadsheet::WriteExcel;
44: use Spreadsheet::WriteExcel::Utility();
45: #
46: # Excel data
47: #
48: my $excel_sheet;
49: my $excel_workbook;
50: my $filename;
51: my $format;
52: my $request_aborted;
53: my $header_row;
54: my $cols_output;
55: my %prog_state;
56:
57:
1.1 bowersj2 58: sub handler {
59: my $r = shift;
1.5 bowersj2 60: return real_handler($r);
61: }
62:
63: sub real_handler {
64: my $r = shift;
1.1 bowersj2 65:
66: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
67:
68: # Handle header-only request
1.40 albertel 69: if ($env{'browser.mathml'}) {
70: &Apache::loncommon::content_type($r,'text/xml');
71: } else {
72: &Apache::loncommon::content_type($r,'text/html');
73: }
1.1 bowersj2 74: if ($r->header_only) {
1.40 albertel 75: $r->send_http_header;
1.1 bowersj2 76: return OK;
77: }
78:
1.106 raeburn 79: my $cangrade=&Apache::lonnet::allowed('mgr');
1.111 raeburn 80: my $showPoints =
81: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard')
82: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'));
83:
84: my $reinitresult;
1.106 raeburn 85:
1.117 ! raeburn 86: if ($env{'request.course.id'}) {
! 87: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 88: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 89: my ($blocked,$blocktext) =
! 90: &Apache::loncommon::blocking_status('grades',$cnum,$cdom);
! 91: if ($blocked) {
! 92: my $checkrole = "cm./$cdom/$cnum";
! 93: if ($env{'request.course.sec'} ne '') {
! 94: $checkrole .= "/$env{'request.course.sec'}";
! 95: }
! 96: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
! 97: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
! 98: &grades_blocked($r,$blocktext,$showPoints);
! 99: return OK;
! 100: }
! 101: }
! 102: }
! 103:
1.106 raeburn 104: unless ($cangrade) {
105: # Check for critical messages and redirect if present.
1.110 raeburn 106: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'grades');
1.106 raeburn 107: if ($redirect) {
108: &Apache::loncommon::content_type($r,'text/html');
109: $r->header_out(Location => $url);
110: return REDIRECT;
111: }
112:
113: # Check if course needs to be re-initialized
114: my $loncaparev = $r->dir_config('lonVersion');
1.111 raeburn 115: ($reinitresult,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
1.106 raeburn 116:
1.111 raeburn 117: if ($reinitresult eq 'switch') {
1.106 raeburn 118: &Apache::loncommon::content_type($r,'text/html');
119: $r->send_http_header;
120: $r->print(&Apache::loncommon::check_release_result(@reinit));
121: return OK;
1.111 raeburn 122: } elsif ($reinitresult eq 'update') {
123: my $cid = $env{'request.course.id'};
124: my $cnum = $env{'course.'.$cid.'.num'};
125: my $cdom = $env{'course.'.$cid.'.domain'};
126: &Apache::loncommon::content_type($r,'text/html');
127: $r->send_http_header;
128: &startpage($r,$showPoints);
129: my $preamble = '<div id="LC_update_'.$cid.'" class="LC_info">'.
130: '<br />'.
131: &mt('Your course session is being updated because of recent changes by course personnel.').
132: ' '.&mt('Please be patient.').'<br /></div>'.
133: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
134: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
135: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
136: $r->rflush();
1.106 raeburn 137: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.111 raeburn 138: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished'));
139: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
140: my $closure = <<ENDCLOSE;
141: <script type="text/javascript">
142: // <![CDATA[
143: \$("#LC_update_$cid").hide('slow');
144: // ]]>
145: </script>
146: ENDCLOSE
1.106 raeburn 147: if ($ferr) {
1.111 raeburn 148: $r->print($closure.&Apache::loncommon::end_page());
1.106 raeburn 149: my $requrl = $r->uri;
150: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
151: $env{'user.reinit'} = 1;
152: return HTTP_NOT_ACCEPTABLE;
1.111 raeburn 153: } else {
154: $r->print($closure);
1.106 raeburn 155: }
1.109 raeburn 156: } elsif ((&Apache::loncommon::course_type() eq 'Placement') &&
157: (!$env{'request.role.adv'})) {
158: my $furl = &Apache::lonpageflip::first_accessible_resource();
159: &Apache::loncommon::content_type($r,'text/html');
160: $r->header_out(Location => $furl);
161: return REDIRECT;
1.106 raeburn 162: }
1.105 raeburn 163: }
164:
1.111 raeburn 165: unless ($reinitresult eq 'update') {
166: # Send header, don't cache this page
167: &Apache::loncommon::no_cache($r);
168: $r->send_http_header;
169: &startpage($r,$showPoints);
170: }
171: $r->rflush();
1.1 bowersj2 172:
1.55 www 173: &startGradeScreen($r,'quick');
1.17 bowersj2 174:
1.74 www 175: #
176: # Pick student
177: #
1.54 www 178: my $uname;
179: my $udom;
1.74 www 180: my $stdid;
181: if ($cangrade) {
1.101 www 182: $r->print("<h2>".&mt("Download Multiple")."</h2>".
183: '<table cellspacing="5">'."\n".
184: '<tr>'.
185: '<td align="center"><b>'.&mt('Sections').'</b>'.
186: &Apache::loncommon::help_open_topic("Chart_Sections").
187: '</td>'.
188: '<td align="center"><b>'.&mt('Groups').'</b>'.
189: '</td>'.
190: '<td align="center"><b>'.&mt('Student Data').'</b>'.
191: &Apache::loncommon::help_open_topic("Chart_Student_Data").
192: '</td>'.
193: '<td align="center"><b>'.&mt('Access Status').'</b>'.
194: &Apache::loncommon::help_open_topic("Chart_Enrollment_Status").
195: '</td>'.
196: '<td align="center"><b>'.&mt('Output Format').'</b>'.
197: &Apache::loncommon::help_open_topic("Chart_Output_Formats").
198: '</td><td> </td></tr>'."\n".
199: '<tr><td align="center">'."\n".
200: &Apache::lonstatistics::SectionSelect('Section','multiple',5).
201: '</td><td align="center">'.
202: &Apache::lonstatistics::GroupSelect('Group','multiple',5).
203: '</td><td align="center">'.
204: &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',5,undef).
205: '</td><td>'."\n".
206: &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
207: '</td><td>'."\n".
208: &Apache::lonstudentassessment::CreateAndParseOutputSelector().
209: '</td><td>'.
210: '<input type="submit" name="download" value="'.&mt('Display/Download Multiple Students').'" />'.
211: '</td></tr>'."\n".
212: '</table>'."\n"
213: );
214: $r->print("<hr /><h2>".&mt("Display Individual")."</h2>");
1.74 www 215: if ($env{'form.uname'}) { $uname=$env{'form.uname'}; }
216: if ($env{'form.udom'}) { $udom=$env{'form.udom'}; }
217: if ($env{'form.id'}) { $stdid=$env{'form.id'}; }
218: if (($stdid) && ($udom)) {
1.108 raeburn 219: $uname=(&Apache::lonnet::idget($udom,[$stdid],'ids'))[1];
1.74 www 220: }
1.75 www 221: if (($stdid) && (!$uname)) {
222: $r->print('<p><span class="LC_warning">'.&mt("Unknown Student/Employee ID: [_1]",$stdid).'</span></p>');
223: $stdid='';
224: }
1.74 www 225: $r->print('<form method="post" name="quickform" action="/adm/quickgrades">');
226: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
227: &Apache::loncommon::selectstudent_link('quickform','uname','udom');
228: $r->print("<p>\n".&Apache::loncommon::studentbrowser_javascript()."\n");
229: $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
230: ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
231: ,'<input type="text" value="'.$stdid.'" size="12" name="id" /> '
1.101 www 232: ,$chooseopt).
233: ' <input type="submit" name="display" value="'.&mt('Display Individual Student').'" /></p>');
1.75 www 234: if (($uname) && ($udom)) {
235: $r->print('<p>'.&mt('Full Name: [_1]',&Apache::loncommon::plainname($uname,$udom)).'</p>');
236: }
1.74 www 237: }
238: $r->rflush();
1.53 www 239:
1.111 raeburn 240: my $notshowSPRSlink =
241: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
242: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'));
243: my $notshowTotals=
244: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
245: my $showCategories=
246: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
247:
1.53 www 248: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
249: &getData($showPoints,$uname,$udom);
250:
251: if ($showCategories) {
252: &outputCategories($r,$showPoints,$notshowTotals,
253: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
254: } else {
255: &outputTable($r,$showPoints,$notshowTotals,
1.51 www 256: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
1.53 www 257: }
1.74 www 258: if ($cangrade) { $r->print("\n</form>\n"); }
1.55 www 259: &endGradeScreen($r);
1.51 www 260: return OK;
261:
262: }
1.2 bowersj2 263:
1.117 ! raeburn 264: sub grades_blocked {
! 265: my ($r,$blocktext,$caller) = @_;
! 266: my $title = 'Points Display';
! 267: if ($caller eq 'spreadsheet') {
! 268: $title = 'Spreadsheet';
! 269: } elsif ($env{'course.'.$env{'request.course.id'}.'.grading'} ne 'standard') {
! 270: $title = 'Completed Problems Display';
! 271: }
! 272: my $brcrum = [{href=>"/adm/quickgrades",text => $title}];
! 273: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 274: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/quickgrades',
! 275: text=> $title});
! 276: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title);
! 277: &Apache::loncommon::content_type($r,'text/html');
! 278: &Apache::loncommon::no_cache($r);
! 279: $r->send_http_header;
! 280: $r->print(&Apache::loncommon::start_page($title).
! 281: $breadcrumbs.
! 282: $blocktext.
! 283: &Apache::loncommon::end_page());
! 284: return;
! 285: }
! 286:
1.99 www 287: sub getStudentCatGrade {
288: my ($uname,$udom,%categories)=@_;
289: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
290: &getData(1,$uname,$udom);
291: return &output_category_table(undef,0,$navmap,0,%categories);
292: }
293:
294: sub getAllStudentData {
295: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
296: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.100 www 297:
1.99 www 298: my %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum);
1.100 www 299:
300: my $classlist = &Apache::loncoursedata::get_classlist();
301:
302: my $statusidx = &Apache::loncoursedata::CL_STATUS();
303: my $usernameidx = &Apache::loncoursedata::CL_SNAME();
304: my $domainidx = &Apache::loncoursedata::CL_SDOM();
305: my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
306:
307: foreach my $key (keys(%{$classlist})) {
308: my $student = $classlist->{$key};
309: my $perc=&getStudentCatGrade($classlist->{$student}->[$usernameidx],
310: $classlist->{$student}->[$domainidx],
311: %categories);
312: }
1.99 www 313: }
314:
1.111 raeburn 315: sub startpage {
316: my ($r,$showPoints) = @_;
317: my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
318: my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
319: $r->print(&Apache::loncommon::start_page($title,undef,
320: {'bread_crumbs' => $brcrum})
321: );
322: }
1.99 www 323:
1.55 www 324: sub startGradeScreen {
325: my ($r,$mode)=@_;
326:
327: my $showPoints =
328: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
329: my $notshowSPRSlink =
330: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
331: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')
332: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'));
333: my $notshowTotals=
334: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
335: my $showCategories=
336: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
1.115 raeburn 337:
338: my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
339: if ((!$allowed_to_view) && ($env{'request.course.sec'} ne '')) {
340: $allowed_to_view = &Apache::lonnet::allowed('vgr',
341: "$env{'request.course.id'}/$env{'request.course.sec'}");
342: }
1.55 www 343:
1.115 raeburn 344: my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
1.116 raeburn 345: if ((!$allowed_to_edit) && ($env{'request.course.sec'} ne '')) {
1.115 raeburn 346: $allowed_to_edit = &Apache::lonnet::allowed('mgr',
347: "$env{'request.course.id'}/$env{'request.course.sec'}");
348: }
1.55 www 349:
350: if ($allowed_to_view) {
1.61 raeburn 351: my @notes;
352: push(@notes,&mt('Students do not see total points.')) if ($notshowTotals);
353: push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink);
354: push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints);
355: push(@notes,&mt('Students will see points based on categories.')) if ($showCategories);
356: push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
357: $r->print(&Apache::loncommon::head_subbox(join(' ',@notes)));
1.55 www 358: }
359:
360:
1.56 www 361: $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
1.57 www 362: $r->print("\n".'<li'.($mode eq 'quick'?' class="active"':'').'><a href="/adm/quickgrades"><b> '.
1.62 www 363: ($showPoints?&mt('Individual Points Overview'):($showCategories?&mt('Grades Overview'):&mt('Completion Overview'))).
1.57 www 364: ' </b></a></li>');
1.55 www 365:
366: if (!($showPoints || $notshowSPRSlink) || ($allowed_to_view)) {
1.56 www 367: $r->print("\n".'<li'.($mode eq 'spreadsheet'?' class="active"':'').'><a href="/adm/'.($allowed_to_view?'classcalc':'studentcalc').'"><b>'.
1.57 www 368: &mt('Spreadsheet (Detailed)').'</b></a></li>');
1.55 www 369: }
1.58 www 370: if ($allowed_to_view) {
1.63 www 371: $r->print("\n".'<li'.($mode eq 'statistics'?' class="active"':'').'><a href="/adm/statistics"><b>'.
372: &mt('Statistics and Reports').'</b></a></li>');
373:
1.58 www 374: $r->print("\n".'<li'.($mode eq 'chart'?' class="active"':'').'><a href="/adm/statistics?reportSelected=student_assessment"><b>'.
1.113 raeburn 375: &mt('Assessment Chart').'</b></a></li>');
1.58 www 376:
377: }
1.59 www 378: if ($allowed_to_edit) {
379: $r->print("\n".'<li'.($mode eq 'grading'?' class="active"':'').'><a href="/adm/grades"><b> '.
1.66 www 380: &mt('Content Grading').' </b></a></li>');
381: if ($env{'form.symb'}) {
382: $r->print("\n".'<li'.($mode eq 'probgrading'?' class="active"':'').'><a href="/adm/grades?symb='.
383: &Apache::lonhtmlcommon::entity_encode($env{'form.symb'}).
1.103 raeburn 384: '&command=gradingmenu"><b> '.
1.66 www 385: &mt('Problem Grading').' </b></a></li>');
386:
387: }
1.59 www 388: }
1.56 www 389: $r->print("\n".'</ul>'."\n");
1.55 www 390: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
391: }
392:
393: sub endGradeScreen {
394: my ($r)=@_;
1.72 www 395: $r->print('</div></div></div>'.&Apache::loncommon::end_page());
1.55 www 396: }
397:
1.102 www 398: # -----------
399:
400:
401: sub excel_cleanup {
402: undef ($excel_sheet);
403: undef ($excel_workbook);
404: undef ($filename);
405: undef ($format);
406: }
407:
408:
409: sub excel_initialize {
410: my ($r) = @_;
411:
412: &excel_cleanup();
413:
414: # Create sheet
415: ($excel_workbook,$filename,$format)=
416: &Apache::loncommon::create_workbook($r);
417: return if (! defined($excel_workbook));
418: #
419: # Add a worksheet
420: my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
421: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
422: $excel_sheet = $excel_workbook->addworksheet($sheetname);
423: #
424: # Put the course description in the header
425: $excel_sheet->write($header_row,$cols_output++,
426: $env{'course.'.$env{'request.course.id'}.'.description'},
427: $format->{'h1'});
428: }
429:
430: sub excel_finish {
431: my ($r) = @_;
432: if ($request_aborted || ! defined($excel_sheet)) {
433: &excel_cleanup();
434: return;
435: }
436: #
437: # Write the excel file
438: $excel_workbook->close();
439: #
440: # Close the progress window
441: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
442: #
443: # Tell the user where to get their excel file
444: $r->print('<br />'.
445: '<a href="'.$filename.'">'.&mt('Your Excel spreadsheet').'</a>'."\n");
446: $r->rflush();
447: &excel_cleanup();
448: return;
449: }
450:
451:
452: #
453: # CSV data
454: #
455: # -----------
456:
457: #
458: # Go through the complete course and collect data
459: #
1.55 www 460:
1.51 www 461: sub getData {
462:
1.53 www 463: my ($showPoints,$uname,$udom)=@_;
464:
1.51 www 465: # Create the nav map
1.53 www 466: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
1.51 www 467:
468: my $res = $navmap->firstResource(); # temp resource to access constants
1.1 bowersj2 469:
470: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
471: my $depth = 1;
472: $iterator->next(); # ignore first BEGIN_MAP
473: my $curRes = $iterator->next();
1.4 bowersj2 474:
1.5 bowersj2 475: # General overview of the following: Walk along the course resources.
476: # For every problem in the resource, tell its parent maps how many
477: # parts and how many parts correct it has. After that, each map will
478: # have a count of the total parts underneath it, correct and otherwise.
479: # After that, we will walk through the course again and read off
480: # maps in order, with their data.
481: # (If in the future people decide not to be cumulative, only add
482: # the counts to the parent map.)
1.17 bowersj2 483: # For convenience, "totalParts" is also "totalPoints" when we're looking
484: # at points; I can't come up with a variable name that makes sense
485: # equally for both cases.
1.5 bowersj2 486:
487: my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
1.28 bowersj2 488: my $totalAttempted = 0;
1.14 bowersj2 489: my $now = time();
1.28 bowersj2 490: my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
1.5 bowersj2 491:
492: # Pre-run: Count parts correct
1.1 bowersj2 493: while ( $depth > 0 ) {
494: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
495: if ($curRes == $iterator->END_MAP()) { $depth--; }
496:
1.114 raeburn 497: if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout &&
498: ($curRes->deeplink ne 'absent'))
1.5 bowersj2 499: {
500: # Get number of correct, incorrect parts
501: my $parts = $curRes->parts();
502: my $partsRight = 0;
1.17 bowersj2 503: my $partsCount = 0;
1.28 bowersj2 504: my $partsAttempted = 0;
1.5 bowersj2 505: my $stack = $iterator->getStack();
506:
507: for my $part (@{$parts}) {
1.28 bowersj2 508: my $dateStatus = $curRes->getDateStatus($part);
1.97 www 509: my $weight = $curRes->weight($part);
510: my $problemstatus = $curRes->problemstatus($part);
511:
1.98 www 512: if ($curRes->solved($part) eq 'excused') {
1.21 matthew 513: next;
514: }
1.17 bowersj2 515: if ($showPoints) {
1.28 bowersj2 516: my $score = 0;
517: # If we're not telling status and the answer date isn't passed yet,
518: # it's an "attempted" point
1.97 www 519: if ((($problemstatus eq 'no') ||
520: ($problemstatus eq 'no_feedback_ever')) &&
1.28 bowersj2 521: ($dateStatus != $curRes->ANSWER_OPEN)) {
1.31 albertel 522: my $status = $curRes->simpleStatus($part);
523: if ($status == $curRes->ATTEMPTED) {
1.97 www 524: $partsAttempted += $weight;
1.31 albertel 525: $totalAttempted += $partsAttempted;
526: }
1.28 bowersj2 527: } else {
1.97 www 528: $score = &Apache::grades::compute_points($weight, $curRes->awarded($part));
1.28 bowersj2 529: }
1.17 bowersj2 530: $partsRight += $score;
531: $totalRight += $score;
1.97 www 532: $partsCount += $weight;
1.18 bowersj2 533:
1.83 www 534: $curRes->{DATA}->{PROB_SCORE} += $score;
1.97 www 535: $curRes->{DATA}->{PROB_WEIGHT} += $weight;
1.83 www 536:
1.17 bowersj2 537: if ($curRes->opendate($part) < $now) {
1.97 www 538: $totalPossible += $weight;
539: $curRes->{DATA}->{PROB_POSSIBLE} += $weight;
1.17 bowersj2 540: }
1.97 www 541: $totalParts += $weight;
1.17 bowersj2 542: } else {
1.27 bowersj2 543: my $status = $curRes->simpleStatus($part);
1.17 bowersj2 544: my $thisright = 0;
545: $partsCount++;
1.37 albertel 546: if ($status == $curRes->CORRECT ||
547: $status == $curRes->PARTIALLY_CORRECT ) {
1.17 bowersj2 548: $partsRight++;
549: $totalRight++;
550: $thisright = 1;
551: }
1.28 bowersj2 552:
553: if ($status == $curRes->ATTEMPTED) {
554: $partsAttempted++;
555: $totalAttempted++;
556: }
1.17 bowersj2 557:
1.19 bowersj2 558: $totalParts++;
1.17 bowersj2 559: if ($curRes->opendate($part) < $now) {
560: $totalPossible++;
561: }
562: }
1.5 bowersj2 563: }
1.15 bowersj2 564:
565: if ($depth == 1) { # in top-level only
1.19 bowersj2 566: $topLevelParts += $partsCount;
1.15 bowersj2 567: $topLevelRight += $partsRight;
1.28 bowersj2 568: $topLevelAttempted += $partsAttempted;
1.15 bowersj2 569: }
570:
1.5 bowersj2 571: # Crawl down stack and record parts correct and total
572: for my $res (@{$stack}) {
573: if (ref($res) && $res->is_map()) {
574: if (!defined($res->{DATA}->{CHILD_PARTS})) {
575: $res->{DATA}->{CHILD_PARTS} = 0;
576: $res->{DATA}->{CHILD_CORRECT} = 0;
1.28 bowersj2 577: $res->{DATA}->{CHILD_ATTEMPTED} = 0;
1.5 bowersj2 578: }
579:
1.17 bowersj2 580: $res->{DATA}->{CHILD_PARTS} += $partsCount;
1.5 bowersj2 581: $res->{DATA}->{CHILD_CORRECT} += $partsRight;
1.28 bowersj2 582: $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
1.5 bowersj2 583: }
584: }
585: }
586: $curRes = $iterator->next();
587: }
1.51 www 588: return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
589: }
590:
591: #
592: # Outputting everything.
593: #
594:
595: sub outputTable {
1.5 bowersj2 596:
1.51 www 597: my ($r,$showPoints,$notshowTotals,
598: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
1.5 bowersj2 599:
1.7 bowersj2 600: my @start = (255, 255, 192);
1.5 bowersj2 601: my @end = (0, 192, 0);
602:
603: my $indentString = ' ';
604:
605: # Second pass: Print the maps.
1.43 bisitz 606: $r->print(&Apache::loncommon::start_data_table()
607: .&Apache::loncommon::start_data_table_header_row()
608: .'<th>'.&mt('Folder').'</th>');
1.51 www 609: my $title = &mt($showPoints ? "Points Scored" : "Done");
1.28 bowersj2 610: if ($totalAttempted) {
1.51 www 611: $title .= " / " . &mt("Attempted");
1.28 bowersj2 612: }
1.49 www 613: $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
1.43 bisitz 614: .&Apache::loncommon::end_data_table_header_row());
1.51 www 615: #
616: # Output of folder scores
617: #
618:
619: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
620: my $depth = 1;
621: $iterator->next(); # ignore first BEGIN_MAP
622: my $curRes = $iterator->next();
623:
1.5 bowersj2 624: while ($depth > 0) {
625: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
626: if ($curRes == $iterator->END_MAP()) { $depth--; }
627:
628: if (ref($curRes) && $curRes->is_map()) {
629: my $title = $curRes->compTitle();
630:
631: my $correct = $curRes->{DATA}->{CHILD_CORRECT};
632: my $total = $curRes->{DATA}->{CHILD_PARTS};
1.28 bowersj2 633: my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
1.5 bowersj2 634:
1.6 bowersj2 635: if ($total > 0) {
636: my $ratio;
637: $ratio = $correct / $total;
1.51 www 638: my $color = &mixColors(\@start, \@end, $ratio);
1.43 bisitz 639: $r->print(&Apache::loncommon::start_data_table_row()
640: .'<td style="background-color:'.$color.';">');
1.6 bowersj2 641:
1.15 bowersj2 642: my $thisIndent = '';
643: for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
1.6 bowersj2 644:
1.15 bowersj2 645: $r->print("$thisIndent$title</td>");
1.28 bowersj2 646: if ($totalAttempted) {
1.45 bisitz 647: $r->print('<td valign="top">'
648: .$thisIndent
649: .'<span class="LC_nobreak">'
1.49 www 650: .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
1.45 bisitz 651: .'</span></td>'
652: .&Apache::loncommon::end_data_table_row()
653: );
1.28 bowersj2 654: } else {
1.45 bisitz 655: $r->print('<td valign="top">'
656: .$thisIndent
657: .'<span class="LC_nobreak">'
1.49 www 658: .$correct.($notshowTotals?'':' / '.$total)
1.45 bisitz 659: .'</span></td>'
1.43 bisitz 660: .&Apache::loncommon::end_data_table_row());
1.28 bowersj2 661: }
1.6 bowersj2 662: }
1.5 bowersj2 663: }
1.4 bowersj2 664:
1.5 bowersj2 665: $curRes = $iterator->next();
666: }
1.4 bowersj2 667:
1.6 bowersj2 668: # If there were any problems at the top level, print an extra "catchall"
1.15 bowersj2 669: if ($topLevelParts > 0) {
670: my $ratio = $topLevelRight / $topLevelParts;
1.68 www 671: my $color = &mixColors(\@start, \@end, $ratio);
1.43 bisitz 672: $r->print(&Apache::loncommon::start_data_table_row()
673: .'<td style="background-color:'.$color.';">');
1.25 www 674: $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
1.43 bisitz 675: $r->print("$topLevelRight / $topLevelParts</td>"
676: .&Apache::loncommon::end_data_table_row());
1.6 bowersj2 677: }
1.4 bowersj2 678:
1.51 www 679: #
680: # show totals (if applicable), close table
681: #
1.35 albertel 682: if ($showPoints) {
1.68 www 683: my $maxHelpLink = &Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
1.2 bowersj2 684:
1.51 www 685: $title = $showPoints ? "Points" : "Parts Done";
686: my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
687: $r->print(&Apache::loncommon::start_data_table_row()
1.48 bisitz 688: .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
1.51 www 689: $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
690: $title = $showPoints ? "Points" : "Parts";
691: $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
1.43 bisitz 692: .&Apache::loncommon::end_data_table_row());
1.34 www 693: }
1.1 bowersj2 694:
1.72 www 695: $r->print(&Apache::loncommon::end_data_table());
1.5 bowersj2 696: }
697:
1.53 www 698: #
1.65 www 699: # === Outputting category-based grades.
700: #
701: # $category{'order'}: output order of categories by id
702: # $category{'all'}: complete list of all categories
703: # $category{$id.'_name'}: display-name of category
1.53 www 704: #
705:
706: sub outputCategories {
707:
708: my ($r,$showPoints,$notshowTotals,
709: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
1.62 www 710: # Take care of storing and retrieving categories
711:
1.64 www 712: my $cangrade=&Apache::lonnet::allowed('mgr');
713:
1.62 www 714: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
715: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.64 www 716: my %categories=();
1.65 www 717: # Loading old categories
718: %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum);
1.64 www 719: # Storing
1.72 www 720: if (($cangrade) && (($env{'form.storechanges'}) || ($env{'form.storemove'} ne '') || ($env{'form.cmd'} ne ''))) {
1.65 www 721: # Process the changes
722: %categories=&process_category_edits($r,$cangrade,%categories);
1.64 www 723: # Actually store
724: &Apache::lonnet::put('grading_categories',\%categories,$cdom,$cnum);
725: }
1.65 www 726: # new categories loaded now
1.99 www 727: &output_category_table($r,$cangrade,$navmap,1,%categories);
1.65 www 728: #
729: if ($cangrade) {
1.84 www 730: $r->print(&Apache::loncommon::resourcebrowser_javascript().
731: '<input type="hidden" name="storemove" value="" />'.
1.72 www 732: '<input type="hidden" name="cmd" value="" />'.
1.86 www 733: '<input type="hidden" name="resourcesymb" value="" />'.
1.72 www 734: '<input type="submit" name="storechanges" value="'.&mt("Save changes to grading categories").'" />'.
1.74 www 735: '<script>function storecmd (cmd) { document.quickform.cmd.value=cmd; document.quickform.submit(); }</script>');
1.65 www 736: }
1.82 www 737: }
738:
739: #
740: # Get data for all symbs
741: #
742:
743: sub dumpdata {
744: my ($navmap)=@_;
745: my %returndata=();
746:
747: # Run through the map and get all data
748:
749: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
750: my $depth = 1;
751: $iterator->next(); # ignore first BEGIN_MAP
752: my $curRes = $iterator->next();
753:
754: while ($depth > 0) {
755: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
756: if ($curRes == $iterator->END_MAP()) { $depth--; }
1.83 www 757: if (ref($curRes)) {
758: if ($curRes->is_map()) {
759: $returndata{$curRes->symb()}='folder:'.$curRes->{DATA}->{CHILD_PARTS}.':'.$curRes->{DATA}->{CHILD_ATTEMPTED}.':'.$curRes->{DATA}->{CHILD_CORRECT};
760: } else {
761: $returndata{$curRes->symb()}='res:'.$curRes->{DATA}->{PROB_WEIGHT}.':'.$curRes->{DATA}->{PROB_POSSIBLE}.':'.$curRes->{DATA}->{PROB_SCORE};
762: }
1.82 www 763: }
764: $curRes = $iterator->next();
765: }
766: return %returndata;
1.65 www 767: }
768:
769: #
770: # Process editing commands, update category hash
771: #
772:
773: sub process_category_edits {
774: my ($r,$cangrade,%categories)=@_;
775: unless ($cangrade) { return %categories; }
1.72 www 776: # First store everything
777: foreach my $id (split(/\,/,$categories{'order'})) {
1.80 www 778: # Set names, types, and weight (there is only one of each per category)
1.72 www 779: %categories=&set_category_name($cangrade,$id,$env{'form.name_'.$id},%categories);
780: %categories=&set_category_total($cangrade,$id,$env{'form.totaltype_'.$id},$env{'form.total_'.$id},%categories);
781: %categories=&set_category_weight($cangrade,$id,$env{'form.weight_'.$id},%categories);
1.81 www 782: %categories=&set_category_displayachieved($cangrade,$id,$env{'form.displayachieved_'.$id},%categories);
1.80 www 783: # Set values for category rules (before names may change)
784: %categories=&set_category_rules($cangrade,$id,%categories);
1.72 www 785: }
786:
787: # Now deal with commands
1.67 www 788: my $cmd=$env{'form.cmd'};
789: if ($cmd eq 'createnewcat') {
1.69 www 790: %categories=&make_new_category($r,$cangrade,undef,%categories);
1.72 www 791: } elsif ($cmd=~/^up\_(.+)$/) {
792: %categories=&move_up_category($1,$cangrade,%categories);
793: } elsif ($cmd=~/^down\_(.+)$/) {
794: %categories=&move_down_category($1,$cangrade,%categories);
1.69 www 795: } elsif ($cmd=~/^delcat\_(.+)$/) {
796: %categories=&del_category($1,$cangrade,%categories);
1.75 www 797: } elsif ($cmd=~/^addcont\_(.+)$/) {
1.87 www 798: %categories=&add_category_content($1,$cangrade,$env{'form.resourcesymb'},%categories);
1.75 www 799: } elsif ($cmd=~/^delcont\_(.+)\_\_\_\_\_\_(.+)$/) {
800: %categories=&del_category_content($1,$cangrade,$2,%categories);
1.77 www 801: } elsif ($cmd=~/^newrule\_(.+)$/) {
802: %categories=&add_calculation_rule($1,$cangrade,':',%categories);
1.79 www 803: } elsif ($cmd=~/^delrule\_(.+)\_\_\_\_\_\_(.*)$/) {
804: %categories=&del_calculation_rule($1,$cangrade,$2,%categories);
1.73 www 805: }
806: # Move to a new position
807: my $moveid=$env{'form.storemove'};
808: if ($moveid) {
809: %categories=&move_category($moveid,$cangrade,$env{'form.newpos_'.$moveid},%categories);
1.72 www 810: }
1.65 www 811: return %categories;
812: }
813:
814: #
815: # Output the table
816: #
817:
818: sub output_category_table {
1.99 www 819: my ($r,$cangrade,$navmaps,$output,%categories)=@_;
1.96 www 820:
821: my $totalweight=0;
822: my $totalpoints=0;
823:
1.99 www 824: if ($output) {
825: $r->print(&Apache::loncommon::start_data_table());
1.65 www 826: #
1.99 www 827: &output_category_table_header($r,$cangrade);
828: }
1.65 www 829: #
830: my @order=split(/\,/,$categories{'order'});
831: #
1.88 www 832: my %performance=&dumpdata($navmaps);
1.65 www 833: my $maxpos=$#order;
834: for (my $i=0;$i<=$maxpos;$i++) {
1.99 www 835: my ($correct,$possible,$type,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,\%performance,$output,%categories);
1.96 www 836: unless ($possible) { next; }
837: $totalpoints+=$weight*$correct/$possible;
838: $totalweight+=$weight;
1.65 www 839: }
840: #
1.96 www 841: my $perc=0;
842: if ($totalweight) { $perc=100.*$totalpoints/$totalweight; }
843:
1.99 www 844: if ($output) {
845: &bottom_line_category($r,$cangrade,$perc);
846: $r->print(&Apache::loncommon::end_data_table());
847: }
1.96 www 848: return $perc;
1.65 www 849: }
850:
851: sub output_category_table_header {
852: my ($r,$cangrade)=@_;
853: $r->print(&Apache::loncommon::start_data_table_header_row());
854: if ($cangrade) {
855: $r->print('<th colspan="2">'.&mt("Move").'</th><th>'.&mt('Action').'</th>');
856: }
857: $r->print('<th>'.&mt('Category').'</th>'.
858: '<th>'.&mt('Contents').'</th>'.
1.81 www 859: '<th>'.&mt('Total Points').'</th>'.
1.65 www 860: '<th>'.&mt('Calculation').'</th>'.
1.81 www 861: '<th>'.&mt('Relative Weight').'</th>'.
862: '<th>'.&mt('Achieved').'</th>');
1.65 www 863: $r->print(&Apache::loncommon::end_data_table_header_row());
864: }
865:
866:
867: #
868: # Output one category to table
869: #
870:
871: sub output_and_calc_category {
1.89 www 872: my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,$performance,$output,%categories)=@_;
1.99 www 873:
874: if ($output) { $r->print("\n".&Apache::loncommon::start_data_table_row()); }
1.95 www 875:
1.99 www 876: if ($output && $cangrade) {
877: my $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
878: my %lt=&Apache::lonlocal::texthash(
1.65 www 879: 'up' => 'Move Up',
880: 'dw' => 'Move Down');
881:
882: $r->print(<<ENDMOVE);
883: <td>
884: <div class="LC_docs_entry_move">
1.72 www 885: <a href='javascript:storecmd("up_$id");'>
1.65 www 886: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
887: </a>
888: </div>
889: <div class="LC_docs_entry_move">
1.72 www 890: <a href='javascript:storecmd("down_$id");'>
1.65 www 891: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
892: </a>
893: </div>
894: </td>
895: ENDMOVE
896: $r->print("\n<td>\n<select name='newpos_$id' onchange='this.form.storemove.value=\"$id\";this.form.submit()'>");
897: for (my $i=0;$i<=$maxpos;$i++) {
898: if ($i==$currentpos) {
899: $r->print('<option value="" selected="selected">('.$i.')</option>');
900: } else {
901: $r->print('<option value="'.$i.'">'.$i.'</option>');
902: }
903: }
904: $r->print("\n</select>\n</td>\n");
1.72 www 905: $r->print('<td><a href="javascript:storecmd(\'delcat_'.$id.'\');">'.&mt('Delete').'</a></td>');
1.69 www 906: $r->print('<td><input type="text" name="name_'.$id.
907: '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_name'}).'" /></td>');
1.89 www 908: } elsif ($output) {
1.69 www 909: $r->print('<td>'.$categories{$id.'_name'}.'</td>');
1.65 www 910: }
1.89 www 911: # Content display and summing up of points
912: my $totalpossible=0;
913: my $totalcorrect=0;
1.91 www 914: my @individual=();
1.89 www 915: if ($output) { $r->print('<td><ul>'); }
1.75 www 916: foreach my $contentid (split(/\,/,$categories{$id.'_content'})) {
1.89 www 917: my ($type,$possible,$attempted,$correct)=split(/\:/,$$performance{$contentid});
918: $totalpossible+=$possible;
919: $totalcorrect+=$correct;
1.91 www 920: if ($possible>0) { push(@individual,"$possible:$correct"); }
1.89 www 921: if ($output) {
922: $r->print('<li>');
1.96 www 923: $r->print(&Apache::lonnet::gettitle($contentid).' ('.&numberout($correct).'/'.&numberout($possible).')');
1.89 www 924: if ($cangrade) {
925: $r->print(' <a href="javascript:storecmd(\'delcont_'.$id.'______'.$contentid.'\');">'.&mt('Delete').'</a>');
926: }
927: $r->print('</li>');
1.75 www 928: }
929: }
1.89 www 930: if ($output) {
931: $r->print('</ul>');
932: if ($cangrade) {
933: $r->print('<br />'.&Apache::loncommon::selectresource_link('quickform','addcont_'.$id,&mt('Add Problem or Folder')).'<br />');
934: }
1.96 www 935: $r->print('<p><b>'.&mt('Total raw points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'</b></p>');
1.89 www 936: $r->print('</td>');
1.70 www 937: }
1.81 www 938: # Total
1.90 www 939: if ($output) { $r->print('<td>'); }
1.81 www 940: if ($cangrade) {
1.89 www 941: if ($output) {
1.90 www 942: $r->print(
1.81 www 943: '<select name="totaltype_'.$id.'">'.
944: '<option value="default"'.($categories{$id.'_totaltype'} eq 'default'?' selected="selected"':'').'>'.&mt('default').'</option>'.
945: '<option value="typein"'.($categories{$id.'_totaltype'} eq 'typein'?' selected="selected"':'').'>'.&mt('Type-in value').'</option>'.
946: '</select>'.
947: '<input type="text" size="4" name="total_'.$id.
1.90 www 948: '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_total'}).'" />');
1.89 www 949: }
1.81 www 950: } else {
1.89 www 951: if ($output) {
1.90 www 952: $r->print('<td>'.($categories{$id.'_totaltype'} eq 'default'?&mt('default'):$categories{$id.'_total'}));
1.89 www 953: }
1.81 www 954: }
1.90 www 955: # Adjust total points
956: if ($categories{$id.'_totaltype'} eq 'typein') {
957: $totalpossible=1.*$categories{$id.'_total'};
958: }
959: if ($output) {
1.96 www 960: $r->print('<p><b>'.&mt('Adjusted raw points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'</b></p>');
1.90 www 961: }
1.81 www 962:
963:
1.70 www 964: # Calculation
1.89 www 965: if ($output) { $r->print('<td><ul>'); }
1.76 www 966: foreach my $calcrule (split(/\,/,$categories{$id.'_calculations'})) {
1.89 www 967: if ($output) { $r->print('<li>'); }
1.78 www 968: my ($code,$value)=split(/\:/,$calcrule);
1.89 www 969: if ($output) { $r->print(&pretty_prt_rule($cangrade,$id,$code,$value)); }
1.76 www 970: if ($cangrade) {
1.89 www 971: if ($output) { $r->print(' <a href="javascript:storecmd(\'delrule_'.$id.'______'.$code.'\');">'.&mt('Delete').'</a>'); }
1.76 www 972: }
1.91 www 973: if ($code eq 'capabove') {
974: if ($totalpossible>0) {
1.92 www 975: if ($totalcorrect/$totalpossible>$value/100.) {
976: $totalcorrect=$totalpossible*$value/100.;
1.91 www 977: }
978: }
979: } elsif ($code eq 'capbelow') {
980: if ($totalpossible>0) {
1.92 www 981: if ($totalcorrect/$totalpossible<$value/100.) {
982: $totalcorrect=$totalpossible*$value/100.;
1.91 www 983: }
984: }
1.92 www 985: } elsif ($code eq 'droplow') {
1.94 www 986: ($totalpossible,$totalcorrect,@individual)=&drop(0,0,$value,@individual);
1.92 www 987: } elsif ($code eq 'drophigh') {
1.94 www 988: ($totalpossible,$totalcorrect,@individual)=&drop(1,0,$value,@individual);
1.92 www 989: } elsif ($code eq 'droplowperc') {
1.94 www 990: ($totalpossible,$totalcorrect,@individual)=&drop(0,1,$value,@individual);
1.92 www 991: } elsif ($code eq 'drophighperc') {
1.94 www 992: ($totalpossible,$totalcorrect,@individual)=&drop(1,1,$value,@individual);
1.91 www 993: }
1.89 www 994: if ($output) { $r->print('</li>'); }
1.76 www 995: }
1.94 www 996: # Re-adjust total points if force total
997: if ($categories{$id.'_totaltype'} eq 'typein') {
998: $totalpossible=1.*$categories{$id.'_total'};
999: }
1000:
1.91 www 1001: if ($output) {
1.92 www 1002: $r->print('</ul>');
1003: if ($cangrade) { $r->print('<br />'.&new_calc_rule_form($id)); }
1.96 www 1004: $r->print('<p><b>'.&mt('Calculated points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'</b></p>');
1.92 www 1005: $r->print('</td>');
1.91 www 1006: }
1.95 www 1007: #
1008: # Prepare for export
1009: #
1.70 www 1010: # Weight
1.95 www 1011: my $weight=$categories{$id.'_weight'};
1012: unless (1.*$weight>0) { $weight=0; }
1.70 www 1013: if ($cangrade) {
1.89 www 1014: if ($output) {
1015: $r->print('<td>'.
1.70 www 1016: '<input type="text" size="4" name="weight_'.$id.
1.95 www 1017: '" value="'.&Apache::lonhtmlcommon::entity_encode($weight).'" /></td>');
1.89 www 1018: }
1.70 www 1019: } else {
1.89 www 1020: if ($output) {
1.95 www 1021: $r->print('<td>'.$weight.'</td>');
1.89 www 1022: }
1.70 www 1023: }
1.81 www 1024: # Achieved
1.95 www 1025: my $type=$categories{$id.'_displayachieved'};
1026: unless (($type eq 'percent') || ($type eq 'points')) { $type='points'; }
1.89 www 1027: if ($output) { $r->print('<td>'); }
1.81 www 1028: if ($cangrade) {
1.89 www 1029: if ($output) {
1030: $r->print('<select name="displayachieved_'.$id.'">'.
1.95 www 1031: '<option value="percent"'.($type eq 'percent'?' selected="selected"':'').'>'.&mt('percent').'</option>'.
1032: '<option value="points"'.($type eq 'points'?' selected="selected"':'').'>'.&mt('points').'</option>'.
1.81 www 1033: '</select>');
1.89 www 1034: }
1.95 www 1035: }
1036: if ($output) {
1.96 www 1037: $r->print('<p><b>');
1.95 www 1038: if ($type eq 'percent') {
1039: my $perc='---';
1040: if ($totalpossible) {
1041: $perc=100.*$totalcorrect/$totalpossible;
1.89 www 1042: }
1.96 www 1043: $r->print(&mt('[_1] percent',&numberout($perc)));
1.95 www 1044: } else {
1.96 www 1045: $r->print(&mt('[_1]/[_2] points',&numberout($totalcorrect),&numberout($totalpossible)));
1.81 www 1046: }
1.96 www 1047: $r->print('</b></p>');
1.81 www 1048: }
1.89 www 1049: if ($output) { $r->print('</td>'); }
1.70 www 1050:
1.95 www 1051: return ($totalcorrect,$totalpossible,$type,$weight);
1.65 www 1052: }
1053:
1054: #
1.92 www 1055: # Drop folders and problems
1056: #
1057:
1058: sub drop {
1.93 www 1059: my ($high,$percent,$n,@individual)=@_;
1.94 www 1060: # Sort assignments by points or percent
1.92 www 1061: my @newindividual=sort {
1062: my ($pa,$ca)=split(/\:/,$a);
1063: my ($pb,$cb)=split(/\:/,$b);
1064: if ($percent) {
1065: my $perca=0;
1066: if ($pa>0) { $perca=$ca/$pa; }
1067: my $percb=0;
1068: if ($pb>0) { $percb=$cb/$pb; }
1069: $perca<=>$percb;
1070: } else {
1071: $ca<=>$cb;
1072: }
1073: } @individual;
1.94 www 1074: # Drop the ones we don't want
1.93 www 1075: if ($#newindividual>=$n) {
1076: if ($high) {
1077: splice(@newindividual,$#newindividual+1-$n,$n);
1078: } else {
1079: splice(@newindividual,0,$n);
1080: }
1081: } else {
1082: @newindividual=();
1083: }
1.94 www 1084: # Re-calculate how many points possible and achieved
1085: my $newpossible=0;
1.92 www 1086: my $newcorrect=0;
1.93 www 1087: for my $score (@newindividual) {
1.94 www 1088: my ($thispossible,$thiscorrect)=(split(/\:/,$score));
1089: $newpossible+=$thispossible;
1090: $newcorrect+=$thiscorrect;
1.93 www 1091: }
1.94 www 1092: return ($newpossible,$newcorrect,@newindividual);
1.92 www 1093: }
1094: #
1.65 www 1095: # Bottom line with grades
1096: #
1097:
1098: sub bottom_line_category {
1.96 www 1099: my ($r,$cangrade,$perc)=@_;
1.67 www 1100: $r->print(&Apache::loncommon::start_data_table_row());
1101: if ($cangrade) {
1.72 www 1102: $r->print('<td colspan="3"><a href="javascript:storecmd(\'createnewcat\');">'.&mt('Create New Category').'</a></td>');
1.67 www 1103: }
1.96 www 1104: $r->print('<td colspan="6"><b>'.&mt('Total: [_1] percent',&numberout($perc)).'</b></td>');
1.65 www 1105: }
1106:
1.96 www 1107: sub numberout {
1108: my ($number)=@_;
1109: my $printout=sprintf("%.3f", $number);
1110: $printout=~s/0+$//;
1111: $printout=~s/\.$//;
1112: return $printout;
1113: }
1.65 www 1114: #
1115: # Make one new category
1116: #
1117:
1118: sub make_new_category {
1119: my ($r,$cangrade,$ordernum,%categories)=@_;
1120: unless ($cangrade) { return %categories; }
1121: # Generate new ID
1122: my $id=time.'_'.$$.'_'.rand(10000);
1123: # Add new ID to list of all IDs ever created in this course
1124: $categories{'all'}.=','.$id;
1125: $categories{'all'}=~s/^\,//;
1126: # Add new ID to ordered list of displayed and evaluated categories
1127: $categories{'order'}.=','.$id;
1128: $categories{'order'}=~s/^\,//;
1129: # Move it into desired space
1130: if (defined($ordernum)) {
1131: %categories=&move_category($id,$cangrade,$ordernum,%categories);
1132: }
1.71 www 1133: $categories{$id.'_weight'}=0;
1134: $categories{$id.'_totaltype'}='default';
1.81 www 1135: $categories{$id.'_displayachieved'}='percent';
1.65 www 1136: return %categories;
1.53 www 1137: }
1138:
1.76 www 1139:
1140: # === Calculation Rule Editing
1141:
1.80 www 1142: sub category_rule_codes {
1143: return &Apache::lonlocal::texthash(
1.91 www 1144: 'droplowperc' => 'Drop N lowest grade percentage problems/folders',
1145: 'drophighperc' => 'Drop N highest grade percentage problems/folderss',
1146: 'droplow' => 'Drop N lowest point problems/folders',
1147: 'drophigh' => 'Drop N highest point problems/folders',
1.78 www 1148: 'capabove' => 'Cap percentage above N percent',
1149: 'capbelow' => 'Cap percentage below N percent');
1.80 www 1150: }
1151:
1152: sub pretty_prt_rule {
1153: my ($cangrade,$id,$code,$value)=@_;
1154: my $cid=$id.'_'.$code;
1155: my %lt=&category_rule_codes();
1.78 www 1156: my $ret='<span class="LC_nobreak">';
1157: if ($cangrade) {
1158: $ret.='<select name="sel_'.$cid.'">';
1159: foreach my $calc (''=>'',sort(keys(%lt))) {
1160: $ret.='<option value="'.$calc.'"'.($calc eq $code?' selected="selected"':'').' />'.$lt{$calc}.'</input>';
1161: }
1.80 www 1162: $ret.='</select> N=<input type="text" size="5" name="val_'.$cid.'" value="'.$value.'" /></span>';
1.78 www 1163: } else {
1164: $ret.=$lt{$code}.'; N='.$value;
1165: }
1166: $ret.='</span>';
1167: return $ret;
1.76 www 1168: }
1169:
1170: sub new_calc_rule_form {
1.77 www 1171: my ($id)=@_;
1172: return '<a href="javascript:storecmd(\'newrule_'.$id.'\');">'.&mt('New Calculation Rule').'</a>';
1.76 www 1173: }
1174:
1175: #
1176: # Add a calculation rule
1177: #
1178:
1179: sub add_calculation_rule {
1180: my ($id,$cangrade,$newcontent,%categories)=@_;
1181: unless ($cangrade) { return %categories; }
1182: my %newcontent=($newcontent => 1);
1183: foreach my $current (split(/\,/,$categories{$id.'_calculations'})) {
1184: $newcontent{$current}=1;
1185: }
1186: $categories{$id.'_calculations'}=join(',',sort(keys(%newcontent)));
1187: return %categories;
1188: }
1189:
1190: #
1191: # Delete a calculation rule
1192: #
1193:
1194: sub del_calculation_rule {
1195: my ($id,$cangrade,$delcontent,%categories)=@_;
1196: unless ($cangrade) { return %categories; }
1197: my @newcontent=();
1198: foreach my $current (split(/\,/,$categories{$id.'_calculations'})) {
1.78 www 1199: unless ($current=~/^\Q$delcontent\E\:/) {
1.76 www 1200: push(@newcontent,$current);
1201: }
1202: }
1203: $categories{$id.'_calculations'}=join(',',@newcontent);
1204: return %categories;
1205: }
1206:
1.80 www 1207: sub set_category_rules {
1208: my ($cangrade,$id,%categories)=@_;
1209: unless ($cangrade) { return %categories; }
1210: my %lt=&category_rule_codes();
1211: my @newrules=();
1212: foreach my $code ('',(keys(%lt))) {
1213: if ($env{'form.sel_'.$id.'_'.$code}) {
1214: push(@newrules,$env{'form.sel_'.$id.'_'.$code}.':'.$env{'form.val_'.$id.'_'.$code});
1215: }
1216: }
1217: $categories{$id.'_calculations'}=join(',',sort(@newrules));
1218: return %categories;
1219: }
1220:
1221:
1.76 www 1222: # === Category Editing
1223:
1.65 www 1224: #
1.75 www 1225: # Add to category content
1226: #
1227:
1228: sub add_category_content {
1229: my ($id,$cangrade,$newcontent,%categories)=@_;
1230: unless ($cangrade) { return %categories; }
1.87 www 1231: &Apache::lonnet::logthis("In here $newcontent");
1.75 www 1232: my %newcontent=($newcontent => 1);
1233: foreach my $current (split(/\,/,$categories{$id.'_content'})) {
1234: $newcontent{$current}=1;
1235: }
1236: $categories{$id.'_content'}=join(',',sort(keys(%newcontent)));
1237: return %categories;
1238: }
1239:
1240: #
1241: # Delete from category content
1242: #
1243:
1244: sub del_category_content {
1245: my ($id,$cangrade,$delcontent,%categories)=@_;
1246: unless ($cangrade) { return %categories; }
1247: my @newcontent=();
1248: foreach my $current (split(/\,/,$categories{$id.'_content'})) {
1249: unless ($current eq $delcontent) {
1250: push(@newcontent,$current);
1251: }
1252: }
1253: $categories{$id.'_content'}=join(',',@newcontent);
1254: return %categories;
1255: }
1256:
1257: #
1.68 www 1258: # Delete category
1259: #
1260:
1261: sub del_category {
1.75 www 1262: my ($id,$cangrade,%categories)=@_;
1263: unless ($cangrade) { return %categories; }
1264: my @neworder=();
1265: foreach my $currentid (split(/\,/,$categories{'order'})) {
1266: unless ($currentid eq $id) {
1267: push(@neworder,$currentid);
1268: }
1269: }
1270: $categories{'order'}=join(',',@neworder);
1271: return %categories;
1.68 www 1272: }
1273:
1274: #
1.72 www 1275: # Move category up
1276: #
1277:
1278: sub move_up_category {
1279: my ($id,$cangrade,%categories)=@_;
1280: my $currentpos=¤t_pos_category($id,%categories);
1281: if ($currentpos<1) { return %categories; }
1282: return &move_category($id,$cangrade,$currentpos-1,%categories);
1283: }
1284:
1285: #
1286: # Move category down
1287: #
1288:
1289: sub move_down_category {
1290: my ($id,$cangrade,%categories)=@_;
1291: my $currentpos=¤t_pos_category($id,%categories);
1292: my @order=split(/\,/,$categories{'order'});
1293: if ($currentpos>=$#order) { return %categories; }
1294: return &move_category($id,$cangrade,$currentpos+1,%categories);
1295: }
1296:
1297: #
1.65 www 1298: # Move a category to a desired position n the display order
1299: #
1300:
1301: sub move_category {
1302: my ($id,$cangrade,$ordernum,%categories)=@_;
1303: unless ($cangrade) { return %categories; }
1304: my @order=split(/\,/,$categories{'order'});
1305: # Where is the index currently?
1306: my $currentpos=¤t_pos_category($id,%categories);
1307: if (defined($currentpos)) {
1308: if ($currentpos<$ordernum) {
1309: # This is moving to a higher index
1310: # ....X1234....
1311: # ....1234X....
1312: for (my $i=$currentpos;$i<$ordernum;$i++) {
1313: $order[$i]=$order[$i+1];
1314: }
1315: $order[$ordernum]=$id;
1316: }
1317: if ($currentpos>$ordernum) {
1318: # This is moving to a lower index
1319: # ....1234X....
1320: # ....X1234....
1321: for (my $i=$currentpos;$i>$ordernum;$i--) {
1322: $order[$i]=$order[$i-1];
1323: }
1324: $order[$ordernum]=$id;
1325: }
1326: }
1327: $categories{'order'}=join(',',@order);
1328: return %categories;
1329: }
1330:
1331: #
1332: # Find current postion of a category in the order
1333: #
1334:
1335: sub current_pos_category {
1336: my ($id,%categories)=@_;
1337: my @order=split(/\,/,$categories{'order'});
1338: for (my $i=0;$i<=$#order;$i++) {
1339: if ($order[$i] eq $id) { return $i; }
1340: }
1341: # not found
1342: return undef;
1343: }
1344:
1345: #
1346: # Set name of a category
1347: #
1348: sub set_category_name {
1.69 www 1349: my ($cangrade,$id,$name,%categories)=@_;
1350: unless ($cangrade) { return %categories; }
1.65 www 1351: $categories{$id.'_name'}=$name;
1352: return %categories;
1353: }
1354:
1355: #
1.71 www 1356: # Set total of a category
1.70 www 1357: #
1.71 www 1358: sub set_category_total {
1359: my ($cangrade,$id,$totaltype,$total,%categories)=@_;
1.70 www 1360: unless ($cangrade) { return %categories; }
1.71 www 1361: if (($categories{$id.'_total'} eq '') && ($total=~/\d/)) {
1362: $totaltype='typein';
1.70 www 1363: }
1.71 www 1364: $categories{$id.'_totaltype'}=$totaltype;
1365: if ($totaltype eq 'default') {
1366: $categories{$id.'_total'}='';
1.70 www 1367: } else {
1.71 www 1368: $total=~s/\D//gs;
1369: unless ($total) { $total=0; }
1370: $categories{$id.'_total'}=$total;
1.70 www 1371: }
1372: return %categories;
1373: }
1374:
1.71 www 1375: sub set_category_weight {
1376: my ($cangrade,$id,$weight,%categories)=@_;
1377: unless ($cangrade) { return %categories; }
1378: $weight=~s/\D//gs;
1379: unless ($weight) { $weight=0; }
1380: $categories{$id.'_weight'}=$weight;
1381: return %categories;
1382: }
1.70 www 1383:
1.81 www 1384: sub set_category_displayachieved {
1385: my ($cangrade,$id,$value,%categories)=@_;
1386: unless ($cangrade) { return %categories; }
1387: unless (($value eq 'percent') || ($value eq 'points')) { $value='percent'; }
1388: $categories{$id.'_displayachieved'}=$value;
1389: return %categories;
1390: }
1391:
1392:
1.70 www 1393: #
1.65 www 1394: # === end category-related
1395: #
1396: #
1.5 bowersj2 1397: # Pass this two refs to arrays for the start and end color, and a number
1398: # from 0 to 1 for how much of the latter you want to mix in. It will
1399: # return a string ready to show ("#FFC309");
1.51 www 1400:
1.5 bowersj2 1401: sub mixColors {
1402: my $start = shift;
1403: my $end = shift;
1404: my $ratio = shift;
1405:
1.9 matthew 1406: my ($a,$b);
1.5 bowersj2 1407: my $final = "";
1.9 matthew 1408: $a = $start->[0]; $b = $end->[0];
1.5 bowersj2 1409: my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
1.9 matthew 1410: $a = $start->[1]; $b = $end->[1];
1.5 bowersj2 1411: my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
1.9 matthew 1412: $a = $start->[2]; $b = $end->[2];
1.5 bowersj2 1413: my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
1414:
1.16 bowersj2 1415: $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
1.5 bowersj2 1416: return "#" . $final;
1.1 bowersj2 1417: }
1418:
1419: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>