1: # The LearningOnline Network with CAPA
2: # Quick Student Grades Display
3: #
4: # $Id: lonquickgrades.pm,v 1.66 2011/02/07 19:16:34 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonquickgrades;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use POSIX;
34: use Apache::loncommon;
35: use Apache::lonlocal;
36: use Apache::lonnet;
37: use Apache::grades;
38:
39: sub handler {
40: my $r = shift;
41: return real_handler($r);
42: }
43:
44: sub real_handler {
45: my $r = shift;
46:
47: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
48:
49: # Handle header-only request
50: if ($env{'browser.mathml'}) {
51: &Apache::loncommon::content_type($r,'text/xml');
52: } else {
53: &Apache::loncommon::content_type($r,'text/html');
54: }
55: if ($r->header_only) {
56: $r->send_http_header;
57: return OK;
58: }
59:
60: # Send header, don't cache this page
61: &Apache::loncommon::no_cache($r);
62: $r->send_http_header;
63:
64: my $showPoints =
65: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
66: my $notshowSPRSlink =
67: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
68: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'));
69: my $notshowTotals=
70: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
71: my $showCategories=
72: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
73:
74:
75: my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display";
76: my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}];
77: $r->print(&Apache::loncommon::start_page($title,undef,
78: {'bread_crumbs' => $brcrum})
79: );
80:
81: &startGradeScreen($r,'quick');
82:
83: $r->rflush();
84:
85: # my $uname='korte';
86: # my $udom='gerd';
87:
88: my $uname;
89: my $udom;
90:
91: my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=
92: &getData($showPoints,$uname,$udom);
93:
94: if ($showCategories) {
95: &outputCategories($r,$showPoints,$notshowTotals,
96: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
97: } else {
98: &outputTable($r,$showPoints,$notshowTotals,
99: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
100: }
101: &endGradeScreen($r);
102: return OK;
103:
104: }
105:
106: sub startGradeScreen {
107: my ($r,$mode)=@_;
108:
109: my $showPoints =
110: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard';
111: my $notshowSPRSlink =
112: (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external')
113: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')
114: || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'));
115: my $notshowTotals=
116: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals';
117: my $showCategories=
118: $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories';
119:
120: my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
121: my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
122:
123: if ($allowed_to_view) {
124: my @notes;
125: push(@notes,&mt('Students do not see total points.')) if ($notshowTotals);
126: push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink);
127: push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints);
128: push(@notes,&mt('Students will see points based on categories.')) if ($showCategories);
129: push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading'));
130: $r->print(&Apache::loncommon::head_subbox(join(' ',@notes)));
131: }
132:
133:
134: $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
135: $r->print("\n".'<li'.($mode eq 'quick'?' class="active"':'').'><a href="/adm/quickgrades"><b> '.
136: ($showPoints?&mt('Individual Points Overview'):($showCategories?&mt('Grades Overview'):&mt('Completion Overview'))).
137: ' </b></a></li>');
138:
139: if (!($showPoints || $notshowSPRSlink) || ($allowed_to_view)) {
140: $r->print("\n".'<li'.($mode eq 'spreadsheet'?' class="active"':'').'><a href="/adm/'.($allowed_to_view?'classcalc':'studentcalc').'"><b>'.
141: &mt('Spreadsheet (Detailed)').'</b></a></li>');
142: }
143: if ($allowed_to_view) {
144: $r->print("\n".'<li'.($mode eq 'statistics'?' class="active"':'').'><a href="/adm/statistics"><b>'.
145: &mt('Statistics and Reports').'</b></a></li>');
146:
147: $r->print("\n".'<li'.($mode eq 'chart'?' class="active"':'').'><a href="/adm/statistics?reportSelected=student_assessment"><b>'.
148: &mt('Assessment Overview Chart').'</b></a></li>');
149:
150: }
151: if ($allowed_to_edit) {
152: $r->print("\n".'<li'.($mode eq 'grading'?' class="active"':'').'><a href="/adm/grades"><b> '.
153: &mt('Content Grading').' </b></a></li>');
154: if ($env{'form.symb'}) {
155: $r->print("\n".'<li'.($mode eq 'probgrading'?' class="active"':'').'><a href="/adm/grades?symb='.
156: &Apache::lonhtmlcommon::entity_encode($env{'form.symb'}).
157: '&command=gradingmenu"><b> '.
158: &mt('Problem Grading').' </b></a></li>');
159:
160: }
161: }
162: $r->print("\n".'</ul>'."\n");
163: $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;">');
164: }
165:
166: sub endGradeScreen {
167: my ($r)=@_;
168: $r->print('</div></div></div>');
169: }
170:
171:
172: sub getData {
173:
174: my ($showPoints,$uname,$udom)=@_;
175:
176: &Apache::lonnet::logthis("About to call with $uname $udom");
177:
178: # Create the nav map
179: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
180:
181: my $res = $navmap->firstResource(); # temp resource to access constants
182:
183: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
184: my $depth = 1;
185: $iterator->next(); # ignore first BEGIN_MAP
186: my $curRes = $iterator->next();
187:
188: # General overview of the following: Walk along the course resources.
189: # For every problem in the resource, tell its parent maps how many
190: # parts and how many parts correct it has. After that, each map will
191: # have a count of the total parts underneath it, correct and otherwise.
192: # After that, we will walk through the course again and read off
193: # maps in order, with their data.
194: # (If in the future people decide not to be cumulative, only add
195: # the counts to the parent map.)
196: # For convenience, "totalParts" is also "totalPoints" when we're looking
197: # at points; I can't come up with a variable name that makes sense
198: # equally for both cases.
199:
200: my $totalParts = 0; my $totalPossible = 0; my $totalRight = 0;
201: my $totalAttempted = 0;
202: my $now = time();
203: my $topLevelParts = 0; my $topLevelRight = 0; my $topLevelAttempted = 0;
204:
205: # Pre-run: Count parts correct
206: while ( $depth > 0 ) {
207: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
208: if ($curRes == $iterator->END_MAP()) { $depth--; }
209:
210: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout)
211: {
212: # Get number of correct, incorrect parts
213: my $parts = $curRes->parts();
214: my $partsRight = 0;
215: my $partsCount = 0;
216: my $partsAttempted = 0;
217: my $stack = $iterator->getStack();
218:
219: for my $part (@{$parts}) {
220: my $completionStatus = $curRes->getCompletionStatus($part);
221: my $dateStatus = $curRes->getDateStatus($part);
222:
223: if ($completionStatus == $curRes->EXCUSED()) {
224: next;
225: }
226: if ($showPoints) {
227: my $score = 0;
228: # If we're not telling status and the answer date isn't passed yet,
229: # it's an "attempted" point
230: if ((($curRes->problemstatus($part) eq 'no') ||
231: ($curRes->problemstatus($part) eq 'no_feedback_ever')) &&
232: ($dateStatus != $curRes->ANSWER_OPEN)) {
233: my $status = $curRes->simpleStatus($part);
234: if ($status == $curRes->ATTEMPTED) {
235: $partsAttempted += $curRes->weight($part);
236: $totalAttempted += $partsAttempted;
237: }
238: } else {
239: $score = &Apache::grades::compute_points($curRes->weight($part), $curRes->awarded($part));
240: }
241: $partsRight += $score;
242: $totalRight += $score;
243: $partsCount += $curRes->weight($part);
244:
245: if ($curRes->opendate($part) < $now) {
246: $totalPossible += $curRes->weight($part);
247: }
248: $totalParts += $curRes->weight($part);
249: } else {
250: my $status = $curRes->simpleStatus($part);
251: my $thisright = 0;
252: $partsCount++;
253: if ($status == $curRes->CORRECT ||
254: $status == $curRes->PARTIALLY_CORRECT ) {
255: $partsRight++;
256: $totalRight++;
257: $thisright = 1;
258: }
259:
260: if ($status == $curRes->ATTEMPTED) {
261: $partsAttempted++;
262: $totalAttempted++;
263: }
264:
265: my $dateStatus = $curRes->getDateStatus($part);
266: $totalParts++;
267: if ($curRes->opendate($part) < $now) {
268: $totalPossible++;
269: }
270: }
271: }
272:
273: if ($depth == 1) { # in top-level only
274: $topLevelParts += $partsCount;
275: $topLevelRight += $partsRight;
276: $topLevelAttempted += $partsAttempted;
277: }
278:
279: # Crawl down stack and record parts correct and total
280: for my $res (@{$stack}) {
281: if (ref($res) && $res->is_map()) {
282: if (!defined($res->{DATA}->{CHILD_PARTS})) {
283: $res->{DATA}->{CHILD_PARTS} = 0;
284: $res->{DATA}->{CHILD_CORRECT} = 0;
285: $res->{DATA}->{CHILD_ATTEMPTED} = 0;
286: }
287:
288: $res->{DATA}->{CHILD_PARTS} += $partsCount;
289: $res->{DATA}->{CHILD_CORRECT} += $partsRight;
290: $res->{DATA}->{CHILD_ATTEMPTED} += $partsAttempted;
291: }
292: }
293: }
294: $curRes = $iterator->next();
295: }
296: return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted);
297: }
298:
299: #
300: # Outputting everything.
301: #
302:
303: sub outputTable {
304:
305: my ($r,$showPoints,$notshowTotals,
306: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
307:
308: my @start = (255, 255, 192);
309: my @end = (0, 192, 0);
310:
311: my $indentString = ' ';
312:
313: # Second pass: Print the maps.
314: $r->print(&Apache::loncommon::start_data_table()
315: .&Apache::loncommon::start_data_table_header_row()
316: .'<th>'.&mt('Folder').'</th>');
317: my $title = &mt($showPoints ? "Points Scored" : "Done");
318: if ($totalAttempted) {
319: $title .= " / " . &mt("Attempted");
320: }
321: $r->print("<th>$title".($notshowTotals?'':" / ".&mt('Total')).'</th>'
322: .&Apache::loncommon::end_data_table_header_row());
323: #
324: # Output of folder scores
325: #
326:
327: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
328: my $depth = 1;
329: $iterator->next(); # ignore first BEGIN_MAP
330: my $curRes = $iterator->next();
331:
332: while ($depth > 0) {
333: if ($curRes == $iterator->BEGIN_MAP()) {$depth++;}
334: if ($curRes == $iterator->END_MAP()) { $depth--; }
335:
336: if (ref($curRes) && $curRes->is_map()) {
337: my $title = $curRes->compTitle();
338:
339: my $correct = $curRes->{DATA}->{CHILD_CORRECT};
340: my $total = $curRes->{DATA}->{CHILD_PARTS};
341: my $attempted = $curRes->{DATA}->{CHILD_ATTEMPTED};
342:
343: if ($total > 0) {
344: my $ratio;
345: $ratio = $correct / $total;
346: my $color = &mixColors(\@start, \@end, $ratio);
347: $r->print(&Apache::loncommon::start_data_table_row()
348: .'<td style="background-color:'.$color.';">');
349:
350: my $thisIndent = '';
351: for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; }
352:
353: $r->print("$thisIndent$title</td>");
354: if ($totalAttempted) {
355: $r->print('<td valign="top">'
356: .$thisIndent
357: .'<span class="LC_nobreak">'
358: .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total)
359: .'</span></td>'
360: .&Apache::loncommon::end_data_table_row()
361: );
362: } else {
363: $r->print('<td valign="top">'
364: .$thisIndent
365: .'<span class="LC_nobreak">'
366: .$correct.($notshowTotals?'':' / '.$total)
367: .'</span></td>'
368: .&Apache::loncommon::end_data_table_row());
369: }
370: }
371: }
372:
373: $curRes = $iterator->next();
374: }
375:
376: # If there were any problems at the top level, print an extra "catchall"
377: if ($topLevelParts > 0) {
378: my $ratio = $topLevelRight / $topLevelParts;
379: my $color = mixColors(\@start, \@end, $ratio);
380: $r->print(&Apache::loncommon::start_data_table_row()
381: .'<td style="background-color:'.$color.';">');
382: $r->print(&mt("Problems Not Contained In A Folder")."</td><td>");
383: $r->print("$topLevelRight / $topLevelParts</td>"
384: .&Apache::loncommon::end_data_table_row());
385: }
386:
387: #
388: # show totals (if applicable), close table
389: #
390: if ($showPoints) {
391: my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct");
392:
393: $title = $showPoints ? "Points" : "Parts Done";
394: my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done");
395: $r->print(&Apache::loncommon::start_data_table_row()
396: .'<td colspan="2" align="right">'.$totaltitle.': <b>'.$totalRight.'</b><br />');
397: $r->print(&mt('Max Possible To Date')." $maxHelpLink: <b>$totalPossible</b><br />");
398: $title = $showPoints ? "Points" : "Parts";
399: $r->print(&mt("Total $title In Course").': <b>'.$totalParts.'</b></td>'
400: .&Apache::loncommon::end_data_table_row());
401: }
402:
403: $r->print(&Apache::loncommon::end_data_table()
404: .&Apache::loncommon::end_page());
405:
406: }
407:
408: #
409: # === Outputting category-based grades.
410: #
411: # $category{'order'}: output order of categories by id
412: # $category{'all'}: complete list of all categories
413: # $category{$id.'_name'}: display-name of category
414: #
415:
416: sub outputCategories {
417:
418: my ($r,$showPoints,$notshowTotals,
419: $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_;
420: # Take care of storing and retrieving categories
421:
422: my $cangrade=&Apache::lonnet::allowed('mgr');
423:
424: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
425: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
426: my %categories=();
427: # Loading old categories
428: %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum);
429: # Storing
430: if (($cangrade) && (($env{'form.storechanges'}) || ($env{'form.storemove'} ne ''))) {
431: # Process the changes
432: %categories=&process_category_edits($r,$cangrade,%categories);
433: # Actually store
434: &Apache::lonnet::put('grading_categories',\%categories,$cdom,$cnum);
435: }
436: # new categories loaded now
437: # Form only generated if user can change the grading categories
438: if ($cangrade) {
439: $r->print('<form method="post">');
440: }
441: #
442: &output_category_table($r,$cangrade,$navmap,%categories);
443: #
444: if ($cangrade) {
445: $r->print('<input type="hidden" name="storemove" value="" />'.
446: '<input type="submit" name="storechanges" value="'.&mt("Save changes to grading categories").'" /></form>');
447: }
448: }
449:
450: #
451: # Process editing commands, update category hash
452: #
453:
454: sub process_category_edits {
455: my ($r,$cangrade,%categories)=@_;
456: unless ($cangrade) { return %categories; }
457: #
458: # Business logic here
459: #
460: return %categories;
461: }
462:
463: #
464: # Output the table
465: #
466:
467: sub output_category_table {
468: my ($r,$cangrade,$navmaps,%categories)=@_;
469: my $sum=0;
470: $r->print(&Apache::loncommon::start_data_table());
471: #
472: &output_category_table_header($r,$cangrade);
473: #
474: my @order=split(/\,/,$categories{'order'});
475: #
476: # FIXME: Debug only
477: @order=('3131_4123_42124','4124_34231_3412');
478: #
479: my $maxpos=$#order;
480: for (my $i=0;$i<=$maxpos;$i++) {
481: my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,%categories);
482: }
483: #
484: &bottom_line_category($r,$cangrade);
485: #
486: $r->print(&Apache::loncommon::end_data_table());
487: return $sum;
488: }
489:
490: sub output_category_table_header {
491: my ($r,$cangrade)=@_;
492: $r->print(&Apache::loncommon::start_data_table_header_row());
493: if ($cangrade) {
494: $r->print('<th colspan="2">'.&mt("Move").'</th><th>'.&mt('Action').'</th>');
495: }
496: $r->print('<th>'.&mt('Category').'</th>'.
497: '<th>'.&mt('Contents').'</th>'.
498: '<th>'.&mt('Calculation').'</th>'.
499: '<th>'.&mt('Weight').'</th>'.
500: '<th>'.&mt('Percent Overall').'</th>');
501: $r->print(&Apache::loncommon::end_data_table_header_row());
502: }
503:
504:
505: #
506: # Output one category to table
507: #
508:
509: sub output_and_calc_category {
510: my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,%categories)=@_;
511: my $value=0;
512: my $weight=0;
513: my $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
514: my %lt=&Apache::lonlocal::texthash(
515: 'up' => 'Move Up',
516: 'dw' => 'Move Down');
517: $r->print("\n".&Apache::loncommon::start_data_table_row());
518:
519: if ($cangrade) {
520: $r->print(<<ENDMOVE);
521: <td>
522: <div class="LC_docs_entry_move">
523: <a href='/adm/quickgrades?cmd=up_$id&storechanges=1'>
524: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
525: </a>
526: </div>
527: <div class="LC_docs_entry_move">
528: <a href='/adm/quickgrades?cmd=down_$id&storechanges=1'>
529: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
530: </a>
531: </div>
532: </td>
533: ENDMOVE
534: $r->print("\n<td>\n<select name='newpos_$id' onchange='this.form.storemove.value=\"$id\";this.form.submit()'>");
535: for (my $i=0;$i<=$maxpos;$i++) {
536: if ($i==$currentpos) {
537: $r->print('<option value="" selected="selected">('.$i.')</option>');
538: } else {
539: $r->print('<option value="'.$i.'">'.$i.'</option>');
540: }
541: }
542: $r->print("\n</select>\n</td>\n");
543:
544: }
545: $r->print(&Apache::loncommon::end_data_table_row()."\n");
546: return ($value,$weight);
547: }
548:
549: #
550: # Bottom line with grades
551: #
552:
553: sub bottom_line_category {
554: my ($r,$cangrade)=@_;
555: }
556:
557: #
558: # Make one new category
559: #
560:
561: sub make_new_category {
562: my ($r,$cangrade,$ordernum,%categories)=@_;
563: unless ($cangrade) { return %categories; }
564: # Generate new ID
565: my $id=time.'_'.$$.'_'.rand(10000);
566: # Add new ID to list of all IDs ever created in this course
567: $categories{'all'}.=','.$id;
568: $categories{'all'}=~s/^\,//;
569: # Add new ID to ordered list of displayed and evaluated categories
570: $categories{'order'}.=','.$id;
571: $categories{'order'}=~s/^\,//;
572: # Move it into desired space
573: if (defined($ordernum)) {
574: %categories=&move_category($id,$cangrade,$ordernum,%categories);
575: }
576: return %categories;
577: }
578:
579: #
580: # Move a category to a desired position n the display order
581: #
582:
583: sub move_category {
584: my ($id,$cangrade,$ordernum,%categories)=@_;
585: unless ($cangrade) { return %categories; }
586: my @order=split(/\,/,$categories{'order'});
587: # Where is the index currently?
588: my $currentpos=¤t_pos_category($id,%categories);
589: if (defined($currentpos)) {
590: if ($currentpos<$ordernum) {
591: # This is moving to a higher index
592: # ....X1234....
593: # ....1234X....
594: for (my $i=$currentpos;$i<$ordernum;$i++) {
595: $order[$i]=$order[$i+1];
596: }
597: $order[$ordernum]=$id;
598: }
599: if ($currentpos>$ordernum) {
600: # This is moving to a lower index
601: # ....1234X....
602: # ....X1234....
603: for (my $i=$currentpos;$i>$ordernum;$i--) {
604: $order[$i]=$order[$i-1];
605: }
606: $order[$ordernum]=$id;
607: }
608: }
609: $categories{'order'}=join(',',@order);
610: return %categories;
611: }
612:
613: #
614: # Find current postion of a category in the order
615: #
616:
617: sub current_pos_category {
618: my ($id,%categories)=@_;
619: my @order=split(/\,/,$categories{'order'});
620: for (my $i=0;$i<=$#order;$i++) {
621: if ($order[$i] eq $id) { return $i; }
622: }
623: # not found
624: return undef;
625: }
626:
627: #
628: # Set name of a category
629: #
630: sub set_category_name {
631: my ($canedit,$id,$name,%categories)=@_;
632: unless ($canedit) { return %categories; }
633: $categories{$id.'_name'}=$name;
634: return %categories;
635: }
636:
637: #
638: # === end category-related
639: #
640: #
641: # Pass this two refs to arrays for the start and end color, and a number
642: # from 0 to 1 for how much of the latter you want to mix in. It will
643: # return a string ready to show ("#FFC309");
644:
645: sub mixColors {
646: my $start = shift;
647: my $end = shift;
648: my $ratio = shift;
649:
650: my ($a,$b);
651: my $final = "";
652: $a = $start->[0]; $b = $end->[0];
653: my $mix1 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
654: $a = $start->[1]; $b = $end->[1];
655: my $mix2 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
656: $a = $start->[2]; $b = $end->[2];
657: my $mix3 = POSIX::floor((1-$ratio)*$a + $ratio*$b);
658:
659: $final = sprintf "%02x%02x%02x", $mix1, $mix2, $mix3;
660: return "#" . $final;
661: }
662:
663: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>