Annotation of loncom/interface/statistics/lonsurveyreports.pm, revision 1.1
1.1 ! matthew 1: # The LearningOnline Network with CAPA
! 2: #
! 3: # $Id: lonstudentsubmissions.pm,v 1.11 2004/06/04 21:42:18 matthew Exp $
! 4: #
! 5: # Copyright Michigan State University Board of Trustees
! 6: #
! 7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 8: #
! 9: # LON-CAPA is free software; you can redistribute it and/or modify
! 10: # it under the terms of the GNU General Public License as published by
! 11: # the Free Software Foundation; either version 2 of the License, or
! 12: # (at your option) any later version.
! 13: #
! 14: # LON-CAPA is distributed in the hope that it will be useful,
! 15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 17: # GNU General Public License for more details.
! 18: #
! 19: # You should have received a copy of the GNU General Public License
! 20: # along with LON-CAPA; if not, write to the Free Software
! 21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 22: #
! 23: # /home/httpd/html/adm/gpl.txt
! 24: #
! 25: # http://www.lon-capa.org/
! 26: #
! 27: package Apache::lonsurveyreports;
! 28:
! 29: use strict;
! 30: use Apache::lonnet();
! 31: use Apache::loncommon();
! 32: use Apache::lonhtmlcommon();
! 33: use Apache::loncoursedata();
! 34: use Apache::lonstatistics;
! 35: use Apache::lonlocal;
! 36: use Apache::lonstathelpers;
! 37: use HTML::Entities();
! 38: use Time::Local();
! 39:
! 40: my @SubmitButtons = ({ name => 'PrevProblem',
! 41: text => 'Previous Survey' },
! 42: { name => 'NextProblem',
! 43: text => 'Next Survey' },
! 44: { name => 'break'},
! 45: { name => 'SelectAnother',
! 46: text => 'Choose a different Survey Problem' },
! 47: { name => 'Generate',
! 48: text => 'Generate Report'},
! 49: );
! 50:
! 51: sub BuildSurveyReportsPage {
! 52: my ($r,$c)=@_;
! 53: #
! 54: my %Saveable_Parameters = ('Status' => 'scalar',
! 55: 'Section' => 'array',
! 56: 'NumPlots' => 'scalar',
! 57: );
! 58: &Apache::loncommon::store_course_settings('survey_reports',
! 59: \%Saveable_Parameters);
! 60: &Apache::loncommon::restore_course_settings('survey_resports',
! 61: \%Saveable_Parameters);
! 62: #
! 63: &Apache::lonstatistics::PrepareClasslist();
! 64: #
! 65: $r->print(&CreateInterface());
! 66: #
! 67: my @Students = @Apache::lonstatistics::Students;
! 68: #
! 69: if (@Students < 1) {
! 70: $r->print('<h2>There are no students in the sections selected</h2>');
! 71: }
! 72: #
! 73: my @CacheButtonHTML =
! 74: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
! 75: $r->rflush();
! 76: #
! 77: if (exists($ENV{'form.problemchoice'}) &&
! 78: ! exists($ENV{'form.SelectAnother'})) {
! 79: foreach my $button (@SubmitButtons) {
! 80: if ($button->{'name'} eq 'break') {
! 81: $r->print("<br />\n");
! 82: } else {
! 83: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
! 84: 'value="'.&mt($button->{'text'}).'" />');
! 85: $r->print(' 'x5);
! 86: }
! 87: }
! 88: foreach my $html (@CacheButtonHTML) {
! 89: $r->print($html.(' 'x5));
! 90: }
! 91: #
! 92: $r->print('<hr />');
! 93: $r->rflush();
! 94: #
! 95: # Determine which problem we are to analyze
! 96: my $current_problem = &Apache::lonstathelpers::get_target_from_id
! 97: ($ENV{'form.problemchoice'});
! 98: #
! 99: my ($prev,$curr,$next) =
! 100: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
! 101: '.',
! 102: 'part_survey',
! 103: );
! 104: if (exists($ENV{'form.PrevProblem'}) && defined($prev)) {
! 105: $current_problem = $prev;
! 106: } elsif (exists($ENV{'form.NextProblem'}) && defined($next)) {
! 107: $current_problem = $next;
! 108: } else {
! 109: $current_problem = $curr;
! 110: }
! 111: #
! 112: # Store the current problem choice and send it out in the form
! 113: $ENV{'form.problemchoice'} =
! 114: &Apache::lonstathelpers::make_target_id($current_problem);
! 115: $r->print('<input type="hidden" name="problemchoice" value="'.
! 116: $ENV{'form.problemchoice'}.'" />');
! 117: #
! 118: if (! defined($current_problem->{'resource'})) {
! 119: $r->print('resource is undefined');
! 120: } else {
! 121: my $resource = $current_problem->{'resource'};
! 122: $r->print('<h1>'.$resource->{'title'}.'</h1>');
! 123: $r->print('<h3>'.$resource->{'src'}.'</h3>');
! 124: $r->print(&Apache::lonstathelpers::render_resource($resource));
! 125: $r->rflush();
! 126: my %Data = &Apache::lonstathelpers::get_problem_data
! 127: ($resource->{'src'});
! 128: &make_HTML_report($r,$current_problem,\%Data,\@Students);
! 129: }
! 130: $r->print('<hr />');
! 131: } else {
! 132: $r->print('<input type="submit" name="Generate" value="'.
! 133: &mt('Generate Survey Report').'" />');
! 134: $r->print(' 'x5);
! 135: $r->print('<h3>'.&mt('Please select a Survey to analyze').'</h3>');
! 136: $r->print(&SurveyProblemSelector());
! 137: }
! 138: }
! 139:
! 140: ##########################################################
! 141: ##########################################################
! 142: ##
! 143: ## SurveyProblemSelector
! 144: ##
! 145: ##########################################################
! 146: ##########################################################
! 147: sub SurveyProblemSelector {
! 148: my $Str = '';
! 149: my @SurveyProblems;
! 150: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess('all')) {
! 151: next if ($seq->{'num_assess'}<1);
! 152: foreach my $res (@{$seq->{'contents'}}) {
! 153: next if ($res->{'type'} ne 'assessment');
! 154: foreach my $part (@{$res->{'parts'}}) {
! 155: if ($res->{'partdata'}->{$part}->{'Survey'}) {
! 156: push(@SurveyProblems,{res=>$res,seq=>$seq,part=>$part});
! 157: last;
! 158: }
! 159: }
! 160: }
! 161: }
! 162: if (! scalar(@SurveyProblems)) {
! 163: $Str = '<h1>'.
! 164: &mt('There are no survey problems in this course').
! 165: '</h1>'.$/;
! 166: return $Str;
! 167: }
! 168: $Str .= '<table>'.$/;
! 169: $Str .= '<tr>'.'<td></td>'.
! 170: '<th>'.&mt('Sequence').'</th>'.
! 171: '<th>'.&mt('Problem').'</th>'.
! 172: '</tr>'.$/;
! 173: foreach my $problem (@SurveyProblems) {
! 174: my $value = &Apache::lonstathelpers::make_target_id
! 175: ({symb=>$problem->{'res'}->{'symb'},
! 176: part=>$problem->{'part'},
! 177: respid=>undef,
! 178: resptype=>undef});
! 179: my $checked = '';
! 180: if ($ENV{'form.problemchoice'} eq $value) {
! 181: $checked = 'checked ';
! 182: }
! 183: $Str .= '<tr>'.'<td>'.
! 184: '<input type="radio" name="problemchoice" '.
! 185: 'value="'.$value.'" '.$checked.'/>'.'</td>'.
! 186: '<td>'.$problem->{'seq'}->{'title'}.'</td>'.
! 187: '<td>'.$problem->{'res'}->{'title'}.'</td>'.
! 188: '</tr>'.$/;
! 189: }
! 190: $Str .= '</table>';
! 191: return $Str;
! 192: }
! 193:
! 194: #########################################################
! 195: #########################################################
! 196: ##
! 197: ## Compile Student Answers
! 198: ##
! 199: #########################################################
! 200: #########################################################
! 201: sub Compile_Student_Answers {
! 202: my ($problem,$ProblemData,$Students) = @_;
! 203: my $resource = $problem->{'resource'};
! 204: foreach my $student (@$Students) {
! 205: foreach my $partid (@{$resource->{'parts'}}) {
! 206: my $partdata = $resource->{'partdata'}->{$partid};
! 207: for (my $i=0;$i<=@{$partdata->{'ResponseIds'}};$i++) {
! 208: my $respid = $partdata->{'ResponseIds'}->[$i];
! 209: my $resptype = $partdata->{'ResponseTypes'}->[$i];
! 210: my $results =
! 211: &Apache::loncoursedata::get_response_data_by_student
! 212: ($student,$resource->{'symb'},$respid);
! 213: next if (! defined($results) || ref($results) ne 'ARRAY' ||
! 214: ref($results->[0]) ne 'ARRAY');
! 215: my $student_response =
! 216: $results->[0]->[&Apache::loncoursedata::RDs_submission()];
! 217: $problem->{'responsedata'}->{$partid}->{$respid}->{'_count'}++;
! 218: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
! 219: if ($resptype =~ /^(radiobutton|optionresponse)$/) {
! 220: # Restricted response type can be categorized.
! 221: #
! 222: # Assume responses were not randomized and the order
! 223: # represents their value. This is probably a dumb thing
! 224: # to do...
! 225: #
! 226: my ($foil,$value) = split('=',$student_response);
! 227: $value += 1; # explicitly increment it...
! 228: $data->{'foil_responses'}->{$foil}++;
! 229: $data->{'foil_values'}->{$value}++;
! 230: if (! exists($data->{'map'}->{$value})) {
! 231: $data->{'map'}->{$value} = $foil;
! 232: }
! 233: } else {
! 234: # Variable stuff (essays, raw numbers, strings) go here
! 235: push(@{$data->{'responses'}},$student_response);
! 236: }
! 237: }
! 238: }
! 239: }
! 240: return;
! 241: }
! 242:
! 243: #########################################################
! 244: #########################################################
! 245: ##
! 246: ## make_HTML_report
! 247: ##
! 248: #########################################################
! 249: #########################################################
! 250: sub make_HTML_report {
! 251: my ($r,$problem,$ProblemData,$Students) = @_;
! 252: &Compile_Student_Answers($problem,$ProblemData,$Students);
! 253: # &output_hash('',$ProblemData);
! 254: my $resource = $problem->{'resource'};
! 255: foreach my $partid (@{$resource->{'parts'}}) {
! 256: my $partdata = $resource->{'partdata'}->{$partid};
! 257: for (my $i=0;$i<=@{$partdata->{'ResponseIds'}};$i++) {
! 258: my $Str = '<table>'.$/;
! 259: my $respid = $partdata->{'ResponseIds'}->[$i];
! 260: my $resptype = $partdata->{'ResponseTypes'}->[$i];
! 261: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
! 262: next if (! defined($data) || ref($data) ne 'HASH');
! 263: # Debugging code
! 264: # $Str .= '<tr>'.
! 265: # '<td>'.$partid.'</td>'.
! 266: # '<td>'.$respid.'</td>'.
! 267: # '<td>'.$resptype.'</td>'.
! 268: # '</tr>'.$/;
! 269: $Str .= '<tr>'.
! 270: '<td><b>'.&mt('Total').'</b></td>'.
! 271: '<td>'.$data->{'_count'}.'</td>'.
! 272: '<td> </td>'.
! 273: '</tr>'.$/;
! 274: if (exists($data->{'responses'}) &&
! 275: ref($data->{'responses'}) eq 'ARRAY') {
! 276: &randomize_array($data->{'responses'});
! 277: foreach my $response (@{$data->{'responses'}}) {
! 278: $response =~ s/\\r\\n/\n/g;
! 279: $response =~ s/\\'/'/g;
! 280: $response =~ s/\\"/"/g;
! 281: $Str .= '<tr>'.
! 282: '<td colspan="3"><pre>'.
! 283: &HTML::Entities::encode($response,'<>&').
! 284: '</pre><hr /></td>'.
! 285: '</tr>'.$/;
! 286: }
! 287: } elsif (exists($data->{'_count'}) &&
! 288: exists($data->{'foil_values'}) &&
! 289: exists($data->{'map'})) {
! 290: # This is an option or radiobutton survey response
! 291: my $total = $data->{'_count'};
! 292: my $sum = 0;
! 293: my $tmp;
! 294: foreach my $value (sort(keys(%{$data->{'foil_values'}}))) {
! 295: my $count = $data->{'foil_values'}->{$value};
! 296: my $foilid = $data->{'map'}->{$value};
! 297: my $foiltext = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'text'};
! 298: my $foilname = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'name'};
! 299: $sum = $value * $data->{'foil_values'}->{$value};
! 300: $tmp .= '<tr>'.
! 301: '<td>'.$foilname.'</td>'.
! 302: '<td>'.$foiltext.'</td>'.
! 303: '<td align="right">'.$count.'</td>'.
! 304: '<td align="right">'.
! 305: sprintf("%.2f",$count/$total*100).'%</td>'.
! 306: '</tr>'.$/;
! 307: }
! 308: $Str .= '<tr>'.
! 309: '<td><b>'.&mt('mean').'</b></td>'.
! 310: '<td>'.sprintf("%.2f",$sum/$total).'</td>'.
! 311: '<td> </td>'.
! 312: '<td> </td>'.
! 313: '</tr>'.$/.
! 314: '<tr>'.
! 315: '<th>'.&mt('Foil Name').'</th>'.
! 316: '<th>'.&mt('Text').'</th>'.
! 317: '<th>'.&mt('Freq').'</th>'.
! 318: '<th>'.&mt('Percent').'</th>'.
! 319: '</tr>'.$/.
! 320: $tmp;
! 321: }
! 322: $Str.= '</table><hr />';
! 323: $r->print($Str);
! 324: $r->rflush();
! 325: }
! 326: }
! 327: return;
! 328: }
! 329:
! 330: sub randomize_array {
! 331: # Fisher Yates shuffle, lifted from p 121 of "The Perl Cookbook"
! 332: my ($array) = @_;
! 333: for (my $i=scalar(@$array);--$i;) {
! 334: my $j = int(rand($i+1));
! 335: next if ($i == $j);
! 336: @$array[$i,$j]=@$array[$j,$i];
! 337: }
! 338: }
! 339:
! 340: #########################################################
! 341: #########################################################
! 342: ##
! 343: ## Generic Interface Routines
! 344: ##
! 345: #########################################################
! 346: #########################################################
! 347: sub CreateInterface {
! 348: ##
! 349: ## Environment variable initialization
! 350: my $Str = '';
! 351: $Str .= &Apache::lonhtmlcommon::breadcrumbs
! 352: (undef,'Student Submission Reports');
! 353: $Str .= '<p>';
! 354: $Str .= '<table cellspacing="5">'."\n";
! 355: $Str .= '<tr>';
! 356: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
! 357: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
! 358: $Str .= '</tr>'."\n";
! 359: #
! 360: $Str .= '<tr><td align="center">'."\n";
! 361: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
! 362: $Str .= '</td>';
! 363: #
! 364: $Str .= '<td align="center">';
! 365: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
! 366: $Str .= '</td>';
! 367: #
! 368: $Str .= '</tr>'."\n";
! 369: $Str .= '</table>'."\n";
! 370: #
! 371: $Str .= '<nobr>'.&mt('Status: [_1]',
! 372: '<input type="text" '.
! 373: 'name="stats_status" size="60" value="" />').
! 374: '</nobr>'.'</p>';
! 375: ##
! 376: return $Str;
! 377: }
! 378:
! 379:
! 380:
! 381: 1;
! 382:
! 383: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>