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