Annotation of loncom/interface/statistics/lonsurveyreports.pm, revision 1.25
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.25 ! www 3: # $Id: lonsurveyreports.pm,v 1.24 2010/02/28 23:58:55 raeburn 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.7 matthew 237: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
238: ($r,'Processing Student Submissions',
239: 'Processing Student Submissions',
240: scalar(@$Students),'inline',undef,'Statistics','stats_status');
1.1 matthew 241: foreach my $student (@$Students) {
1.3 matthew 242: foreach my $partid (@{$resource->parts}) {
243: my @response_ids = $resource->responseIds($partid);
244: my @response_types = $resource->responseType($partid);
245: for (my $i=0;$i<=$#response_ids;$i++) {
246: my $respid = $response_ids[$i];
247: my $resptype = $response_types[$i];
1.1 matthew 248: my $results =
249: &Apache::loncoursedata::get_response_data_by_student
1.3 matthew 250: ($student,$resource->symb,$respid);
1.1 matthew 251: next if (! defined($results) || ref($results) ne 'ARRAY' ||
252: ref($results->[0]) ne 'ARRAY');
253: my $student_response =
254: $results->[0]->[&Apache::loncoursedata::RDs_submission()];
255: $problem->{'responsedata'}->{$partid}->{$respid}->{'_count'}++;
256: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
1.3 matthew 257: if ($resptype =~ /^(option|match)$/) {
258: my @responses = split('&',$student_response);
259: foreach my $response (@responses) {
260: my ($foilid,$option) =
261: map {
1.13 www 262: &unescape($_);
1.3 matthew 263: } split('=',$response);
264: $data->{'foil_count'}->{$foilid}++;
265: $data->{'foil_responses'}->{$foilid}->{$option}++;
266: }
267: } elsif ($resptype =~ /^(radiobutton)$/) {
1.13 www 268: my ($foil,$value) = map { &unescape($_); } split('=',$student_response);
1.1 matthew 269: $value += 1; # explicitly increment it...
270: $data->{'foil_responses'}->{$foil}++;
271: $data->{'foil_values'}->{$value}++;
272: if (! exists($data->{'map'}->{$value})) {
273: $data->{'map'}->{$value} = $foil;
1.15 albertel 274: $data->{'map_fv'}->{$foil} = $value;
1.1 matthew 275: }
276: } else {
277: # Variable stuff (essays, raw numbers, strings) go here
278: push(@{$data->{'responses'}},$student_response);
279: }
280: }
281: }
1.7 matthew 282: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
283: 'last student');
284: }
285: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
286: return;
287: }
288:
289:
290: #########################################################
291: #########################################################
292: ##
293: ## make_text_report
294: ##
295: #########################################################
296: #########################################################
297: sub make_text_report {
298: my ($r,$problem,$problem_data,$students) = @_;
299: my ($file,$filename) = &Apache::loncommon::create_text_file($r,'txt');
300: if (! defined($file)) { return '';}
301: $r->print('<script>'.
302: 'window.document.Statistics.stats_status.value="'.
303: &mt('Building text document.').
304: '";</script>');
305: my $resource = $problem->{'resource'};
306: print $file $resource->compTitle.$/;
307: print $file &Apache::lonstatistics::section_and_enrollment_description().
308: ' '.&mt('Generated on [_1]',&Apache::lonlocal::locallocaltime(time)).
309: $/;
310: my $something_has_been_output = 0;
311: foreach my $partid (@{$resource->parts}) {
312: my @response_ids = $resource->responseIds($partid);
313: my @response_types = $resource->responseType($partid);
314: for (my $i=0;$i<=$#response_ids;$i++) {
315: my $respid = $response_ids[$i];
316: my $resptype = $response_types[$i];
317: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
318: if (exists($data->{'responses'}) &&
319: ref($data->{'responses'}) eq 'ARRAY') {
320: # Essay type response
321: print $file ('-'x40).$/;
322: print $file
323: $resource->part_display($partid).', '.$respid.':'.$resptype.$/;
324: foreach my $submission (@{$data->{'responses'}}) {
325: print $file ('-'x20).$/;
326: $submission =~ s/(\\r\\n|\\n)/\n/g;
327: $submission =~ s/\\(\'|\"|\`)/$1/g;
328: print $file $submission.$/.$/;
329: $something_has_been_output=1;
330: }
331: }
332: }
1.1 matthew 333: }
1.7 matthew 334: close($file);
335: if($something_has_been_output) {
1.17 bisitz 336: $r->print('<p class="LC_info"><a href="'.$filename.'">'.
337: &mt('Your text file').
1.7 matthew 338: '</a></p>'."\n");
339: $r->print('<script>'.
340: 'window.document.Statistics.stats_status.value="'.
1.17 bisitz 341: &mt('Done compiling text file. See link below to download.').
1.7 matthew 342: '";</script>');
343: } else {
1.17 bisitz 344: $r->print('<p class="LC_warning">'
345: .&mt('There is no essay or string response data to output for this survey.')
1.22 raeburn 346: .'</p>');
1.7 matthew 347: }
348: $r->rflush();
1.1 matthew 349: return;
350: }
351:
1.7 matthew 352:
1.1 matthew 353: #########################################################
354: #########################################################
355: ##
1.4 matthew 356: ## make_Excel_report
357: ##
358: #########################################################
359: #########################################################
360: sub make_Excel_report {
361: my ($r,$problem,$problem_data,$students) = @_;
362: my ($workbook,$filename,$format) = &Apache::loncommon::create_workbook($r);
363: if (! defined($workbook)) { return '';}
364: $r->print('<script>'.
365: 'window.document.Statistics.stats_status.value="'.
366: &mt('Building spreadsheet.').
367: '";</script>');
368: my $worksheet = $workbook->addworksheet('Survey Reports');
369: #
370: my $rows_output=0;
371: $worksheet->write($rows_output++,0,
1.8 albertel 372: $env{'course.'.$env{'request.course.id'}.'.description'},
1.4 matthew 373: $format->{'h1'});
374: $rows_output++;
375: #
376: my $resource = $problem->{'resource'};
377: $worksheet->write($rows_output++,0,$resource->compTitle,$format->{'h2'});
378: foreach my $partid (@{$resource->parts}) {
379: my @response_ids = $resource->responseIds($partid);
380: my @response_types = $resource->responseType($partid);
381: for (my $i=0;$i<=$#response_ids;$i++) {
382: my $respid = $response_ids[$i];
383: my $resptype = $response_types[$i];
384: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
385: my $cols_output=0;
386: $worksheet->write($rows_output,$cols_output++,
387: $resource->part_display($partid),$format->{'h3'});
388: $worksheet->write($rows_output,$cols_output++,
389: 'Response '.$respid.', '.$resptype,
390: $format->{'h3'});
391: $rows_output++;
392: if (exists($data->{'responses'}) &&
393: ref($data->{'responses'}) eq 'ARRAY') {
394: my $warned_about_size = 0;
395: foreach my $data (@{$data->{'responses'}}) {
396: if (length($data) > 255 && ! $warned_about_size) {
1.17 bisitz 397: $r->print('<p class="LC_warning">'.
398: &mt('[_1]:[_2] responses to [_3] may be too long to fit Excel spreadsheet.',
1.4 matthew 399: $resource->compTitle,
400: $resource->part_display($partid),
401: $respid).
402: '</p>');
403: $r->rflush();
404: $warned_about_size=1;
405: }
406: $worksheet->write($rows_output++,0,$data);
407: }
408: } elsif (exists($data->{'foil_count'}) &&
409: exists($data->{'foil_responses'})) {
410: my $respdata = $problem_data->{$partid.'.'.$respid};
411: my @rowdata = ('Foil Name','Foil Text','Option',
412: 'Frequency');
413: $worksheet->write_row($rows_output++,0,
414: \@rowdata,$format->{'h4'});
415: #
1.15 albertel 416: my @foils = sort(keys(%{$respdata->{'_Foils'}}));
1.4 matthew 417: foreach my $foilid (@foils) {
418: my $foil_count = $data->{'foil_count'}->{$foilid};
419: my $foiltext = $respdata->{'_Foils'}->{$foilid}->{'text'};
420: my $foilname = $respdata->{'_Foils'}->{$foilid}->{'name'};
421: $foiltext = &HTML::Entities::decode($foilname);
422: my $cols_output=0;
423: $worksheet->write($rows_output,$cols_output++,$foilname);
424: $worksheet->write($rows_output,$cols_output++,$foiltext);
425: my $option_start_col = $cols_output;
426: #
427: foreach my $option (sort(@{$respdata->{'_Options'}})){
428: $cols_output= $option_start_col;
429: $worksheet->write($rows_output,$cols_output++,
430: $option);
431: my $count=
432: $data->{'foil_responses'}->{$foilid}->{$option};
433: $worksheet->write($rows_output,$cols_output++,$count);
434: $rows_output++;
435: }
436: }
437: } elsif (exists($data->{'_count'}) &&
438: exists($data->{'foil_values'}) &&
439: exists($data->{'map'})) {
440: my $respdata = $problem_data->{$partid.'.'.$respid};
441: my @rowdata = ('Foil Name','Foil Text','Frequency');
442: $worksheet->write_row($rows_output++,0,
443: \@rowdata,$format->{'h4'});
1.15 albertel 444: my @foils = sort(keys(%{$respdata->{'_Foils'}}));
445: foreach my $foilid (@foils) {
1.4 matthew 446: undef(@rowdata);
1.15 albertel 447: my $value = $data->{'map_fv'}->{$foilid};
1.4 matthew 448: push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'name'});
449: push(@rowdata,$respdata->{'_Foils'}->{$foilid}->{'text'});
450: push(@rowdata,$data->{'foil_values'}->{$value});
451: $worksheet->write_row($rows_output++,0,\@rowdata);
452: }
453: }
454: $rows_output++;
455: } #response ids
456: } # partids
457: $workbook->close();
1.17 bisitz 458: $r->print('<p class="LC_info"><a href="'.$filename.'">'.
1.4 matthew 459: &mt('Your Excel spreadsheet.').
460: '</a></p>'."\n");
461: $r->print('<script>'.
462: 'window.document.Statistics.stats_status.value="'.
1.17 bisitz 463: &mt('Done compiling spreadsheet. See link below to download.').
1.4 matthew 464: '";</script>');
465: $r->rflush();
466: return;
467: }
468:
469: #########################################################
470: #########################################################
471: ##
1.1 matthew 472: ## make_HTML_report
473: ##
474: #########################################################
475: #########################################################
476: sub make_HTML_report {
477: my ($r,$problem,$ProblemData,$Students) = @_;
478: my $resource = $problem->{'resource'};
1.3 matthew 479: foreach my $partid (@{$resource->parts}) {
480: my @response_ids = $resource->responseIds($partid);
481: my @response_types = $resource->responseType($partid);
482: for (my $i=0;$i<=$#response_ids;$i++) {
1.1 matthew 483: my $Str = '<table>'.$/;
1.3 matthew 484: my $respid = $response_ids[$i];
485: my $resptype = $response_types[$i];
1.1 matthew 486: my $data = $problem->{'responsedata'}->{$partid}->{$respid};
1.3 matthew 487: if (! defined($data) || ref($data) ne 'HASH') {
488: next;
489: }
1.1 matthew 490: # Debugging code
491: # $Str .= '<tr>'.
492: # '<td>'.$partid.'</td>'.
493: # '<td>'.$respid.'</td>'.
494: # '<td>'.$resptype.'</td>'.
495: # '</tr>'.$/;
496: $Str .= '<tr>'.
497: '<td><b>'.&mt('Total').'</b></td>'.
498: '<td>'.$data->{'_count'}.'</td>'.
1.9 albertel 499: '<td>'.&mt('Part [_1], Response [_2]',
500: $resource->part_display($partid),$respid).'</td>'.
1.3 matthew 501: '</tr>';
1.1 matthew 502: if (exists($data->{'responses'}) &&
503: ref($data->{'responses'}) eq 'ARRAY') {
504: &randomize_array($data->{'responses'});
505: foreach my $response (@{$data->{'responses'}}) {
506: $response =~ s/\\r\\n/\n/g;
507: $response =~ s/\\'/'/g;
508: $response =~ s/\\"/"/g;
509: $Str .= '<tr>'.
510: '<td colspan="3"><pre>'.
511: &HTML::Entities::encode($response,'<>&').
512: '</pre><hr /></td>'.
513: '</tr>'.$/;
514: }
1.3 matthew 515: } elsif (exists($data->{'foil_count'}) &&
516: exists($data->{'foil_responses'})) {
1.17 bisitz 517: $Str.='<tr>'
518: .'<td colspan="3">'
519: .&Apache::loncommon::start_data_table()
520: .&Apache::loncommon::start_data_table_header_row();
1.3 matthew 521: my $tmp = '<th>'.join('</th><th>',
522: (&mt('Foil Name'),
523: &mt('Foil Text'),
524: &mt('Option'),
525: &mt('Frequency'),
1.17 bisitz 526: &mt('Percent'))).'</th>'
527: .&Apache::loncommon::end_data_table_header_row();
1.15 albertel 528: my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid}->{'_Foils'}}));
1.3 matthew 529: foreach my $foilid (@foils) {
530: my $prob_data = $ProblemData->{$partid.'.'.$respid};
531: my $foil_count = $data->{'foil_count'}->{$foilid};
532: my $foiltext = $prob_data->{'_Foils'}->{$foilid}->{'text'};
533: my $foilname = $prob_data->{'_Foils'}->{$foilid}->{'name'};
534: my $rowspan = scalar(@{$prob_data->{'_Options'}});
1.17 bisitz 535: my $preamble = &Apache::loncommon::start_data_table_row().
1.3 matthew 536: '<td valign="top" rowspan="'.$rowspan.'">'.
537: $foilname.'</td>'.
538: '<td valign="top" rowspan="'.$rowspan.'">'.
539: $foiltext.'</td>';
540: foreach my $option (sort(@{$prob_data->{'_Options'}})){
541: my $count =
542: $data->{'foil_responses'}->{$foilid}->{$option};
543: $tmp .= $preamble.
544: '<td>'.$option.'</td>'.
545: '<td align="right">'.$count.'</td>'.
546: '<td align="right">'.
547: sprintf('%.2f',100*$count/$foil_count).'%'.
1.17 bisitz 548: '</td>'.&Apache::loncommon::end_data_table_row().$/;
549: $preamble = &Apache::loncommon::continue_data_table_row(); #&Apache::loncommon::start_data_table_row();
1.3 matthew 550: }
551: }
1.17 bisitz 552: $Str.=$tmp.&Apache::loncommon::end_data_table()
553: .'</td></tr>';
1.1 matthew 554: } elsif (exists($data->{'_count'}) &&
555: exists($data->{'foil_values'}) &&
556: exists($data->{'map'})) {
557: # This is an option or radiobutton survey response
558: my $total = $data->{'_count'};
559: my $sum = 0;
560: my $tmp;
1.15 albertel 561: my @foils = sort(keys(%{$ProblemData->{$partid.'.'.$respid}
562: ->{'_Foils'}}));
563: foreach my $foilid (@foils) {
564: my $value = $data->{'map_fv'}->{$foilid};
1.1 matthew 565: my $count = $data->{'foil_values'}->{$value};
566: my $foiltext = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'text'};
567: my $foilname = $ProblemData->{$partid.'.'.$respid}->{'_Foils'}->{$foilid}->{'name'};
1.17 bisitz 568: $tmp .= &Apache::loncommon::start_data_table_row().
1.1 matthew 569: '<td>'.$foilname.'</td>'.
570: '<td>'.$foiltext.'</td>'.
571: '<td align="right">'.$count.'</td>'.
572: '<td align="right">'.
573: sprintf("%.2f",$count/$total*100).'%</td>'.
1.17 bisitz 574: &Apache::loncommon::end_data_table_row().$/;
1.1 matthew 575: }
1.20 bisitz 576: $Str.='<tr>'
577: .'<td colspan="3">'
578: .&Apache::loncommon::start_data_table()
579: .&Apache::loncommon::start_data_table_header_row()
580: .'<th>'.&mt('Foil Name').'</th>'
581: .'<th>'.&mt('Text').'</th>'
582: .'<th>'.&mt('Frequency').'</th>'
583: .'<th>'.&mt('Percent').'</th>'
584: .&Apache::loncommon::end_data_table_header_row().$/
585: .$tmp
586: .&Apache::loncommon::end_data_table()
587: .'</td></tr>';
1.1 matthew 588: }
1.20 bisitz 589: $Str.= '</table>';
1.1 matthew 590: $r->print($Str);
591: $r->rflush();
592: }
593: }
594: return;
595: }
596:
597: sub randomize_array {
598: # Fisher Yates shuffle, lifted from p 121 of "The Perl Cookbook"
599: my ($array) = @_;
600: for (my $i=scalar(@$array);--$i;) {
601: my $j = int(rand($i+1));
602: next if ($i == $j);
603: @$array[$i,$j]=@$array[$j,$i];
604: }
605: }
606:
607: #########################################################
608: #########################################################
609: ##
610: ## Generic Interface Routines
611: ##
612: #########################################################
613: #########################################################
614: sub CreateInterface {
615: ##
616: ## Environment variable initialization
617: my $Str = '';
1.4 matthew 618: my $output_selector = '<select name="output" size="5">'.$/;
1.8 albertel 619: if (! exists($env{'form.output'})) {
620: $env{'form.output'} = 'HTML';
1.4 matthew 621: }
622: foreach my $output_format ( {name=>'HTML',text=>&mt("HTML") },
1.7 matthew 623: {name=>'Excel',text=>&mt("Excel") },
624: {name=>'TXT',text=>&mt("Text (essays only)") },
625: ) {
1.4 matthew 626: $output_selector.='<option value="'.$output_format->{'name'}.'"';
1.8 albertel 627: if ($env{'form.output'} eq $output_format->{'name'}) {
1.19 bisitz 628: $output_selector.=' selected="selected"';
1.4 matthew 629: }
630: $output_selector.= '>'.$output_format->{'text'}.'</option>'.$/;
631: }
632: $output_selector .= '</select>'.$/;
1.1 matthew 633: $Str .= '<p>';
1.19 bisitz 634: $Str .= &Apache::loncommon::start_data_table();
635: $Str .= &Apache::loncommon::start_data_table_header_row();
1.6 matthew 636: $Str .= '<th>'.&mt('Sections').'</th>';
1.12 raeburn 637: $Str .= '<th>'.&mt('Groups').'</th>';
1.14 raeburn 638: $Str .= '<th>'.&mt('Access Status').'</th>';
1.6 matthew 639: $Str .= '<th>'.&mt('Output Format').'</th>';
1.19 bisitz 640: $Str .= '<th>'.&mt('Options').'</th>';
641: $Str .= &Apache::loncommon::end_data_table_header_row();
1.1 matthew 642: #
1.19 bisitz 643: $Str .= &Apache::loncommon::start_data_table_row();
644: $Str .= '<td align="center">'."\n";
1.1 matthew 645: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
646: $Str .= '</td>';
647: #
1.12 raeburn 648: $Str .= '<td align="center">'."\n";
649: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
650: $Str .= '</td>';
651: #
1.1 matthew 652: $Str .= '<td align="center">';
653: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
654: $Str .= '</td>';
655: #
1.4 matthew 656: $Str .= '<td align="center">'.$output_selector.'</td>';
657: #
1.6 matthew 658: # Render problem checkbox
659: my $prob_checkbox = '<input type="checkbox" name="renderprob" ';
1.8 albertel 660: if (exists($env{'form.renderprob'}) && $env{'form.renderprob'} eq 'true') {
1.19 bisitz 661: $prob_checkbox .= 'checked="checked" ';
1.6 matthew 662: }
663: $prob_checkbox .= 'value="true" />';
1.23 bisitz 664: $Str .=
665: '<td valign="top">'
666: .'<label>'
667: .$prob_checkbox.&mt('Show problem')
668: .'</label>'
669: .'</td>';
1.6 matthew 670: #
1.19 bisitz 671: $Str .= &Apache::loncommon::end_data_table_row();
672: $Str .= &Apache::loncommon::end_data_table();
1.1 matthew 673: #
1.18 bisitz 674: $Str .= '<p><span class="LC_nobreak">'
675: .&mt('Status: [_1]',
676: '<input type="text" name="stats_status"'
677: .' size="60" value="" readonly="readonly" />')
678: .'</span></p>';
679: $Str .= '</p>';
1.1 matthew 680: ##
681: return $Str;
682: }
683:
684: 1;
685:
686: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>