--- loncom/interface/lonquickgrades.pm 2011/03/26 20:04:15 1.81 +++ loncom/interface/lonquickgrades.pm 2011/05/24 18:06:10 1.90 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.81 2011/03/26 20:04:15 www Exp $ +# $Id: lonquickgrades.pm,v 1.90 2011/05/24 18:06:10 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,7 +62,8 @@ sub real_handler { $r->send_http_header; my $showPoints = - $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); my $notshowSPRSlink = (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external') || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')); @@ -266,8 +267,12 @@ sub getData { $totalRight += $score; $partsCount += $curRes->weight($part); + $curRes->{DATA}->{PROB_SCORE} += $score; + $curRes->{DATA}->{PROB_WEIGHT} += $curRes->weight($part); + if ($curRes->opendate($part) < $now) { $totalPossible += $curRes->weight($part); + $curRes->{DATA}->{PROB_POSSIBLE} += $curRes->weight($part); } $totalParts += $curRes->weight($part); } else { @@ -459,11 +464,50 @@ sub outputCategories { &output_category_table($r,$cangrade,$navmap,%categories); # if ($cangrade) { - $r->print('<input type="hidden" name="storemove" value="" />'. + $r->print(&Apache::loncommon::resourcebrowser_javascript(). + '<input type="hidden" name="storemove" value="" />'. '<input type="hidden" name="cmd" value="" />'. + '<input type="hidden" name="resourcesymb" value="" />'. '<input type="submit" name="storechanges" value="'.&mt("Save changes to grading categories").'" />'. '<script>function storecmd (cmd) { document.quickform.cmd.value=cmd; document.quickform.submit(); }</script>'); } +# +# Debug +# +# my %data=&dumpdata($navmap); +# foreach (keys(%data)) { +# $r->print("\n<br />".$_.'='.$data{$_}); +# } +} + +# +# Get data for all symbs +# + +sub dumpdata { + my ($navmap)=@_; + my %returndata=(); + +# Run through the map and get all data + + my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $iterator->next(); # ignore first BEGIN_MAP + my $curRes = $iterator->next(); + + while ($depth > 0) { + if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} + if ($curRes == $iterator->END_MAP()) { $depth--; } + if (ref($curRes)) { + if ($curRes->is_map()) { + $returndata{$curRes->symb()}='folder:'.$curRes->{DATA}->{CHILD_PARTS}.':'.$curRes->{DATA}->{CHILD_ATTEMPTED}.':'.$curRes->{DATA}->{CHILD_CORRECT}; + } else { + $returndata{$curRes->symb()}='res:'.$curRes->{DATA}->{PROB_WEIGHT}.':'.$curRes->{DATA}->{PROB_POSSIBLE}.':'.$curRes->{DATA}->{PROB_SCORE}; + } + } + $curRes = $iterator->next(); + } + return %returndata; } # @@ -495,7 +539,7 @@ sub process_category_edits { } elsif ($cmd=~/^delcat\_(.+)$/) { %categories=&del_category($1,$cangrade,%categories); } elsif ($cmd=~/^addcont\_(.+)$/) { - %categories=&add_category_content($1,$cangrade,$env{'form.addcont_'.$1.'_symb'},%categories); + %categories=&add_category_content($1,$cangrade,$env{'form.resourcesymb'},%categories); } elsif ($cmd=~/^delcont\_(.+)\_\_\_\_\_\_(.+)$/) { %categories=&del_category_content($1,$cangrade,$2,%categories); } elsif ($cmd=~/^newrule\_(.+)$/) { @@ -525,9 +569,10 @@ sub output_category_table { # my @order=split(/\,/,$categories{'order'}); # + my %performance=&dumpdata($navmaps); my $maxpos=$#order; for (my $i=0;$i<=$maxpos;$i++) { - my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,%categories); + my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,\%performance,1,%categories); $sum+=$value*$weight; $total+=$weight; } @@ -559,16 +604,16 @@ sub output_category_table_header { # sub output_and_calc_category { - my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,%categories)=@_; + my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,$performance,$output,%categories)=@_; my $value=0; my $weight=0; my $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/"); my %lt=&Apache::lonlocal::texthash( 'up' => 'Move Up', 'dw' => 'Move Down'); - $r->print("\n".&Apache::loncommon::start_data_table_row()); + if ($output) { $r->print("\n".&Apache::loncommon::start_data_table_row()); } - if ($cangrade) { + if ($output && $cangrade) { $r->print(<<ENDMOVE); <td> <div class="LC_docs_entry_move"> @@ -595,80 +640,108 @@ ENDMOVE $r->print('<td><a href="javascript:storecmd(\'delcat_'.$id.'\');">'.&mt('Delete').'</a></td>'); $r->print('<td><input type="text" name="name_'.$id. '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_name'}).'" /></td>'); - } else { + } elsif ($output) { $r->print('<td>'.$categories{$id.'_name'}.'</td>'); } -# Content - $r->print('<td><ul>'); +# Content display and summing up of points + my $totalpossible=0; + my $totalcorrect=0; + if ($output) { $r->print('<td><ul>'); } foreach my $contentid (split(/\,/,$categories{$id.'_content'})) { - $r->print('<li>'); - $r->print(&Apache::lonnet::gettitle($contentid)); - if ($cangrade) { - $r->print(' <a href="javascript:storecmd(\'delcont_'.$id.'______'.$contentid.'\');">'.&mt('Delete').'</a>'); - } - $r->print('</li>'); - } - $r->print('</ul>'); - if ($cangrade) { - $r->print('<br />'.&mt('Add Problem or Sequence').'<br />'. - &Apache::lonstathelpers::problem_selector('.',undef,1,1,'addcont_'.$id.'_',1,'this.form.cmd.value="addcont_'.$id.'";this.form.submit();')); + my ($type,$possible,$attempted,$correct)=split(/\:/,$$performance{$contentid}); + $totalpossible+=$possible; + $totalcorrect+=$correct; + if ($output) { + $r->print('<li>'); + $r->print(&Apache::lonnet::gettitle($contentid).' ('.$correct.'/'.$possible.')'); + if ($cangrade) { + $r->print(' <a href="javascript:storecmd(\'delcont_'.$id.'______'.$contentid.'\');">'.&mt('Delete').'</a>'); + } + $r->print('</li>'); + } + } + if ($output) { + $r->print('</ul>'); + $r->print('<p>'.&mt('Total raw points: [_1]/[_2]',$totalcorrect,$totalpossible).'</p>'); + if ($cangrade) { + $r->print('<br />'.&Apache::loncommon::selectresource_link('quickform','addcont_'.$id,&mt('Add Problem or Folder')).'<br />'); + } + $r->print('</td>'); } - $r->print('</td>'); - # Total + if ($output) { $r->print('<td>'); } if ($cangrade) { - $r->print('<td>'. + if ($output) { + $r->print( '<select name="totaltype_'.$id.'">'. '<option value="default"'.($categories{$id.'_totaltype'} eq 'default'?' selected="selected"':'').'>'.&mt('default').'</option>'. '<option value="typein"'.($categories{$id.'_totaltype'} eq 'typein'?' selected="selected"':'').'>'.&mt('Type-in value').'</option>'. '</select>'. '<input type="text" size="4" name="total_'.$id. - '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_total'}).'" /></td>'); + '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_total'}).'" />'); + } } else { - $r->print('<td>'.($categories{$id.'_totaltype'} eq 'default'?&mt('default'):$categories{$id.'_total'}).'</td>'); + if ($output) { + $r->print('<td>'.($categories{$id.'_totaltype'} eq 'default'?&mt('default'):$categories{$id.'_total'})); + } + } +# Adjust total points + if ($categories{$id.'_totaltype'} eq 'typein') { + $totalpossible=1.*$categories{$id.'_total'}; + } + if ($output) { + $r->print('<p>'.&mt('Adjusted raw points: [_1]/[_2]',$totalcorrect,$totalpossible).'</p>'); } # Calculation - $r->print('<td><ul>'); + if ($output) { $r->print('<td><ul>'); } foreach my $calcrule (split(/\,/,$categories{$id.'_calculations'})) { - $r->print('<li>'); + if ($output) { $r->print('<li>'); } my ($code,$value)=split(/\:/,$calcrule); - $r->print(&pretty_prt_rule($cangrade,$id,$code,$value)); + if ($output) { $r->print(&pretty_prt_rule($cangrade,$id,$code,$value)); } if ($cangrade) { - $r->print(' <a href="javascript:storecmd(\'delrule_'.$id.'______'.$code.'\');">'.&mt('Delete').'</a>'); + if ($output) { $r->print(' <a href="javascript:storecmd(\'delrule_'.$id.'______'.$code.'\');">'.&mt('Delete').'</a>'); } } - $r->print('</li>'); + if ($output) { $r->print('</li>'); } } - $r->print('</ul>'); + if ($output) { $r->print('</ul>'); } if ($cangrade) { - $r->print('<br />'.&new_calc_rule_form($id)); + if ($output) { $r->print('<br />'.&new_calc_rule_form($id)); } } - $r->print('</td>'); + if ($output) { $r->print('</td>'); } # Weight if ($cangrade) { - $r->print('<td>'. + if ($output) { + $r->print('<td>'. '<input type="text" size="4" name="weight_'.$id. '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_weight'}).'" /></td>'); + } } else { - $r->print('<td>'.$categories{$id.'_weight'}.'</td>'); + if ($output) { + $r->print('<td>'.$categories{$id.'_weight'}.'</td>'); + } } # Achieved - $r->print('<td>'); + if ($output) { $r->print('<td>'); } if ($cangrade) { - $r->print('<select name="displayachieved_'.$id.'">'. + if ($output) { + $r->print('<select name="displayachieved_'.$id.'">'. '<option value="percent"'.($categories{$id.'_displayachieved'} eq 'percent'?' selected="selected"':'').'>'.&mt('percent').'</option>'. '<option value="points"'.($categories{$id.'_displayachieved'} eq 'points'?' selected="selected"':'').'>'.&mt('points').'</option>'. '</select>'); + } } else { - if ($categories{$id.'_displayachieved'} eq 'percent') { - $r->print(&mt('percent')); - } else { - $r->print(&mt('points')); + if ($output) { + if ($categories{$id.'_displayachieved'} eq 'percent') { + $r->print(&mt('percent')); + } else { + $r->print(&mt('points')); + } } } - $r->print('</td>'); + if ($output) { $r->print('</td>'); } return ($value,$weight); } @@ -801,6 +874,7 @@ sub set_category_rules { sub add_category_content { my ($id,$cangrade,$newcontent,%categories)=@_; unless ($cangrade) { return %categories; } + &Apache::lonnet::logthis("In here $newcontent"); my %newcontent=($newcontent => 1); foreach my $current (split(/\,/,$categories{$id.'_content'})) { $newcontent{$current}=1;