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