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