Annotation of loncom/interface/statistics/lonsurveyreports.pm, revision 1.26
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.26 ! www 3: # $Id: lonsurveyreports.pm,v 1.25 2011/01/17 00:19:41 www Exp $
1.1 matthew 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;
1.8 albertel 30: use Apache::lonnet;
1.1 matthew 31: use Apache::loncommon();
32: use Apache::lonhtmlcommon();
1.25 www 33: use Apache::lonquickgrades();
1.1 matthew 34: use Apache::loncoursedata();
35: use Apache::lonstatistics;
36: use Apache::lonlocal;
37: use Apache::lonstathelpers;
1.4 matthew 38: use Spreadsheet::WriteExcel;
1.1 matthew 39: use HTML::Entities();
40: use Time::Local();
1.13 www 41: use lib '/home/httpd/lib/perl/';
42: use LONCAPA;
43:
1.1 matthew 44:
1.7 matthew 45: my @SubmitButtons = (
46: { name => 'break'},
47: { name => 'PrevProblem',
1.1 matthew 48: text => 'Previous Survey' },
49: { name => 'NextProblem',
50: text => 'Next Survey' },
1.7 matthew 51: { name => 'SelectAnother',
52: text => 'Choose a different Survey' },
1.1 matthew 53: { name => 'break'},
54: { name => 'Generate',
55: text => 'Generate Report'},
56: );
57:
58: sub BuildSurveyReportsPage {
59: my ($r,$c)=@_;
60: #
61: my %Saveable_Parameters = ('Status' => 'scalar',
62: 'Section' => 'array',
63: 'NumPlots' => 'scalar',
64: );
65: &Apache::loncommon::store_course_settings('survey_reports',
66: \%Saveable_Parameters);
1.24 raeburn 67: &Apache::loncommon::restore_course_settings('survey_reports',
1.1 matthew 68: \%Saveable_Parameters);
69: #
70: &Apache::lonstatistics::PrepareClasslist();
1.25 www 71: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Student Submission Reports'));
72: &Apache::lonquickgrades::startGradeScreen($r,'statistics');
73:
1.1 matthew 74: #
75: $r->print(&CreateInterface());
76: #
77: my @Students = @Apache::lonstatistics::Students;
78: #
79: if (@Students < 1) {
1.17 bisitz 80: $r->print('<p class="LC_warning">'.&mt('There are no students in the sections selected.').'</p>');
1.1 matthew 81: }
82: #
83: my @CacheButtonHTML =
84: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
85: $r->rflush();
86: #
1.8 albertel 87: if (exists($env{'form.problemchoice'}) &&
88: ! exists($env{'form.SelectAnother'})) {
1.7 matthew 89: $r->print(' 'x3);
1.1 matthew 90: foreach my $button (@SubmitButtons) {
91: if ($button->{'name'} eq 'break') {
92: $r->print("<br />\n");
93: } else {
94: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
95: 'value="'.&mt($button->{'text'}).'" />');
96: $r->print(' 'x5);
97: }
98: }
99: foreach my $html (@CacheButtonHTML) {
100: $r->print($html.(' 'x5));
101: }
102: #
103: $r->print('<hr />');
1.5 matthew 104: $r->print('<h4>'.
1.23 bisitz 105: &Apache::lonlocal::locallocaltime(time).', '.
1.5 matthew 106: &Apache::lonstatistics::section_and_enrollment_description().
107: '</h4>');
1.1 matthew 108: $r->rflush();
109: #
110: # Determine which problem we are to analyze
111: my $current_problem = &Apache::lonstathelpers::get_target_from_id
1.8 albertel 112: ($env{'form.problemchoice'});
1.1 matthew 113: #
1.3 matthew 114: my ($navmap,$prev,$curr,$next) =
1.1 matthew 115: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
116: '.',
117: 'part_survey',
118: );
1.8 albertel 119: if (exists($env{'form.PrevProblem'}) && defined($prev)) {
1.1 matthew 120: $current_problem = $prev;
1.8 albertel 121: } elsif (exists($env{'form.NextProblem'}) && defined($next)) {
1.1 matthew 122: $current_problem = $next;
123: } else {
124: $current_problem = $curr;
125: }
126: #
127: # Store the current problem choice and send it out in the form
1.8 albertel 128: $env{'form.problemchoice'} =
1.1 matthew 129: &Apache::lonstathelpers::make_target_id($current_problem);
130: $r->print('<input type="hidden" name="problemchoice" value="'.
1.8 albertel 131: $env{'form.problemchoice'}.'" />');
1.1 matthew 132: #
133: if (! defined($current_problem->{'resource'})) {
134: $r->print('resource is undefined');
135: } else {
136: my $resource = $current_problem->{'resource'};
1.3 matthew 137: $r->print('<h1>'.$resource->compTitle.'</h1>');
138: $r->print('<h3>'.$resource->src.'</h3>');
1.8 albertel 139: if ($env{'form.renderprob'} eq 'true') {
1.19 bisitz 140: $r->print('<hr />'
141: .&Apache::lonstathelpers::render_resource($resource)
142: .'<hr />'
143: );
1.6 matthew 144: }
1.1 matthew 145: $r->rflush();
146: my %Data = &Apache::lonstathelpers::get_problem_data
1.3 matthew 147: ($resource->src);
1.7 matthew 148: &compile_student_answers($r,$current_problem,\%Data,\@Students);
1.8 albertel 149: if ($env{'form.output'} eq 'HTML' ||
150: ! defined($env{'form.output'})) {
1.4 matthew 151: &make_HTML_report($r,$current_problem,\%Data,\@Students);
1.8 albertel 152: } elsif ($env{'form.output'} eq 'Excel') {
1.4 matthew 153: &make_Excel_report($r,$current_problem,\%Data,\@Students);
1.8 albertel 154: } elsif ($env{'form.output'} eq 'TXT') {
1.7 matthew 155: &make_text_report($r,$current_problem,\%Data,\@Students);
1.4 matthew 156: }
1.1 matthew 157: }
158: $r->print('<hr />');
159: } else {
160: $r->print('<input type="submit" name="Generate" value="'.
161: &mt('Generate Survey Report').'" />');
162: $r->print(' 'x5);
163: $r->print('<h3>'.&mt('Please select a Survey to analyze').'</h3>');
164: $r->print(&SurveyProblemSelector());
165: }
166: }
167:
168: ##########################################################
169: ##########################################################
170: ##
171: ## SurveyProblemSelector
172: ##
173: ##########################################################
174: ##########################################################
175: sub SurveyProblemSelector {
176: my $Str = '';
177: my @SurveyProblems;
1.3 matthew 178: my ($navmap,@sequences) =
179: &Apache::lonstatistics::selected_sequences_with_assessments('all');
180: foreach my $seq (@sequences) {
181: my @resources = &Apache::lonstathelpers::get_resources($navmap,$seq);
182: foreach my $res (@resources) {
183: foreach my $part (@{$res->parts}) {
1.24 raeburn 184: if (($res->is_survey($part)) || ($res->is_anonsurvey($part))) {
1.1 matthew 185: push(@SurveyProblems,{res=>$res,seq=>$seq,part=>$part});
186: last;
187: }
188: }
189: }
190: }
191: if (! scalar(@SurveyProblems)) {
1.17 bisitz 192: $Str = '<p class="LC_warning">'.
193: &mt('There are no survey problems in this course.').
194: '</p>'.$/;
1.1 matthew 195: return $Str;
196: }
197: $Str .= '<table>'.$/;
198: $Str .= '<tr>'.'<td></td>'.
1.3 matthew 199: '<th>'.&mt('Survey').'</th>'.
1.1 matthew 200: '</tr>'.$/;
1.3 matthew 201: my $id;
1.1 matthew 202: foreach my $problem (@SurveyProblems) {
1.3 matthew 203: $id++;
1.1 matthew 204: my $value = &Apache::lonstathelpers::make_target_id
1.3 matthew 205: ({symb=>$problem->{'res'}->symb,
1.1 matthew 206: part=>$problem->{'part'},
207: respid=>undef,
208: resptype=>undef});
209: my $checked = '';
1.8 albertel 210: if ($env{'form.problemchoice'} eq $value) {
1.19 bisitz 211: $checked = 'checked="checked" ';
1.1 matthew 212: }
1.16 raeburn 213: my $link = $problem->{'res'}->link.
214: '?symb='.&escape($problem->{'res'}->shown_symb);
1.3 matthew 215: $Str .= '<tr><td>'.
216: '<input type="radio" name="problemchoice" id="'.$id.'" '.
1.1 matthew 217: 'value="'.$value.'" '.$checked.'/>'.'</td>'.
1.21 bisitz 218: '<td><span class="LC_nobreak">'.
1.17 bisitz 219: '<label for="'.$id.'">'.$problem->{'res'}->compTitle.' ('.$problem->{'seq'}->compTitle.')'.'</label>'.
1.3 matthew 220: (' 'x2).
1.22 raeburn 221: '<a target="preview" href="'.$link.'">'.&mt('View survey').'</a></span></td></tr>'.$/;
1.1 matthew 222: }
223: $Str .= '</table>';
224: return $Str;
225: }
226:
227: #########################################################
228: #########################################################
229: ##
230: ## Compile Student Answers
231: ##
232: #########################################################
233: #########################################################
1.7 matthew 234: sub compile_student_answers {
235: my ($r,$problem,$ProblemData,$Students) = @_;
1.1 matthew 236: my $resource = $problem->{'resource'};
1.26 ! www 237: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,scalar(@$Students));
1.1 matthew 238: foreach my $student (@$Students) {
1.3 matthew 239: foreach my $partid (@{$resource->parts}) {
240: my @response_ids = $resource->responseIds($partid);
241: my @response_types = $resource->responseType($partid);
242: for (my $i=0;$i<=$#response_ids;$i++) {
243: my $respid = $response_ids[$i];
244: my $resptype = $response_types[$i];
1.1 matthew 245: my $results =
246: &Apache::loncoursedata::get_response_data_by_student
1.3 matthew 247: ($student,$resource->symb,$respid);
1.1 matthew 248: next if (! defined($results) || ref($results) ne 'ARRAY' ||
249: ref($results->[0]) ne 'ARRAY');
250: my $student_response =
251: $results->[0]->[&Apache::loncoursedata::RDs_submission()];
252: $problem->{'responsedata'}->{$partid}->{$respid}->{'_count'}++;
253: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
1.3 matthew 254: if ($resptype =~ /^(option|match)$/) {
255: my @responses = split('&',$student_response);
256: foreach my $response (@responses) {
257: my ($foilid,$option) =
258: map {
1.13 www 259: &unescape($_);
1.3 matthew 260: } split('=',$response);
261: $data->{'foil_count'}->{$foilid}++;
262: $data->{'foil_responses'}->{$foilid}->{$option}++;
263: }
264: } elsif ($resptype =~ /^(radiobutton)$/) {
1.13 www 265: my ($foil,$value) = map { &unescape($_); } split('=',$student_response);
1.1 matthew 266: $value += 1; # explicitly increment it...
267: $data->{'foil_responses'}->{$foil}++;
268: $data->{'foil_values'}->{$value}++;
269: if (! exists($data->{'map'}->{$value})) {
270: $data->{'map'}->{$value} = $foil;
1.15 albertel 271: $data->{'map_fv'}->{$foil} = $value;
1.1 matthew 272: }
273: } else {
274: # Variable stuff (essays, raw numbers, strings) go here
275: push(@{$data->{'responses'}},$student_response);
276: }
277: }
278: }
1.26 ! www 279: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.7 matthew 280: }
281: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
282: return;
283: }
284:
285:
286: #########################################################
287: #########################################################
288: ##
289: ## make_text_report
290: ##
291: #########################################################
292: #########################################################
293: sub make_text_report {
294: my ($r,$problem,$problem_data,$students) = @_;
295: my ($file,$filename) = &Apache::loncommon::create_text_file($r,'txt');
296: if (! defined($file)) { return '';}
297: $r->print('<script>'.
298: 'window.document.Statistics.stats_status.value="'.
299: &mt('Building text document.').
300: '";</script>');
301: my $resource = $problem->{'resource'};
302: print $file $resource->compTitle.$/;
303: print $file &Apache::lonstatistics::section_and_enrollment_description().
304: ' '.&mt('Generated on [_1]',&Apache::lonlocal::locallocaltime(time)).
305: $/;
306: my $something_has_been_output = 0;
307: foreach my $partid (@{$resource->parts}) {
308: my @response_ids = $resource->responseIds($partid);
309: my @response_types = $resource->responseType($partid);
310: for (my $i=0;$i<=$#response_ids;$i++) {
311: my $respid = $response_ids[$i];
312: my $resptype = $response_types[$i];
313: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
314: if (exists($data->{'responses'}) &&
315: ref($data->{'responses'}) eq 'ARRAY') {
316: # Essay type response
317: print $file ('-'x40).$/;
318: print $file
319: $resource->part_display($partid).', '.$respid.':'.$resptype.$/;
320: foreach my $submission (@{$data->{'responses'}}) {
321: print $file ('-'x20).$/;
322: $submission =~ s/(\\r\\n|\\n)/\n/g;
323: $submission =~ s/\\(\'|\"|\`)/$1/g;
324: print $file $submission.$/.$/;
325: $something_has_been_output=1;
326: }
327: }
328: }
1.1 matthew 329: }
1.7 matthew 330: close($file);
331: if($something_has_been_output) {
1.17 bisitz 332: $r->print('<p class="LC_info"><a href="'.$filename.'">'.
333: &mt('Your text file').
1.7 matthew 334: '</a></p>'."\n");
335: $r->print('<script>'.
336: 'window.document.Statistics.stats_status.value="'.
1.17 bisitz 337: &mt('Done compiling text file. See link below to download.').
1.7 matthew 338: '";</script>');
339: } else {
1.17 bisitz 340: $r->print('<p class="LC_warning">'
341: .&mt('There is no essay or string response data to output for this survey.')
1.22 raeburn 342: .'</p>');
1.7 matthew 343: }
344: $r->rflush();
1.1 matthew 345: return;
346: }
347:
1.7 matthew 348:
1.1 matthew 349: #########################################################
350: #########################################################
351: ##
1.4 matthew 352: ## make_Excel_report
353: ##
354: #########################################################
355: #########################################################
356: sub make_Excel_report {
357: my ($r,$problem,$problem_data,$students) = @_;
358: my ($workbook,$filename,$format) = &Apache::loncommon::create_workbook($r);
359: if (! defined($workbook)) { return '';}
360: $r->print('<script>'.
361: 'window.document.Statistics.stats_status.value="'.
362: &mt('Building spreadsheet.').
363: '";</script>');
364: my $worksheet = $workbook->addworksheet('Survey Reports');
365: #
366: my $rows_output=0;
367: $worksheet->write($rows_output++,0,
1.8 albertel 368: $env{'course.'.$env{'request.course.id'}.'.description'},
1.4 matthew 369: $format->{'h1'});
370: $rows_output++;
371: #
372: my $resource = $problem->{'resource'};
373: $worksheet->write($rows_output++,0,$resource->compTitle,$format->{'h2'});
374: foreach my $partid (@{$resource->parts}) {
375: my @response_ids = $resource->responseIds($partid);
376: my @response_types = $resource->responseType($partid);
377: for (my $i=0;$i<=$#response_ids;$i++) {
378: my $respid = $response_ids[$i];
379: my $resptype = $response_types[$i];
380: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
381: my $cols_output=0;
382: $worksheet->write($rows_output,$cols_output++,
383: $resource->part_display($partid),$format->{'h3'});
384: $worksheet->write($rows_output,$cols_output++,
385: 'Response '.$respid.', '.$resptype,
386: $format->{'h3'});
387: $rows_output++;
388: if (exists($data->{'responses'}) &&
389: ref($data->{'responses'}) eq 'ARRAY') {
390: my $warned_about_size = 0;
391: foreach my $data (@{$data->{'responses'}}) {
392: if (length($data) > 255 && ! $warned_about_size) {
1.17 bisitz 393: $r->print('<p class="LC_warning">'.
394: &mt('[_1]:[_2] responses to [_3] may be too long to fit Excel spreadsheet.',
1.4 matthew 395: $resource->compTitle,
396: $resource->part_display($partid),
397: $respid).
398: '</p>');
399: $r->rflush();
400: $warned_about_size=1;
401: }
402: $worksheet->write($rows_output++,0,$data);
403: }
404: } elsif (exists($data->{'foil_count'}) &&
405: exists($data->{'foil_responses'})) {
406: my $respdata = $problem_data->{$partid.'.'.$respid};
407: my @rowdata = ('Foil Name','Foil Text','Option',
408: 'Frequency');
409: $worksheet->write_row($rows_output++,0,
410: \@rowdata,$format->{'h4'});
411: #
1.15 albertel 412: my @foils = sort(keys(%{$respdata->{'_Foils'}}));
1.4 matthew 413: foreach my $foilid (@foils) {
414: my $foil_count = $data->{'foil_count'}->{$foilid};
415: my $foiltext = $respdata->{'_Foils'}->{$foilid}->{'text'};
416: my $foilname = $respdata->{'_Foils'}->{$foilid}->{'name'};
417: $foiltext = &HTML::Entities::decode($foilname);
418: my $cols_output=0;
419: $worksheet->write($rows_output,$cols_output++,$foilname);
420: $worksheet->write($rows_output,$cols_output++,$foiltext);
421: my $option_start_col = $cols_output;
422: #
423: foreach my $option (sort(@{$respdata->{'_Options'}})){
424: $cols_output= $option_start_col;
425: $worksheet->write($rows_output,$cols_output++,
426: $option);
427: my $count=
428: $data->{'foil_responses'}->{$foilid}->{$option};
429: $worksheet->write($rows_output,$cols_output++,$count);
430: $rows_output++;
431: }
432: }
433: } elsif (exists($data->{'_count'}) &&
434: exists($data->{'foil_values'}) &&
435: exists($data->{'map'})) {
436: my $respdata = $problem_data->{$partid.'.'.$respid};
437: my @rowdata = ('Foil Name','Foil Text','Frequency');
438: $worksheet->write_row($rows_output++,0,
439: \@rowdata,$format->{'h4'});
1.15 albertel 440: my @foils = sort(keys(%{$respdata->{'_Foils'}}));
441: foreach my $foilid (@foils) {
1.4 matthew 442: undef(@rowdata);
1.15 albertel 443: my $value = $data->{'map_fv'}->{$foilid};
1.4 matthew 444: push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'name'});
445: push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'text'});
446: push(@rowdata,$data->{'foil_values'}->{$value});
447: $worksheet->write_row($rows_output++,0,\@rowdata);
448: }
449: }
450: $rows_output++;
451: } #response ids
452: } # partids
453: $workbook->close();
1.17 bisitz 454: $r->print('<p class="LC_info"><a href="'.$filename.'">'.
1.4 matthew 455: &mt('Your Excel spreadsheet.').
456: '</a></p>'."\n");
457: $r->print('<script>'.
458: 'window.document.Statistics.stats_status.value="'.
1.17 bisitz 459: &mt('Done compiling spreadsheet. See link below to download.').
1.4 matthew 460: '";</script>');
461: $r->rflush();
462: return;
463: }
464:
465: #########################################################
466: #########################################################
467: ##
1.1 matthew 468: ## make_HTML_report
469: ##
470: #########################################################
471: #########################################################
472: sub make_HTML_report {
473: my ($r,$problem,$ProblemData,$Students) = @_;
474: my $resource = $problem->{'resource'};
1.3 matthew 475: foreach my $partid (@{$resource->parts}) {
476: my @response_ids = $resource->responseIds($partid);
477: my @response_types = $resource->responseType($partid);
478: for (my $i=0;$i<=$#response_ids;$i++) {
1.1 matthew 479: my $Str = '<table>'.$/;
1.3 matthew 480: my $respid = $response_ids[$i];
481: my $resptype = $response_types[$i];
1.1 matthew 482: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
1.3 matthew 483: if (! defined($data) || ref($data) ne 'HASH') {
484: next;
485: }
1.1 matthew 486: # Debugging code
487: # $Str .= '<tr>'.
488: # '<td>'.$partid.'</td>'.
489: # '<td>'.$respid.'</td>'.
490: # '<td>'.$resptype.'</td>'.
491: # '</tr>'.$/;
492: $Str .= '<tr>'.
493: '<td><b>'.&mt('Total').'</b></td>'.
494: '<td>'.$data->{'_count'}.'</td>'.
1.9 albertel 495: '<td>'.&mt('Part [_1], Response [_2]',
496: $resource->part_display($partid),$respid).'</td>'.
1.3 matthew 497: '</tr>';
1.1 matthew 498: if (exists($data->{'responses'}) &&
499: ref($data->{'responses'}) eq 'ARRAY') {
500: &randomize_array($data->{'responses'});
501: foreach my $response (@{$data->{'responses'}}) {
502: $response =~ s/\\r\\n/\n/g;
503: $response =~ s/\\'/'/g;
504: $response =~ s/\\"/"/g;
505: $Str .= '<tr>'.
506: '<td colspan="3"><pre>'.
507: &HTML::Entities::encode($response,'<>&').
508: '</pre><hr /></td>'.
509: '</tr>'.$/;
510: }
1.3 matthew 511: } elsif (exists($data->{'foil_count'}) &&
512: exists($data->{'foil_responses'})) {
1.17 bisitz 513: $Str.='<tr>'
514: .'<td colspan="3">'
515: .&Apache::loncommon::start_data_table()
516: .&Apache::loncommon::start_data_table_header_row();
1.3 matthew 517: my $tmp = '<th>'.join('</th><th>',
518: (&mt('Foil Name'),
519: &mt('Foil Text'),
520: &mt('Option'),
521: &mt('Frequency'),
1.17 bisitz 522: &mt('Percent'))).'</th>'
523: .&Apache::loncommon::end_data_table_header_row();
1.15 albertel 524: my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid}->{'_Foils'}}));
1.3 matthew 525: foreach my $foilid (@foils) {
526: my $prob_data = $ProblemData->{$partid.'.'.$respid};
527: my $foil_count = $data->{'foil_count'}->{$foilid};
528: my $foiltext = $prob_data->{'_Foils'}->{$foilid}->{'text'};
529: my $foilname = $prob_data->{'_Foils'}->{$foilid}->{'name'};
530: my $rowspan = scalar(@{$prob_data->{'_Options'}});
1.17 bisitz 531: my $preamble = &Apache::loncommon::start_data_table_row().
1.3 matthew 532: '<td valign="top" rowspan="'.$rowspan.'">'.
533: $foilname.'</td>'.
534: '<td valign="top" rowspan="'.$rowspan.'">'.
535: $foiltext.'</td>';
536: foreach my $option (sort(@{$prob_data->{'_Options'}})){
537: my $count =
538: $data->{'foil_responses'}->{$foilid}->{$option};
539: $tmp .= $preamble.
540: '<td>'.$option.'</td>'.
541: '<td align="right">'.$count.'</td>'.
542: '<td align="right">'.
543: sprintf('%.2f',100*$count/$foil_count).'%'.
1.17 bisitz 544: '</td>'.&Apache::loncommon::end_data_table_row().$/;
545: $preamble = &Apache::loncommon::continue_data_table_row(); #&Apache::loncommon::start_data_table_row();
1.3 matthew 546: }
547: }
1.17 bisitz 548: $Str.=$tmp.&Apache::loncommon::end_data_table()
549: .'</td></tr>';
1.1 matthew 550: } elsif (exists($data->{'_count'}) &&
551: exists($data->{'foil_values'}) &&
552: exists($data->{'map'})) {
553: # This is an option or radiobutton survey response
554: my $total = $data->{'_count'};
555: my $sum = 0;
556: my $tmp;
1.15 albertel 557: my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid}
558: ->{'_Foils'}}));
559: foreach my $foilid (@foils) {
560: my $value = $data->{'map_fv'}->{$foilid};
1.1 matthew 561: my $count = $data->{'foil_values'}->{$value};
562: my $foiltext = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'text'};
563: my $foilname = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'name'};
1.17 bisitz 564: $tmp .= &Apache::loncommon::start_data_table_row().
1.1 matthew 565: '<td>'.$foilname.'</td>'.
566: '<td>'.$foiltext.'</td>'.
567: '<td align="right">'.$count.'</td>'.
568: '<td align="right">'.
569: sprintf("%.2f",$count/$total*100).'%</td>'.
1.17 bisitz 570: &Apache::loncommon::end_data_table_row().$/;
1.1 matthew 571: }
1.20 bisitz 572: $Str.='<tr>'
573: .'<td colspan="3">'
574: .&Apache::loncommon::start_data_table()
575: .&Apache::loncommon::start_data_table_header_row()
576: .'<th>'.&mt('Foil Name').'</th>'
577: .'<th>'.&mt('Text').'</th>'
578: .'<th>'.&mt('Frequency').'</th>'
579: .'<th>'.&mt('Percent').'</th>'
580: .&Apache::loncommon::end_data_table_header_row().$/
581: .$tmp
582: .&Apache::loncommon::end_data_table()
583: .'</td></tr>';
1.1 matthew 584: }
1.20 bisitz 585: $Str.= '</table>';
1.1 matthew 586: $r->print($Str);
587: $r->rflush();
588: }
589: }
590: return;
591: }
592:
593: sub randomize_array {
594: # Fisher Yates shuffle, lifted from p 121 of "The Perl Cookbook"
595: my ($array) = @_;
596: for (my $i=scalar(@$array);--$i;) {
597: my $j = int(rand($i+1));
598: next if ($i == $j);
599: @$array[$i,$j]=@$array[$j,$i];
600: }
601: }
602:
603: #########################################################
604: #########################################################
605: ##
606: ## Generic Interface Routines
607: ##
608: #########################################################
609: #########################################################
610: sub CreateInterface {
611: ##
612: ## Environment variable initialization
613: my $Str = '';
1.4 matthew 614: my $output_selector = '<select name="output" size="5">'.$/;
1.8 albertel 615: if (! exists($env{'form.output'})) {
616: $env{'form.output'} = 'HTML';
1.4 matthew 617: }
618: foreach my $output_format ( {name=>'HTML',text=>&mt("HTML") },
1.7 matthew 619: {name=>'Excel',text=>&mt("Excel") },
620: {name=>'TXT',text=>&mt("Text (essays only)") },
621: ) {
1.4 matthew 622: $output_selector.='<option value="'.$output_format->{'name'}.'"';
1.8 albertel 623: if ($env{'form.output'} eq $output_format->{'name'}) {
1.19 bisitz 624: $output_selector.=' selected="selected"';
1.4 matthew 625: }
626: $output_selector.= '>'.$output_format->{'text'}.'</option>'.$/;
627: }
628: $output_selector .= '</select>'.$/;
1.1 matthew 629: $Str .= '<p>';
1.19 bisitz 630: $Str .= &Apache::loncommon::start_data_table();
631: $Str .= &Apache::loncommon::start_data_table_header_row();
1.6 matthew 632: $Str .= '<th>'.&mt('Sections').'</th>';
1.12 raeburn 633: $Str .= '<th>'.&mt('Groups').'</th>';
1.14 raeburn 634: $Str .= '<th>'.&mt('Access Status').'</th>';
1.6 matthew 635: $Str .= '<th>'.&mt('Output Format').'</th>';
1.19 bisitz 636: $Str .= '<th>'.&mt('Options').'</th>';
637: $Str .= &Apache::loncommon::end_data_table_header_row();
1.1 matthew 638: #
1.19 bisitz 639: $Str .= &Apache::loncommon::start_data_table_row();
640: $Str .= '<td align="center">'."\n";
1.1 matthew 641: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
642: $Str .= '</td>';
643: #
1.12 raeburn 644: $Str .= '<td align="center">'."\n";
645: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
646: $Str .= '</td>';
647: #
1.1 matthew 648: $Str .= '<td align="center">';
649: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
650: $Str .= '</td>';
651: #
1.4 matthew 652: $Str .= '<td align="center">'.$output_selector.'</td>';
653: #
1.6 matthew 654: # Render problem checkbox
655: my $prob_checkbox = '<input type="checkbox" name="renderprob" ';
1.8 albertel 656: if (exists($env{'form.renderprob'}) && $env{'form.renderprob'} eq 'true') {
1.19 bisitz 657: $prob_checkbox .= 'checked="checked" ';
1.6 matthew 658: }
659: $prob_checkbox .= 'value="true" />';
1.23 bisitz 660: $Str .=
661: '<td valign="top">'
662: .'<label>'
663: .$prob_checkbox.&mt('Show problem')
664: .'</label>'
665: .'</td>';
1.6 matthew 666: #
1.19 bisitz 667: $Str .= &Apache::loncommon::end_data_table_row();
668: $Str .= &Apache::loncommon::end_data_table();
1.1 matthew 669: #
1.18 bisitz 670: $Str .= '</p>';
1.1 matthew 671: ##
672: return $Str;
673: }
674:
675: 1;
676:
677: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>