Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.55
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.55 ! matthew 3: # $Id: lonproblemanalysis.pm,v 1.54 2004/01/16 15:33:40 matthew Exp $
1.1 stredwic 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: #
1.11 minaeibi 27: package Apache::lonproblemanalysis;
1.1 stredwic 28:
29: use strict;
30: use Apache::lonnet();
1.25 matthew 31: use Apache::loncommon();
1.7 stredwic 32: use Apache::lonhtmlcommon();
1.23 matthew 33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
1.37 matthew 36: use HTML::Entities();
1.42 matthew 37: use Time::Local();
1.43 matthew 38: use Spreadsheet::WriteExcel();
1.2 stredwic 39:
1.40 matthew 40: my $plotcolors = ['#33ff00',
41: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
42: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
43: ];
1.39 matthew 44:
1.54 matthew 45: my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
46: text => 'Previous Problem' },
47: { name => 'ProblemAnalysis',
1.46 matthew 48: text => 'Analyze Problem Again' },
1.54 matthew 49: { name => 'NextProblemAnalysis',
50: text => 'Next Problem' },
51: { name => 'break'},
1.46 matthew 52: { name => 'ClearCache',
53: text => 'Clear Caches' },
54: { name => 'updatecaches',
55: text => 'Update Student Data' },
56: { name => 'SelectAnother',
1.53 matthew 57: text => 'Choose a different Problem' },
1.46 matthew 58: { name => 'ExcelOutput',
59: text => 'Produce Excel Output' });
60:
61: sub render_resource {
62: my ($resource) = @_;
63: ##
64: ## Render the problem
65: my $base;
66: ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
67: $base = "http://".$ENV{'SERVER_NAME'}.$base;
68: my $rendered_problem =
69: &Apache::lonnet::ssi_body($resource->{'src'});
70: $rendered_problem =~ s/<\s*form\s*/<nop /g;
71: $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
72: return '<table bgcolor="ffffff"><tr><td>'.
73: '<base href="'.$base.'" />'.
74: $rendered_problem.
75: '</td></tr></table>';
76: }
77:
1.1 stredwic 78: sub BuildProblemAnalysisPage {
1.23 matthew 79: my ($r,$c)=@_;
1.49 matthew 80: #
81: my %Saveable_Parameters = ('Status' => 'scalar',
82: 'Section' => 'array',
83: 'NumPlots' => 'scalar',
84: 'AnalyzeAs' => 'scalar',
85: 'AnalyzeOver' => 'scalar',
86: );
87: &Apache::loncommon::store_course_settings('problem_analysis',
88: \%Saveable_Parameters);
89: &Apache::loncommon::restore_course_settings('problem_analysis',
90: \%Saveable_Parameters);
91: #
92: &Apache::lonstatistics::PrepareClasslist();
1.48 matthew 93: #
1.24 matthew 94: $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
1.25 matthew 95: $r->print(&CreateInterface());
1.28 matthew 96: #
97: my @Students = @Apache::lonstatistics::Students;
98: #
1.46 matthew 99: if (@Students < 1) {
100: $r->print('<h2>There are no students in the sections selected</h2>');
101: }
102: #
103: &Apache::loncoursedata::clear_internal_caches();
1.41 matthew 104: if (exists($ENV{'form.ClearCache'}) ||
105: exists($ENV{'form.updatecaches'}) ||
1.33 matthew 106: (exists($ENV{'form.firstanalysis'}) &&
107: $ENV{'form.firstanalysis'} ne 'no')) {
108: &Apache::lonstatistics::Gather_Full_Student_Data($r);
109: }
110: if (! exists($ENV{'form.firstanalysis'})) {
111: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
112: } else {
113: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
114: }
1.39 matthew 115: $r->rflush();
1.46 matthew 116: #
1.33 matthew 117: if (exists($ENV{'form.problemchoice'}) &&
118: ! exists($ENV{'form.SelectAnother'})) {
1.46 matthew 119: foreach my $button (@SubmitButtons) {
1.54 matthew 120: if ($button->{'name'} eq 'break') {
121: $r->print("<br />\n");
122: } else {
123: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
124: 'value="'.&mt($button->{'text'}).'" />');
125: $r->print(' 'x5);
126: }
1.46 matthew 127: }
1.31 matthew 128: #
1.25 matthew 129: $r->print('<hr />');
1.54 matthew 130: $r->rflush();
131: #
132: # Determine which problem we are to analyze
133: my $current_problem = &get_target_from_id($ENV{'form.problemchoice'});
134: #
135: my ($prev,$curr,$next) = &get_prev_curr_next($current_problem);
136: if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
137: $current_problem = $prev;
138: } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
139: $current_problem = $next;
140: } else {
141: $current_problem = $curr;
142: }
1.23 matthew 143: #
1.54 matthew 144: # Store the current problem choice and send it out in the form
145: $ENV{'form.problemchoice'} = &make_target_id($current_problem);
146: $r->print('<input type="hidden" name="problemchoice" value="'.
147: $ENV{'form.problemchoice'}.'" />');
1.28 matthew 148: #
1.54 matthew 149: if (! defined($current_problem->{'resource'})) {
1.46 matthew 150: $r->print('resource is undefined');
151: } else {
1.54 matthew 152: my $resource = $current_problem->{'resource'};
1.44 matthew 153: $r->print('<h1>'.$resource->{'title'}.'</h1>');
1.41 matthew 154: $r->print('<h3>'.$resource->{'src'}.'</h3>');
1.47 matthew 155: $r->print(&render_resource($resource));
1.44 matthew 156: $r->rflush();
1.48 matthew 157: my %Data = &get_problem_data($resource->{'src'});
1.54 matthew 158: my $ProblemData = $Data{$current_problem->{'part'}.
159: '.'.
160: $current_problem->{'respid'}};
161: if ($current_problem->{'resptype'} eq 'option') {
162: &OptionResponseAnalysis($r,$resource,
163: $current_problem->{'respid'},
164: $ProblemData,
1.47 matthew 165: \@Students);
1.54 matthew 166: } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
167: &RadioResponseAnalysis($r,$resource,
168: $current_problem->{'part'},
169: $current_problem->{'respid'},
170: $ProblemData,
1.47 matthew 171: \@Students);
172: } else {
173: $r->print('<h2>This analysis is not supported</h2>');
174: }
1.7 stredwic 175: }
1.23 matthew 176: $r->print('<hr />');
1.25 matthew 177: } else {
1.31 matthew 178: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
179: &mt('Analyze Problem').'" />');
180: $r->print(' 'x5);
1.27 matthew 181: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.46 matthew 182: $r->print(&ProblemSelector());
1.1 stredwic 183: }
184: }
185:
1.48 matthew 186: =pod
187:
188: Removed code:
1.47 matthew 189:
190: #########################################################
191: #########################################################
192: ##
193: ## Radio Response Routines
194: ##
195: #########################################################
196: #########################################################
197: sub RadioResponseAnalysis {
1.48 matthew 198: my ($r,$resource,$part,$respid,$ProblemData,$Students) = @_;
199: my $analysis_html;
1.47 matthew 200: my $PerformanceData =
201: &Apache::loncoursedata::get_response_data
1.48 matthew 202: ($Students,$resource->{'symb'},$respid);
203: if (! defined($PerformanceData) ||
204: ref($PerformanceData) ne 'ARRAY' ) {
205: $analysis_html = '<h2>'.
206: &mt('There is no submission data for this resource').
207: '</h2>';
208: $r->print($analysis_html);
1.47 matthew 209: return;
210: }
1.48 matthew 211: if (exists($ENV{'form.ExcelOutput'})) {
212: $analysis_html .= &RR_Excel_output($r,$resource,$PerformanceData,
213: $ProblemData);
214: } elsif ($ENV{'form.AnalyzeOver'} eq 'Tries') {
215: $analysis_html .= &RR_Tries_Analysis($r,$resource,$PerformanceData,
216: $ProblemData);
217: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
218: $analysis_html .= &RR_Time_Analysis($r,$resource,$PerformanceData,
219: $ProblemData);
220: } else {
221: $analysis_html .= '<h2>'.
222: &mt('The analysis you have selected is not supported at this time').
223: '</h2>';
224: }
225: $r->print($analysis_html);
226: }
227:
228:
229: sub RR_Excel_output {
230: my ($r,$PerformanceData,$ProblemData) = @_;
231: return '<h1>No!</h1>';
232: }
233:
234: sub RR_Tries_Analysis {
235: my ($r,$resource,$PerformanceData,$ProblemData) = @_;
236: my $analysis_html;
237: my $mintries = 1;
238: my $maxtries = $ENV{'form.NumPlots'};
239: my ($table,$Foils,$Concepts) = &build_foil_index($ProblemData);
240: if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
241: $table = '<h3>'.
242: &mt('Not enough data for concept analysis. '.
243: 'Performing Foil Analysis').
244: '</h3>'.$table;
245: $ENV{'form.AnalyzeAs'} = 'Foils';
246: }
247: $analysis_html .= $table;
248: my @TryData = &RR_tries_data_analysis($r,$PerformanceData);
249: if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
250: $analysis_html = &RR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,
251: \@TryData,$ProblemData);
252: } else {
253: $analysis_html = &RR_Tries_Concept_Analysis($mintries,$maxtries,
254: $Concepts,
255: \@TryData,
256: $ProblemData);
257: }
258: return $analysis_html;
259: }
260:
261: sub RR_tries_data_analysis {
262: my ($r,$Attempt_data) = @_;
263: my @TryData;
264: foreach my $attempt (@$Attempt_data) {
265: my %Attempt = &hashify_attempt($attempt);
266: my ($answer,undef) = split('=',$Attempt{'submission'});
267: $TryData[$Attempt{'tries'}]->{$answer}++;
268: }
269: return @TryData;
270: }
271:
272: sub RR_Time_Analysis {
273: my ($r,$PerformanceData,$ProblemData) = @_;
274: my $html;
275: return $html;
276: }
277:
278: sub RR_Tries_Foil_Analysis {
279: my ($min,$max,$Foils,$TryData,$ProblemData) = @_;
280: my $html;
281: #
282: # Compute the data neccessary to make the plots
283: for (my $try=$min;$try<=$max;$try++) {
284: my @PlotData_Correct;
285: my @PlotData_Incorrect;
286: next if ($try > scalar(@{$TryData}));
287: next if (! defined($TryData->[$try-1]));
288: my %DataSet = %{$TryData->[$try-1]};
289: my $total = 0;
290: foreach my $foilid (@$Foils) {
291: $total += $DataSet{$foilid};
292: }
293: foreach my $foilid (@$Foils) {
294: if ($total == 0) {
295: push (@PlotData_Correct,0);
296: push (@PlotData_Incorrect,0);
297: } else {
298: if ($ProblemData->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
299: push (@PlotData_Correct,
300: int(100*$DataSet{$foilid}/$total));
301: push (@PlotData_Incorrect,0);
302: } else {
303: push (@PlotData_Correct,0);
304: push (@PlotData_Incorrect,
305: int(100*$DataSet{$foilid}/$total));
306: }
307: }
308: }
309: my $title='Attempt '.$try;
310: my $xlabel = $total.' Submissions';
311: $html.= &Apache::loncommon::DrawBarGraph($title,
312: $xlabel,
313: 'Percent Choosing',
314: 100,
315: ['#33ff00','#ff3300'],
316: \@PlotData_Correct,
317: \@PlotData_Incorrect);
318: }
319: &Apache::lonnet::logthis('plot = '.$html);
320: return $html;
321: }
322:
323: sub RR_Tries_Concept_Analysis {
324: my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
325: my $html;
326: return $html;
327: }
328:
329: sub RR_Time_Foil_Analysis {
330: my ($min,$max,$Foils,$ResponseData,$ProblemData) = @_;
331: my $html;
332: return $html;
333: }
334:
335: sub RR_Time_Concept_Analysis {
336: my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
337: my $html;
338: return $html;
339: }
340:
341:
342:
343: sub get_Radio_problem_data {
344: my ($url) = @_;
345: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
346: (my $garbage,$Answ)=split('_HASH_REF__',$Answ,2);
347: my %Answer = &Apache::lonnet::str2hash($Answ);
348: my %Partdata;
349: &Apache::lonnet::logthis('url = '.$url);
350: foreach my $part (@{$Answer{'parts'}}) {
351: while (my($key,$value) = each(%Answer)) {
352: # if (ref($value) eq 'ARRAY') {
353: # &Apache::lonnet::logthis('is ref part:'.$part.' '.$key.'='.join(',',@$value));
354: # } else {
355: # &Apache::lonnet::logthis('notref part:'.$part.' '.$key.'='.$value);
356: # }
357: next if ($key !~ /^$part/);
358: $key =~ s/^$part\.//;
359: if ($key eq 'foils') {
360: $Partdata{$part}->{'_Foils'}=$value;
361: } elsif ($key eq 'options') {
362: $Partdata{$part}->{'_Options'}=$value;
363: } elsif ($key eq 'shown') {
364: $Partdata{$part}->{'_Shown'}=$value;
365: } elsif ($key =~ /^foil.value.(.*)$/) {
366: $Partdata{$part}->{$1}->{'value'}=$value;
367: } elsif ($key =~ /^foil.text.(.*)$/) {
368: $Partdata{$part}->{$1}->{'text'}=$value;
369: }
370: }
371: }
372: return %Partdata;
1.47 matthew 373: }
1.48 matthew 374:
375: =cut
376:
377:
1.33 matthew 378: #########################################################
379: #########################################################
380: ##
1.46 matthew 381: ## Option Response Routines
1.33 matthew 382: ##
383: #########################################################
384: #########################################################
1.46 matthew 385: sub OptionResponseAnalysis {
1.54 matthew 386: my ($r,$resource,$respid,$ProblemData,$Students) = @_;
1.46 matthew 387: my $PerformanceData =
1.47 matthew 388: &Apache::loncoursedata::get_response_data
1.54 matthew 389: ($Students,$resource->{'symb'},$respid);
1.46 matthew 390: if (! defined($PerformanceData) ||
391: ref($PerformanceData) ne 'ARRAY' ) {
392: $r->print('<h2>'.
393: &mt('There is no student data for this problem.').
394: '</h2>');
395: } else {
396: $r->rflush();
397: if (exists($ENV{'form.ExcelOutput'})) {
398: my $result = &prepare_optionresponse_excel_sheet($r,$resource,
399: $PerformanceData,
400: $ProblemData);
401: $r->print($result);
402: $r->rflush();
1.39 matthew 403: } else {
1.46 matthew 404: if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
405: my $analysis_html = &tries_analysis($r,
406: $PerformanceData,
407: $ProblemData);
408: $r->print($analysis_html);
409: $r->rflush();
410: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
411: my $analysis_html = &time_analysis($PerformanceData,
412: $ProblemData);
413: $r->print($analysis_html);
414: $r->rflush();
1.39 matthew 415: } else {
1.46 matthew 416: $r->print('<h2>'.
417: &mt('The analysis you have selected is '.
418: 'not supported at this time').
419: '</h2>');
420: }
1.36 matthew 421: }
1.39 matthew 422: }
423: }
424:
1.33 matthew 425: #########################################################
1.46 matthew 426: #
427: # Option Response: Tries Analysis
428: #
1.33 matthew 429: #########################################################
430: sub tries_analysis {
1.43 matthew 431: my ($r,$PerformanceData,$ORdata) = @_;
1.33 matthew 432: my $mintries = 1;
433: my $maxtries = $ENV{'form.NumPlots'};
1.39 matthew 434: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
435: if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
436: $table = '<h3>'.
437: &mt('Not enough data for concept analysis. '.
438: 'Performing Foil Analysis').
439: '</h3>'.$table;
440: $ENV{'form.AnalyzeAs'} = 'Foils';
441: }
1.43 matthew 442: my %ResponseData = &analyze_option_data_by_tries($r,$PerformanceData,
1.36 matthew 443: $mintries,$maxtries);
1.42 matthew 444: my $analysis = '';
445: if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
446: $analysis = &Tries_Foil_Analysis($mintries,$maxtries,$Foils,
447: \%ResponseData,$ORdata);
448: } else {
449: $analysis = &Tries_Concept_Analysis($mintries,$maxtries,
450: $Concepts,\%ResponseData,$ORdata);
451: }
452: $table .= $analysis;
453: return $table;
454: }
455:
456: sub Tries_Foil_Analysis {
457: my ($mintries,$maxtries,$Foils,$respdat,$ORdata) = @_;
458: my %ResponseData = %$respdat;
1.31 matthew 459: #
460: # Compute the data neccessary to make the plots
1.42 matthew 461: my @PlotData;
462: foreach my $foilid (@$Foils) {
463: for (my $i=$mintries;$i<=$maxtries;$i++) {
464: if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {
465: push(@{$PlotData[$i]->{'_correct'}},0);
466: } else {
467: push(@{$PlotData[$i]->{'_correct'}},
468: 100*$ResponseData{$foilid}->[$i]->{'_correct'}/
469: $ResponseData{$foilid}->[$i]->{'_total'});
470: }
1.48 matthew 471: foreach my $option (@{$ORdata->{'_Options'}}) {
1.42 matthew 472: push(@{$PlotData[$i]->{'_total'}},
473: $ResponseData{$foilid}->[$i]->{'_total'});
474: if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {
475: push (@{$PlotData[$i]->{$option}},0);
476: } else {
477: if ($ResponseData{$foilid}->[$i]->{'_total'} ==
478: $ResponseData{$foilid}->[$i]->{'_correct'}) {
479: push(@{$PlotData[$i]->{$option}},0);
1.39 matthew 480: } else {
481: push (@{$PlotData[$i]->{$option}},
482: 100 * $ResponseData{$foilid}->[$i]->{$option} /
1.42 matthew 483: ($ResponseData{$foilid}->[$i]->{'_total'} -
484: $ResponseData{$foilid}->[$i]->{'_correct'}));
1.39 matthew 485: }
1.36 matthew 486: }
487: }
488: }
1.42 matthew 489: }
490: #
491: # Build a table for the plots
492: my $analysis_html = "<table>\n";
493: my $foilkey = &build_option_index($ORdata);
494: for (my $i=$mintries;$i<=$maxtries;$i++) {
495: my $count = $ResponseData{'_total'}->[$i];
496: if ($count == 0) {
497: $count = 'no submissions';
498: } elsif ($count == 1) {
499: $count = '1 submission';
500: } else {
501: $count = $count.' submissions';
502: }
503: my $title = 'Attempt '.$i.', '.$count;
504: my @Datasets;
1.48 matthew 505: foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
1.42 matthew 506: next if (! exists($PlotData[$i]->{$option}));
507: push(@Datasets,$PlotData[$i]->{$option});
508: }
1.46 matthew 509: my $correctgraph = &Apache::loncommon::DrawBarGraph
1.42 matthew 510: ($title,'Foil Number','Percent Correct',
511: 100,$plotcolors,$Datasets[0]);
512: $analysis_html.= '<tr><td>'.$correctgraph.'</td>';
513: ##
514: ##
515: for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
516: $Datasets[0]->[$i]=0;
517: }
518: $count = $ResponseData{'_total'}->[$i]-$ResponseData{'_correct'}->[$i];
519: if ($count == 0) {
520: $count = 'no submissions';
521: } elsif ($count == 1) {
522: $count = '1 submission';
523: } else {
524: $count = $count.' submissions';
525: }
526: $title = 'Attempt '.$i.', '.$count;
1.46 matthew 527: my $incorrectgraph = &Apache::loncommon::DrawBarGraph
1.42 matthew 528: ($title,'Foil Number','% Option Chosen Incorrectly',
529: 100,$plotcolors,@Datasets);
530: $analysis_html.= '<td>'.$incorrectgraph.'</td>';
531: $analysis_html.= '<td>'.$foilkey."<td></tr>\n";
532: }
533: $analysis_html .= "</table>\n";
534: return $analysis_html;
535: }
536:
537: sub Tries_Concept_Analysis {
538: my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
539: my %ResponseData = %$respdat;
540: my $analysis_html = "<table>\n";
541: #
542: # Compute the data neccessary to make the plots
543: my @PlotData;
544: # Concept analysis
545: #
546: # Note: we do not bother with characterizing the students incorrect
547: # answers at the concept level because an incorrect answer for one foil
548: # may be a correct answer for another foil.
549: my %ConceptData;
550: foreach my $concept (@{$Concepts}) {
551: for (my $i=$mintries;$i<=$maxtries;$i++) {
552: #
553: # Gather the per-attempt data
554: my $cdata = $ConceptData{$concept}->[$i];
555: foreach my $foilid (@{$concept->{'foils'}}) {
556: $cdata->{'_correct'} +=
557: $ResponseData{$foilid}->[$i]->{'_correct'};
558: $cdata->{'_total'} +=
559: $ResponseData{$foilid}->[$i]->{'_total'};
560: }
561: push (@{$PlotData[$i]->{'_total'}},$cdata->{'_total'});
562: if ($cdata->{'_total'} == 0) {
563: push (@{$PlotData[$i]->{'_correct'}},0);
564: } else {
565: push (@{$PlotData[$i]->{'_correct'}},
566: 100*$cdata->{'_correct'}/$cdata->{'_total'});
1.36 matthew 567: }
1.25 matthew 568: }
1.42 matthew 569: }
1.31 matthew 570: # Build a table for the plots
1.25 matthew 571: for (my $i=$mintries;$i<=$maxtries;$i++) {
1.39 matthew 572: my $minstu = $PlotData[$i]->{'_total'}->[0];
573: my $maxstu = $PlotData[$i]->{'_total'}->[0];
574: foreach my $count (@{$PlotData[$i]->{'_total'}}) {
1.36 matthew 575: if ($minstu > $count) {
576: $minstu = $count;
1.27 matthew 577: }
1.36 matthew 578: if ($maxstu < $count) {
579: $maxstu = $count;
1.27 matthew 580: }
581: }
1.39 matthew 582: $maxstu = 0 if (! defined($maxstu));
583: $minstu = 0 if (! defined($minstu));
1.35 matthew 584: my $title;
1.42 matthew 585: my $count = $ResponseData{'_total'}->[$i];
586: if ($count == 0) {
587: $count = 'no submissions';
588: } elsif ($count == 1) {
589: $count = '1 submission';
1.27 matthew 590: } else {
1.42 matthew 591: $count = $count.' submissions';
1.39 matthew 592: }
1.42 matthew 593: $title = 'Attempt '.$i.', '.$count;
1.46 matthew 594: my $graphlink = &Apache::loncommon::DrawBarGraph
1.42 matthew 595: ($title,'Concept Number','Percent Correct',
596: 100,$plotcolors,$PlotData[$i]->{'_correct'});
597: $analysis_html.= '<tr><td>'.$graphlink."</td></tr>\n";
1.25 matthew 598: }
1.42 matthew 599: $analysis_html .= "</table>\n";
600: return $analysis_html;
1.25 matthew 601: }
602:
603: sub analyze_option_data_by_tries {
1.43 matthew 604: my ($r,$PerformanceData,$mintries,$maxtries) = @_;
1.25 matthew 605: my %Trydata;
606: $mintries = 1 if (! defined($mintries) || $mintries < 1);
607: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26 matthew 608: foreach my $row (@$PerformanceData) {
609: next if (! defined($row));
1.47 matthew 610: my $tries = &get_tries_from_row($row);
1.46 matthew 611: my %Row = &Process_OR_Row($row);
1.43 matthew 612: next if (! %Row);
1.42 matthew 613: while (my ($foilid,$href) = each(%Row)) {
614: if (! ref($href)) {
615: $Trydata{$foilid}->[$tries] += $href;
616: next;
617: }
618: while (my ($option,$value) = each(%$href)) {
619: $Trydata{$foilid}->[$tries]->{$option}+=$value;
1.25 matthew 620: }
621: }
622: }
623: return %Trydata;
624: }
625:
1.33 matthew 626: #########################################################
1.46 matthew 627: #
628: # Option Response: Time Analysis
629: #
1.33 matthew 630: #########################################################
631: sub time_analysis {
632: my ($PerformanceData,$ORdata) = @_;
1.42 matthew 633: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
634: if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
635: $table = '<h3>'.
636: &mt('Not enough data for concept analysis. '.
637: 'Performing Foil Analysis').
638: '</h3>'.$table;
639: $ENV{'form.AnalyzeAs'} = 'Foils';
640: }
1.33 matthew 641: my $num_plots = $ENV{'form.NumPlots'};
642: my $num_data = scalar(@$PerformanceData)-1;
643: my $percent = sprintf('%2f',100/$num_plots);
1.42 matthew 644: #
1.37 matthew 645: $table .= "<table>\n";
1.33 matthew 646: for (my $i=0;$i<$num_plots;$i++) {
1.42 matthew 647: ##
1.34 matthew 648: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
649: ('startdate_'.$i);
650: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
651: ('enddate_'.$i);
652: if (! defined($starttime) || ! defined($endtime)) {
1.42 matthew 653: my $sec_in_day = 86400;
1.47 matthew 654: my $last_sub_time = &get_time_from_row($PerformanceData->[-1]);
1.42 matthew 655: my ($sday,$smon,$syear);
656: (undef,undef,undef,$sday,$smon,$syear) =
657: localtime($last_sub_time - $sec_in_day*$i);
658: $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
659: $endtime = $starttime + $sec_in_day;
660: if ($i == ($num_plots -1 )) {
1.47 matthew 661: $starttime = &get_time_from_row($PerformanceData->[0]);
1.42 matthew 662: }
663: }
1.34 matthew 664: my $startdateform = &Apache::lonhtmlcommon::date_setter
665: ('Statistics','startdate_'.$i,$starttime);
666: my $enddateform = &Apache::lonhtmlcommon::date_setter
667: ('Statistics','enddate_'.$i,$endtime);
1.42 matthew 668: #
669: my $begin_index;
670: my $end_index;
671: my $j;
672: while (++$j < scalar(@$PerformanceData)) {
1.47 matthew 673: last if (&get_time_from_row($PerformanceData->[$j])
1.46 matthew 674: > $starttime);
1.42 matthew 675: }
676: $begin_index = $j;
677: while (++$j < scalar(@$PerformanceData)) {
1.47 matthew 678: last if (&get_time_from_row($PerformanceData->[$j]) > $endtime);
1.42 matthew 679: }
680: $end_index = $j;
681: ##
682: my $interval = {
683: begin_index => $begin_index,
684: end_index => $end_index,
685: startdateform => $startdateform,
686: enddateform => $enddateform,
687: };
688: if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
689: $table .= &Foil_Time_Analysis($PerformanceData,$ORdata,$Foils,
690: $interval);
691: } else {
692: $table .= &Concept_Time_Analysis($PerformanceData,$ORdata,
693: $Concepts,$interval);
694: }
1.33 matthew 695: }
1.42 matthew 696: #
1.33 matthew 697: return $table;
698: }
699:
1.42 matthew 700: sub Foil_Time_Analysis {
701: my ($PerformanceData,$ORdata,$Foils,$interval) = @_;
702: my $analysis_html;
703: my $foilkey = &build_option_index($ORdata);
704: my ($begin_index,$end_index) = ($interval->{'begin_index'},
705: $interval->{'end_index'});
1.33 matthew 706: my %TimeData;
707: #
708: # Compute the number getting the foils correct or incorrects
1.42 matthew 709: for (my $j=$begin_index;$j<=$end_index;$j++) {
710: my $row = $PerformanceData->[$j];
1.33 matthew 711: next if (! defined($row));
1.46 matthew 712: my %Row = &Process_OR_Row($row);
1.42 matthew 713: while (my ($foilid,$href) = each(%Row)) {
714: if (! ref($href)) {
715: $TimeData{$foilid} += $href;
716: next;
717: }
718: while (my ($option,$value) = each(%$href)) {
719: $TimeData{$foilid}->{$option}+=$value;
1.33 matthew 720: }
721: }
722: }
1.39 matthew 723: my @Plotdata;
1.42 matthew 724: foreach my $foil (@$Foils) {
725: my $total = $TimeData{$foil}->{'_total'};
726: if ($total == 0) {
727: push(@{$Plotdata[0]},0);
728: } else {
729: push(@{$Plotdata[0]},
730: 100 * $TimeData{$foil}->{'_correct'} / $total);
731: }
732: my $total_incorrect = $total - $TimeData{$foil}->{'_correct'};
733: my $optionidx = 1;
1.48 matthew 734: foreach my $option (@{$ORdata->{'_Options'}}) {
1.42 matthew 735: if ($total_incorrect == 0) {
736: push(@{$Plotdata[$optionidx]},0);
737: } else {
738: push(@{$Plotdata[$optionidx]},
739: 100 * $TimeData{$foil}->{$option} / $total_incorrect);
1.37 matthew 740: }
1.42 matthew 741: } continue {
742: $optionidx++;
1.39 matthew 743: }
1.42 matthew 744: }
745: #
746: # Create the plot
747: my $count = $end_index-$begin_index;
748: my $title;
749: if ($count == 0) {
750: $title = 'no submissions';
751: } elsif ($count == 1) {
752: $title = 'one submission';
1.39 matthew 753: } else {
1.42 matthew 754: $title = $count.' submissions';
755: }
1.46 matthew 756: my $correctplot = &Apache::loncommon::DrawBarGraph($title,
757: 'Foil Number',
758: 'Percent Correct',
759: 100,
760: $plotcolors,
761: $Plotdata[0]);
1.42 matthew 762: for (my $j=0; $j< scalar(@{$Plotdata[0]});$j++) {
763: $Plotdata[0]->[$j]=0;
764: }
765: $count = $end_index-$begin_index-$TimeData{'_correct'};
766: if ($count == 0) {
767: $title = 'no submissions';
768: } elsif ($count == 1) {
769: $title = 'one submission';
770: } else {
771: $title = $count.' submissions';
772: }
1.46 matthew 773: my $incorrectplot = &Apache::loncommon::DrawBarGraph($title,
1.42 matthew 774: 'Foil Number',
775: 'Incorrect Option Choice',
776: 100,
777: $plotcolors,
778: @Plotdata);
779: $analysis_html.='<tr>'.
780: '<td>'.$correctplot.'</td>'.
781: '<td>'.$incorrectplot.'</td>'.
782: '<td align="left" valign="top">'.$foilkey.'</td>'."</tr>\n";
783: $analysis_html.= '<tr>'.'<td colspan="3">'.
784: '<b>Start Time</b>:'.
785: ' '.$interval->{'startdateform'}.'<br />'.
786: '<b>End Time</b> : '.
787: ' '.$interval->{'enddateform'}.'<br />'.
788: # '<b>Plot Title</b> :'.
789: # (" "x3).$interval->{'titleform'}.
790: '</td>'.
791: "</tr>\n";
792: return $analysis_html;
793: }
794:
795: sub Concept_Time_Analysis {
796: my ($PerformanceData,$ORdata,$Concepts,$interval) = @_;
797: my $analysis_html;
798: ##
799: ## Determine starttime, endtime, startindex, endindex
800: my ($begin_index,$end_index) = ($interval->{'begin_index'},
801: $interval->{'end_index'});
802: my %TimeData;
803: #
804: # Compute the number getting the foils correct or incorrects
805: for (my $j=$begin_index;$j<=$end_index;$j++) {
806: my $row = $PerformanceData->[$j];
807: next if (! defined($row));
1.46 matthew 808: my %Row = &Process_OR_Row($row);
1.42 matthew 809: while (my ($foilid,$href) = each(%Row)) {
810: if (! ref($href)) {
811: $TimeData{$foilid} += $href;
812: next;
1.37 matthew 813: }
1.42 matthew 814: while (my ($option,$value) = each(%$href)) {
815: $TimeData{$foilid}->{$option}+=$value;
1.37 matthew 816: }
1.33 matthew 817: }
818: }
819: #
1.42 matthew 820: # Put the data in plottable form
821: my @Plotdata;
822: foreach my $concept (@$Concepts) {
823: my ($total,$correct);
824: foreach my $foil (@{$concept->{'foils'}}) {
825: $total += $TimeData{$foil}->{'_total'};
826: $correct += $TimeData{$foil}->{'_correct'};
827: }
828: if ($total == 0) {
829: push(@Plotdata,0);
830: } else {
831: push(@Plotdata,100 * $correct / $total);
832: }
833: }
834: #
1.33 matthew 835: # Create the plot
1.42 matthew 836: my $title = ($end_index - $begin_index).' submissions';
1.46 matthew 837: my $correctplot = &Apache::loncommon::DrawBarGraph($title,
1.42 matthew 838: 'Concept Number',
839: 'Percent Correct',
840: 100,
841: $plotcolors,
842: \@Plotdata);
843: $analysis_html.='<tr>'.
844: '<td>'.$correctplot.'</td>'.
845: '<td align="left" valign="top">'.
846: '<b>Start Time</b>: '.$interval->{'startdateform'}.'<br />'.
847: '<b>End Time</b> : '.
848: ' '.$interval->{'enddateform'}.'<br />'.
849: # '<b>Plot Title</b> :'.(" "x3).
850: # $interval->{'titleform'}.
851: '</td>'.
852: "</tr>\n";
853: return $analysis_html;
854: }
855:
856: #########################################################
857: #########################################################
858: ##
859: ## Excel output
860: ##
861: #########################################################
862: #########################################################
1.46 matthew 863: sub prepare_optionresponse_excel_sheet {
1.43 matthew 864: my ($r,$resource,$PerformanceData,$ORdata) = @_;
1.44 matthew 865: my $response = '';
1.42 matthew 866: my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
1.43 matthew 867: #
868: # Create excel worksheet
869: my $filename = '/prtspool/'.
870: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
871: time.'_'.rand(1000000000).'.xls';
872: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
873: if (! defined($workbook)) {
874: $r->log_error("Error creating excel spreadsheet $filename: $!");
875: $r->print('<p>'.&mt("Unable to create new Excel file. ".
876: "This error has been logged. ".
877: "Please alert your LON-CAPA administrator").
878: '</p>');
879: return undef;
880: }
881: #
882: $workbook->set_tempdir('/home/httpd/perl/tmp');
883: #
884: # Define some potentially useful formats
885: my $format;
886: $format->{'header'} = $workbook->add_format(bold => 1,
887: bottom => 1,
888: align => 'center');
889: $format->{'bold'} = $workbook->add_format(bold=>1);
890: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
891: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
892: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
893: $format->{'date'} = $workbook->add_format(num_format=>
894: 'mmm d yyyy hh:mm AM/PM');
895: #
896: # Create and populate main worksheets
897: my $problem_data_sheet = $workbook->addworksheet('Problem Data');
898: my $student_data_sheet = $workbook->addworksheet('Student Data');
899: my $response_data_sheet = $workbook->addworksheet('Response Data');
900: foreach my $sheet ($problem_data_sheet,$student_data_sheet,
901: $response_data_sheet) {
902: $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
903: $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
904: }
905: #
906: my $result;
907: $result = &build_problem_data_worksheet($problem_data_sheet,$format,
908: $Concepts,$ORdata);
909: if ($result ne 'okay') {
910: # Do something useful
911: }
912: $result = &build_student_data_worksheet($student_data_sheet,$format);
913: if ($result ne 'okay') {
914: # Do something useful
915: }
916: $result = &build_response_data_worksheet($response_data_sheet,$format,
917: $PerformanceData,$Foils,
918: $ORdata);
919: if ($result ne 'okay') {
920: # Do something useful
921: }
1.44 matthew 922: $response_data_sheet->activate();
1.43 matthew 923: #
924: # Close the excel file
925: $workbook->close();
926: #
927: # Write a link to allow them to download it
1.44 matthew 928: $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
929: '<p><a href="'.$filename.'">'.
930: &mt('Your Excel spreadsheet.').
931: '</a></p>'."\n";
1.43 matthew 932: return $result;
933: }
934:
935: sub build_problem_data_worksheet {
936: my ($worksheet,$format,$Concepts,$ORdata) = @_;
937: my $rows_output = 3;
938: my $cols_output = 0;
939: $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
940: ##
941: ##
942: my @Headers;
943: if (@$Concepts > 1) {
944: @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
945: 'Foil Name','Foil Text','Correct value');
946: } else {
947: @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
948: }
949: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1.48 matthew 950: my %Foildata = %{$ORdata->{'_Foils'}};
1.43 matthew 951: my $conceptindex = 1;
952: my $foilindex = 1;
953: foreach my $concept (@$Concepts) {
954: my @FoilsInConcept = @{$concept->{'foils'}};
955: my $firstfoil = shift(@FoilsInConcept);
956: if (@$Concepts > 1) {
957: $worksheet->write_row($rows_output++,0,
958: [$conceptindex,
959: $concept->{'name'},
960: $foilindex++,
961: $Foildata{$firstfoil}->{'name'},
962: $Foildata{$firstfoil}->{'text'},
963: $Foildata{$firstfoil}->{'value'},]);
964: } else {
965: $worksheet->write_row($rows_output++,0,
966: [ $foilindex++,
967: $Foildata{$firstfoil}->{'name'},
968: $Foildata{$firstfoil}->{'text'},
969: $Foildata{$firstfoil}->{'value'},]);
970: }
971: foreach my $foilid (@FoilsInConcept) {
972: if (@$Concepts > 1) {
973: $worksheet->write_row($rows_output++,0,
974: ['',
975: '',
976: $foilindex,
977: $Foildata{$foilid}->{'name'},
978: $Foildata{$foilid}->{'text'},
979: $Foildata{$foilid}->{'value'},]);
980: } else {
981: $worksheet->write_row($rows_output++,0,
982: [$foilindex,
983: $Foildata{$foilid}->{'name'},
984: $Foildata{$foilid}->{'text'},
985: $Foildata{$foilid}->{'value'},]);
986: }
987: } continue {
988: $foilindex++;
989: }
990: } continue {
991: $conceptindex++;
992: }
993: $rows_output++;
994: $rows_output++;
995: ##
996: ## Option data output
997: $worksheet->write($rows_output++,0,'Options',$format->{'header'});
1.48 matthew 998: foreach my $string (@{$ORdata->{'_Options'}}) {
1.43 matthew 999: $worksheet->write($rows_output++,0,$string);
1000: }
1001: return 'okay';
1002: }
1003:
1004: sub build_student_data_worksheet {
1005: my ($worksheet,$format) = @_;
1006: my $rows_output = 3;
1007: my $cols_output = 0;
1008: $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
1009: my @Headers = ('full name','username','domain','section',
1010: "student\nnumber",'identifier');
1011: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1012: my @Students = @Apache::lonstatistics::Students;
1013: my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
1014: my %ids;
1015: foreach my $row (@$studentrows) {
1016: my ($mysqlid,$student) = @$row;
1017: $ids{$student}=$mysqlid;
1018: }
1019: foreach my $student (@Students) {
1020: my $name_domain = $student->{'username'}.':'.$student->{'domain'};
1021: $worksheet->write_row($rows_output++,0,
1022: [$student->{'fullname'},
1023: $student->{'username'},$student->{'domain'},
1024: $student->{'section'},$student->{'id'},
1025: $ids{$name_domain}]);
1026: }
1027: return;
1028: }
1029:
1030: sub build_response_data_worksheet {
1031: my ($worksheet,$format,$PerformanceData,$Foils,$ORdata)=@_;
1032: my $rows_output = 3;
1033: my $cols_output = 0;
1034: $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
1035: $worksheet->set_column(1,1,20);
1036: $worksheet->set_column(2,2,13);
1037: my @Headers = ('identifier','time','award detail','attempt');
1038: foreach my $foil (@$Foils) {
1039: push (@Headers,$foil.' submission');
1040: push (@Headers,$foil.' grading');
1041: }
1042: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1043: #
1044: foreach my $row (@$PerformanceData) {
1045: next if (! defined($row));
1046: my ($student,$award,$grading,$submission,$time,$tries) = @$row;
1047: my @Foilgrades = split('&',$grading);
1048: my @Foilsubs = split('&',$submission);
1049: my %ResponseData;
1050: for (my $j=0;$j<=$#Foilgrades;$j++) {
1051: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1052: my (undef,$submission) = split('=',$Foilsubs[$j]);
1053: $submission = &Apache::lonnet::unescape($submission);
1054: $ResponseData{$foilid.' submission'}=$submission;
1055: $ResponseData{$foilid.' award'}=$correct;
1056: }
1057: $worksheet->write($rows_output,$cols_output++,$student);
1058: $worksheet->write($rows_output,$cols_output++,
1059: &calc_serial($time),$format->{'date'});
1060: $worksheet->write($rows_output,$cols_output++,$award);
1061: $worksheet->write($rows_output,$cols_output++,$tries);
1062: foreach my $foilid (@$Foils) {
1063: $worksheet->write($rows_output,$cols_output++,
1064: $ResponseData{$foilid.' submission'});
1065: $worksheet->write($rows_output,$cols_output++,
1066: $ResponseData{$foilid.' award'});
1067: }
1068: $rows_output++;
1069: $cols_output = 0;
1070: }
1071: return;
1.42 matthew 1072: }
1073:
1.43 matthew 1074:
1075: ##
1076: ## The following is copied from datecalc1.pl, part of the
1077: ## Spreadsheet::WriteExcel CPAN module.
1078: ##
1079: ##
1080: ######################################################################
1081: #
1082: # Demonstration of writing date/time cells to Excel spreadsheets,
1083: # using UNIX/Perl time as source of date/time.
1084: #
1085: # Copyright 2000, Andrew Benham, adsb@bigfoot.com
1086: #
1087: ######################################################################
1088: #
1089: # UNIX/Perl time is the time since the Epoch (00:00:00 GMT, 1 Jan 1970)
1090: # measured in seconds.
1091: #
1092: # An Excel file can use exactly one of two different date/time systems.
1093: # In these systems, a floating point number represents the number of days
1094: # (and fractional parts of the day) since a start point. The floating point
1095: # number is referred to as a 'serial'.
1096: # The two systems ('1900' and '1904') use different starting points:
1097: # '1900'; '1.00' is 1 Jan 1900 BUT 1900 is erroneously regarded as
1098: # a leap year - see:
1099: # http://support.microsoft.com/support/kb/articles/Q181/3/70.asp
1100: # for the excuse^H^H^H^H^H^Hreason.
1101: # '1904'; '1.00' is 2 Jan 1904.
1102: #
1103: # The '1904' system is the default for Apple Macs. Windows versions of
1104: # Excel have the option to use the '1904' system.
1105: #
1106: # Note that Visual Basic's "DateSerial" function does NOT erroneously
1107: # regard 1900 as a leap year, and thus its serials do not agree with
1108: # the 1900 serials of Excel for dates before 1 Mar 1900.
1109: #
1110: # Note that StarOffice (at least at version 5.2) does NOT erroneously
1111: # regard 1900 as a leap year, and thus its serials do not agree with
1112: # the 1900 serials of Excel for dates before 1 Mar 1900.
1113: #
1114: ######################################################################
1115: #
1116: # Calculation description
1117: # =======================
1118: #
1119: # 1900 system
1120: # -----------
1121: # Unix time is '0' at 00:00:00 GMT 1 Jan 1970, i.e. 70 years after 1 Jan 1900.
1122: # Of those 70 years, 17 (1904,08,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68)
1123: # were leap years with an extra day.
1124: # Thus there were 17 + 70*365 days = 25567 days between 1 Jan 1900 and
1125: # 1 Jan 1970.
1126: # In the 1900 system, '1' is 1 Jan 1900, but as 1900 was not a leap year
1127: # 1 Jan 1900 should really be '2', so 1 Jan 1970 is '25569'.
1128: #
1129: # 1904 system
1130: # -----------
1131: # Unix time is '0' at 00:00:00 GMT 1 Jan 1970, i.e. 66 years after 1 Jan 1904.
1132: # Of those 66 years, 17 (1904,08,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68)
1133: # were leap years with an extra day.
1134: # Thus there were 17 + 66*365 days = 24107 days between 1 Jan 1904 and
1135: # 1 Jan 1970.
1136: # In the 1904 system, 2 Jan 1904 being '1', 1 Jan 1970 is '24107'.
1137: #
1138: ######################################################################
1139: #
1140: # Copyright (c) 2000, Andrew Benham.
1141: # This program is free software. It may be used, redistributed and/or
1142: # modified under the same terms as Perl itself.
1143: #
1144: # Andrew Benham, adsb@bigfoot.com
1145: # London, United Kingdom
1146: # 11 Nov 2000
1147: #
1148: ######################################################################
1149:
1150: # Use 1900 date system on all platforms other than Apple Mac (for which
1151: # use 1904 date system).
1152: my $DATE_SYSTEM = ($^O eq 'MacOS') ? 1 : 0;
1153:
1154: #-----------------------------------------------------------
1155: # calc_serial()
1156: #
1157: # Called with (up to) 2 parameters.
1158: # 1. Unix timestamp. If omitted, uses current time.
1159: # 2. GMT flag. Set to '1' to return serial in GMT.
1160: # If omitted, returns serial in appropriate timezone.
1161: #
1162: # Returns date/time serial according to $DATE_SYSTEM selected
1163: #-----------------------------------------------------------
1164: sub calc_serial {
1165: my $time = (defined $_[0]) ? $_[0] : time();
1166: my $gmtflag = (defined $_[1]) ? $_[1] : 0;
1167:
1168: # Divide timestamp by number of seconds in a day.
1169: # This gives a date serial with '0' on 1 Jan 1970.
1170: my $serial = $time / 86400;
1171:
1172: # Adjust the date serial by the offset appropriate to the
1173: # currently selected system (1900/1904).
1174: if ($DATE_SYSTEM == 0) { # use 1900 system
1175: $serial += 25569;
1176: } else { # use 1904 system
1177: $serial += 24107;
1178: }
1179:
1180: unless ($gmtflag) {
1181: # Now have a 'raw' serial with the right offset. But this
1182: # gives a serial in GMT, which is false unless the timezone
1183: # is GMT. We need to adjust the serial by the appropriate
1184: # timezone offset.
1185: # Calculate the appropriate timezone offset by seeing what
1186: # the differences between localtime and gmtime for the given
1187: # time are.
1188:
1189: my @gmtime = gmtime($time);
1190: my @ltime = localtime($time);
1191:
1192: # For the first 7 elements of the two arrays, adjust the
1193: # date serial where the elements differ.
1194: for (0 .. 6) {
1195: my $diff = $ltime[$_] - $gmtime[$_];
1196: if ($diff) {
1197: $serial += _adjustment($diff,$_);
1198: }
1199: }
1200: }
1201:
1202: # Perpetuate the error that 1900 was a leap year by decrementing
1203: # the serial if we're using the 1900 system and the date is prior to
1204: # 1 Mar 1900. This has the effect of making serial value '60'
1205: # 29 Feb 1900.
1206:
1207: # This fix only has any effect if UNIX/Perl time on the platform
1208: # can represent 1900. Many can't.
1209:
1210: unless ($DATE_SYSTEM) {
1211: $serial-- if ($serial < 61); # '61' is 1 Mar 1900
1212: }
1213: return $serial;
1214: }
1215:
1216: sub _adjustment {
1217: # Based on the difference in the localtime/gmtime array elements
1218: # number, return the adjustment required to the serial.
1219:
1220: # We only look at some elements of the localtime/gmtime arrays:
1221: # seconds unlikely to be different as all known timezones
1222: # have an offset of integral multiples of 15 minutes,
1223: # but it's easy to do.
1224: # minutes will be different for timezone offsets which are
1225: # not an exact number of hours.
1226: # hours very likely to be different.
1227: # weekday will differ when localtime/gmtime difference
1228: # straddles midnight.
1229: #
1230: # Assume that difference between localtime and gmtime is less than
1231: # 5 days, then don't have to do maths for day of month, month number,
1232: # year number, etc...
1233:
1234: my ($delta,$element) = @_;
1235: my $adjust = 0;
1236:
1237: if ($element == 0) { # Seconds
1238: $adjust = $delta/86400; # 60 * 60 * 24
1239: } elsif ($element == 1) { # Minutes
1240: $adjust = $delta/1440; # 60 * 24
1241: } elsif ($element == 2) { # Hours
1242: $adjust = $delta/24; # 24
1243: } elsif ($element == 6) { # Day of week number
1244: # Catch difference straddling Sat/Sun in either direction
1245: $delta += 7 if ($delta < -4);
1246: $delta -= 7 if ($delta > 4);
1247:
1248: $adjust = $delta;
1249: }
1250: return $adjust;
1.1 stredwic 1251: }
1252:
1.46 matthew 1253: sub build_foil_index {
1254: my ($ORdata) = @_;
1.48 matthew 1255: return if (! exists($ORdata->{'_Foils'}));
1256: my %Foildata = %{$ORdata->{'_Foils'}};
1.46 matthew 1257: my @Foils = sort(keys(%Foildata));
1258: my %Concepts;
1259: foreach my $foilid (@Foils) {
1.48 matthew 1260: push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1.46 matthew 1261: $foilid);
1262: }
1263: undef(@Foils);
1264: # Having gathered the concept information in a hash, we now translate it
1265: # into an array because we need to be consistent about order.
1266: # Also put the foils in order, too.
1267: my $sortfunction = sub {
1268: my %Numbers = (one => 1,
1269: two => 2,
1270: three => 3,
1271: four => 4,
1272: five => 5,
1273: six => 6,
1274: seven => 7,
1275: eight => 8,
1276: nine => 9,
1277: ten => 10,);
1278: my $a1 = lc($a);
1279: my $b1 = lc($b);
1280: if (exists($Numbers{$a})) {
1281: $a1 = $Numbers{$a};
1282: }
1283: if (exists($Numbers{$b})) {
1284: $b1 = $Numbers{$b};
1285: }
1286: $a1 cmp $b1;
1287: };
1288: my @Concepts;
1289: foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1290: push(@Concepts,{ name => $concept,
1291: foils => [@{$Concepts{$concept}}]});
1292: push(@Foils,(@{$Concepts{$concept}}));
1293: }
1294: #
1295: # Build up the table of row labels.
1296: my $table = '<table border="1" >'."\n";
1297: if (@Concepts > 1) {
1298: $table .= '<tr>'.
1299: '<th>'.&mt('Concept Number').'</th>'.
1300: '<th>'.&mt('Concept').'</th>'.
1301: '<th>'.&mt('Foil Number').'</th>'.
1302: '<th>'.&mt('Foil Name').'</th>'.
1303: '<th>'.&mt('Foil Text').'</th>'.
1304: '<th>'.&mt('Correct Value').'</th>'.
1305: "</tr>\n";
1306: } else {
1307: $table .= '<tr>'.
1308: '<th>'.&mt('Foil Number').'</th>'.
1309: '<th>'.&mt('Foil Name').'</th>'.
1310: '<th>'.&mt('Foil Text').'</th>'.
1311: '<th>'.&mt('Correct Value').'</th>'.
1312: "</tr>\n";
1313: }
1314: my $conceptindex = 1;
1315: my $foilindex = 1;
1316: foreach my $concept (@Concepts) {
1317: my @FoilsInConcept = @{$concept->{'foils'}};
1318: my $firstfoil = shift(@FoilsInConcept);
1319: if (@Concepts > 1) {
1320: $table .= '<tr>'.
1321: '<td>'.$conceptindex.'</td>'.
1322: '<td>'.$concept->{'name'}.'</td>'.
1323: '<td>'.$foilindex++.'</td>'.
1324: '<td>'.$Foildata{$firstfoil}->{'name'}.'</td>'.
1325: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1326: '<td>'.$Foildata{$firstfoil}->{'value'}.'</td>'.
1327: "</tr>\n";
1328: } else {
1329: $table .= '<tr>'.
1330: '<td>'.$foilindex++.'</td>'.
1331: '<td>'.$Foildata{$firstfoil}->{'name'}.'</td>'.
1332: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1333: '<td>'.$Foildata{$firstfoil}->{'value'}.'</td>'.
1334: "</tr>\n";
1335: }
1336: foreach my $foilid (@FoilsInConcept) {
1337: if (@Concepts > 1) {
1338: $table .= '<tr>'.
1339: '<td></td>'.
1340: '<td></td>'.
1341: '<td>'.$foilindex.'</td>'.
1342: '<td>'.$Foildata{$foilid}->{'name'}.'</td>'.
1343: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1344: '<td>'.$Foildata{$foilid}->{'value'}.'</td>'.
1345: "</tr>\n";
1346: } else {
1347: $table .= '<tr>'.
1348: '<td>'.$foilindex.'</td>'.
1349: '<td>'.$Foildata{$foilid}->{'name'}.'</td>'.
1350: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1351: '<td>'.$Foildata{$foilid}->{'value'}.'</td>'.
1352: "</tr>\n";
1353: }
1354: } continue {
1355: $foilindex++;
1356: }
1357: } continue {
1358: $conceptindex++;
1359: }
1360: $table .= "</table>\n";
1361: #
1362: # Build option index with color stuff
1363: return ($table,\@Foils,\@Concepts);
1364: }
1365:
1366: sub build_option_index {
1367: my ($ORdata)= @_;
1368: my $table = "<table>\n";
1369: my $optionindex = 0;
1370: my @Rows;
1.48 matthew 1371: foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1.46 matthew 1372: push (@Rows,
1373: '<tr>'.
1374: '<td bgcolor="'.$plotcolors->[$optionindex++].'">'.
1375: (' 'x4).'</td>'.
1376: '<td>'.$option.'</td>'.
1377: "</tr>\n");
1378: }
1379: shift(@Rows); # Throw away 'correct option chosen' color
1380: $table .= join('',reverse(@Rows));
1381: $table .= "</table>\n";
1382: }
1383:
1.33 matthew 1384: #########################################################
1385: #########################################################
1386: ##
1.46 matthew 1387: ## Generic Interface Routines
1.33 matthew 1388: ##
1389: #########################################################
1390: #########################################################
1.23 matthew 1391: sub CreateInterface {
1.28 matthew 1392: ##
1393: ## Environment variable initialization
1.36 matthew 1394: if (! exists$ENV{'form.AnalyzeOver'}) {
1395: $ENV{'form.AnalyzeOver'} = 'Tries';
1.28 matthew 1396: }
1397: ##
1398: ## Build the menu
1.7 stredwic 1399: my $Str = '';
1.23 matthew 1400: $Str .= '<table cellspacing="5">'."\n";
1401: $Str .= '<tr>';
1402: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1403: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.31 matthew 1404: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1405: $Str .= '<td align="center"> </td>';
1.23 matthew 1406: $Str .= '</tr>'."\n";
1.31 matthew 1407: ##
1408: ##
1.23 matthew 1409: $Str .= '<tr><td align="center">'."\n";
1410: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28 matthew 1411: $Str .= '</td>';
1412: #
1413: $Str .= '<td align="center">';
1.23 matthew 1414: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28 matthew 1415: $Str .= '</td>';
1416: #
1.31 matthew 1417: # $Str .= '<td align="center">';
1.23 matthew 1418: my $only_seq_with_assessments = sub {
1419: my $s=shift;
1420: if ($s->{'num_assess'} < 1) {
1421: return 0;
1422: } else {
1423: return 1;
1424: }
1425: };
1.31 matthew 1426: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23 matthew 1427: $only_seq_with_assessments);
1.36 matthew 1428: ##
1429: ##
1.28 matthew 1430: $Str .= '<td>';
1.36 matthew 1431: { # These braces are here to organize the code, not scope it.
1432: {
1433: $Str .= '<nobr>'.&mt('Analyze Over ');
1.51 matthew 1434: $Str .= &Apache::loncommon::help_open_topic
1435: ('Analysis_Analyze_Over');
1.36 matthew 1436: $Str .='<select name="AnalyzeOver" >';
1437: $Str .= '<option value="Tries" ';
1438: if (! exists($ENV{'form.AnalyzeOver'}) ||
1439: $ENV{'form.AnalyzeOver'} eq 'Tries'){
1440: # Default to Tries
1441: $Str .= ' selected ';
1442: }
1443: $Str .= '>'.&mt('Tries').'</option>';
1444: $Str .= '<option value="Time" ';
1445: $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
1446: $Str .= '>'.&mt('Time').'</option>';
1.51 matthew 1447: $Str .= '</select>';
1448: $Str .= '</nobr><br />';
1.36 matthew 1449: }
1450: {
1451: $Str .= '<nobr>'.&mt('Analyze as ');
1.51 matthew 1452: $Str .= &Apache::loncommon::help_open_topic
1453: ('Analysis_Analyze_as');
1.36 matthew 1454: $Str .='<select name="AnalyzeAs" >';
1455: $Str .= '<option value="Concepts" ';
1456: if (! exists($ENV{'form.AnalyzeAs'}) ||
1457: $ENV{'form.AnalyzeAs'} eq 'Concepts'){
1458: # Default to Concepts
1459: $Str .= ' selected ';
1460: }
1461: $Str .= '>'.&mt('Concepts').'</option>';
1462: $Str .= '<option value="Foils" ';
1463: $Str .= ' selected ' if ($ENV{'form.AnalyzeAs'} eq 'Foils');
1464: $Str .= '>'.&mt('Foils').'</option>';
1465: $Str .= '</select></nobr><br />';
1466: }
1467: {
1468: $Str .= '<br /><nobr>'.&mt('Number of Plots:');
1.52 matthew 1469: $Str .= &Apache::loncommon::help_open_topic
1470: ('Analysis_num_plots');
1.36 matthew 1471: $Str .= '<select name="NumPlots">';
1472: if (! exists($ENV{'form.NumPlots'})
1473: || $ENV{'form.NumPlots'} < 1
1474: || $ENV{'form.NumPlots'} > 20) {
1475: $ENV{'form.NumPlots'} = 5;
1476: }
1477: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
1478: $Str .= '<option value="'.$i.'" ';
1479: if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
1480: $Str .= '>'.$i.'</option>';
1481: }
1482: $Str .= '</select></nobr>';
1483: }
1.28 matthew 1484: }
1485: $Str .= '</td>';
1.36 matthew 1486: ##
1487: ##
1.28 matthew 1488: $Str .= '</tr>'."\n";
1.23 matthew 1489: $Str .= '</table>'."\n";
1.42 matthew 1490: return $Str;
1.23 matthew 1491: }
1492:
1.46 matthew 1493: sub ProblemSelector {
1.23 matthew 1494: my $Str;
1495: $Str = "\n<table>\n";
1496: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1497: next if ($seq->{'num_assess'}<1);
1498: my $seq_str = '';
1499: foreach my $res (@{$seq->{'contents'}}) {
1.26 matthew 1500: next if ($res->{'type'} ne 'assessment');
1.23 matthew 1501: foreach my $part (@{$res->{'parts'}}) {
1502: my $partdata = $res->{'partdata'}->{$part};
1.47 matthew 1503: # &Apache::lonnet::logthis('----------------');
1504: # while (my ($k,$v)=each(%$partdata)) {
1505: # if (ref($v) eq 'ARRAY') {
1506: # &Apache::lonnet::logthis($k.' = '.join(',',@$v));
1507: # } else {
1508: # &Apache::lonnet::logthis($k.' = '.$v);
1509: # }
1510: # }
1511: if ((! exists($partdata->{'option'}) ||
1512: $partdata->{'option'} == 0 ) &&
1513: (! exists($partdata->{'radiobutton'}) ||
1514: $partdata->{'radiobutton'} == 0)) {
1.23 matthew 1515: next;
1516: }
1517: for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
1518: my $respid = $partdata->{'ResponseIds'}->[$i];
1519: my $resptype = $partdata->{'ResponseTypes'}->[$i];
1.48 matthew 1520: if ($resptype eq 'option' ){
1521: # if ($resptype eq 'option' || $resptype eq 'radiobutton') {
1.54 matthew 1522: my $value = &make_target_id({symb=>$res->{'symb'},
1523: part=>$part,
1524: respid=>$respid,
1525: resptype=>$resptype});
1.23 matthew 1526: my $checked = '';
1527: if ($ENV{'form.problemchoice'} eq $value) {
1528: $checked = 'checked ';
1529: }
1.50 matthew 1530: my $title = $res->{'title'};
1531: if (! defined($title) || $title eq '') {
1532: ($title) = ($res->{'src'} =~ m:/([^/]*)$:);
1533: }
1.23 matthew 1534: $seq_str .= '<tr><td>'.
1535: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
1536: '</td><td>'.
1.50 matthew 1537: '<a href="'.$res->{'src'}.'">'.$title.'</a> ';
1.48 matthew 1538: # '<a href="'.$res->{'src'}.'">'.$resptype.' '.$res->{'title'}.'</a> ';
1.23 matthew 1539: if ($partdata->{'option'} > 1) {
1540: $seq_str .= &mt('response').' '.$respid;
1541: }
1542: $seq_str .= "</td></tr>\n";
1.11 minaeibi 1543: }
1544: }
1545: }
1546: }
1.23 matthew 1547: if ($seq_str ne '') {
1548: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
1549: "</tr>\n".$seq_str;
1550: }
1.11 minaeibi 1551: }
1.23 matthew 1552: $Str .= "</table>\n";
1553: return $Str;
1.33 matthew 1554: }
1555:
1556: #########################################################
1557: #########################################################
1558: ##
1559: ## Misc functions
1560: ##
1561: #########################################################
1562: #########################################################
1563: sub get_problem_symb {
1564: my $problemstring = shift();
1.54 matthew 1565: my ($symb,$partid,$respid,$resptype) = split(':',$problemstring);
1566: return ({ symb => $symb,
1567: part => $partid,
1568: respid => $respid,
1569: type => $resptype } );
1.11 minaeibi 1570: }
1571:
1.23 matthew 1572: sub get_resource_from_symb {
1573: my ($symb) = @_;
1574: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1575: foreach my $res (@{$seq->{'contents'}}) {
1576: if ($res->{'symb'} eq $symb) {
1577: return $res;
1.2 stredwic 1578: }
1.1 stredwic 1579: }
1580: }
1.23 matthew 1581: return undef;
1.42 matthew 1582: }
1583:
1.54 matthew 1584: sub get_prev_curr_next {
1585: my ($target) = @_;
1586: #
1587: # Build an array with the data we need to search through
1588: my @Resource;
1589: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1590: foreach my $res (@{$seq->{'contents'}}) {
1591: next if ($res->{'type'} ne 'assessment');
1592: foreach my $part (@{$res->{'parts'}}) {
1593: my $partdata = $res->{'partdata'}->{$part};
1594: for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
1595: my $respid = $partdata->{'ResponseIds'}->[$i];
1596: my $resptype = $partdata->{'ResponseTypes'}->[$i];
1597: next if ($resptype ne 'option');
1598: push (@Resource,
1599: { symb => $res->{symb},
1600: part => $part,
1601: respid => $partdata->{'ResponseIds'}->[$i],
1602: resource => $res,
1603: resptype => $resptype
1604: } );
1605: }
1606: }
1607: }
1608: }
1609: #
1610: #
1611: # Get the index of the current situation
1612: my $curr_idx;
1613: for ($curr_idx=0;$curr_idx<$#Resource;$curr_idx++) {
1614: my $curr_item = $Resource[$curr_idx];
1615: last if ($curr_item->{'symb'} eq $target->{'symb'} &&
1616: $curr_item->{'part'} eq $target->{'part'} &&
1617: $curr_item->{'respid'} eq $target->{'respid'} &&
1618: $curr_item->{'resptype'} eq $target->{'resptype'});
1619: }
1620: my $curr_item = $Resource[$curr_idx];
1621: if ($curr_item->{'symb'} ne $target->{'symb'} ||
1622: $curr_item->{'part'} ne $target->{'part'} ||
1623: $curr_item->{'respid'} ne $target->{'respid'} ||
1624: $curr_item->{'resptype'} ne $target->{'resptype'}){
1625: # bogus symb - return nothing
1626: return (undef,undef,undef);
1627: }
1628: #
1629: # Now just pick up the data we need
1630: my ($prev,$curr,$next);
1631: if ($curr_idx == 0) {
1632: $prev = undef;
1633: $curr = $Resource[$curr_idx ];
1634: $next = $Resource[$curr_idx+1];
1635: } elsif ($curr_idx == $#Resource) {
1636: $prev = $Resource[$curr_idx-1];
1637: $curr = $Resource[$curr_idx ];
1638: $next = undef;
1639: } else {
1640: $prev = $Resource[$curr_idx-1];
1641: $curr = $Resource[$curr_idx ];
1642: $next = $Resource[$curr_idx+1];
1643: }
1644: return ($prev,$curr,$next);
1645: }
1646:
1647: sub make_target_id {
1648: my ($target) = @_;
1649: my $id = &Apache::lonnet::escape($target->{'symb'}).':'.
1650: &Apache::lonnet::escape($target->{'part'}).':'.
1651: &Apache::lonnet::escape($target->{'respid'}).':'.
1652: &Apache::lonnet::escape($target->{'resptype'});
1653: return $id;
1654: }
1655:
1656: sub get_target_from_id {
1657: my ($id) = @_;
1658: my ($symb,$part,$respid,$resptype) = split(':',$id);
1659: return ({ symb =>&Apache::lonnet::unescape($symb),
1660: part =>&Apache::lonnet::unescape($part),
1661: respid =>&Apache::lonnet::unescape($respid),
1662: resptype =>&Apache::lonnet::unescape($resptype)});
1663: }
1.47 matthew 1664:
1665: #########################################################
1666: #########################################################
1667: ##
1668: ## Misc Option Response functions
1669: ##
1670: #########################################################
1671: #########################################################
1672: sub get_time_from_row {
1.42 matthew 1673: my ($row) = @_;
1674: if (ref($row)) {
1.47 matthew 1675: return $row->[&Apache::loncoursedata::RD_timestamp()];
1.42 matthew 1676: }
1677: return undef;
1678: }
1679:
1.47 matthew 1680: sub get_tries_from_row {
1.42 matthew 1681: my ($row) = @_;
1682: if (ref($row)) {
1.47 matthew 1683: return $row->[&Apache::loncoursedata::RD_tries()];
1.42 matthew 1684: }
1685: return undef;
1686: }
1687:
1.48 matthew 1688: sub hashify_attempt {
1689: my ($row) = @_;
1690: my %attempt;
1691: $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
1692: $attempt{'submission'} = $row->[&Apache::loncoursedata::RD_submission()];
1693: $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
1694: $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
1695: return %attempt;
1696: }
1697:
1.46 matthew 1698: sub Process_OR_Row {
1.42 matthew 1699: my ($row) = @_;
1700: my %RowData;
1.47 matthew 1701: my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1702: my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
1703: my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
1704: my $submission = $row->[&Apache::loncoursedata::RD_submission()];
1705: my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
1706: my $tries = $row->[&Apache::loncoursedata::RD_tries()];
1.43 matthew 1707: return undef if ($award eq 'MISSING_ANSWER');
1.42 matthew 1708: if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
1709: $RowData{'_correct'} = 1;
1710: }
1711: $RowData{'_total'} = 1;
1712: my @Foilgrades = split('&',$grading);
1713: my @Foilsubs = split('&',$submission);
1714: for (my $j=0;$j<=$#Foilgrades;$j++) {
1715: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1716: my (undef,$submission) = split('=',$Foilsubs[$j]);
1717: if ($correct) {
1718: $RowData{$foilid}->{'_correct'}++;
1719: } else {
1720: $submission = &Apache::lonnet::unescape($submission);
1721: $RowData{$foilid}->{$submission}++;
1722: }
1723: $RowData{$foilid}->{'_total'}++;
1724: }
1725: return %RowData;
1.1 stredwic 1726: }
1727:
1.39 matthew 1728: ##
1729: ## get problem data and put it into a useful data structure.
1730: ## note: we must force each foil and option to not begin or end with
1731: ## spaces as they are stored without such data.
1732: ##
1.48 matthew 1733: sub get_problem_data {
1.25 matthew 1734: my ($url) = @_;
1735: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
1.23 matthew 1736: (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
1.25 matthew 1737: my %Answer;
1.23 matthew 1738: %Answer=&Apache::lonnet::str2hash($Answ);
1.25 matthew 1739: my %Partdata;
1740: foreach my $part (@{$Answer{'parts'}}) {
1741: while (my($key,$value) = each(%Answer)) {
1742: next if ($key !~ /^$part/);
1743: $key =~ s/^$part\.//;
1744: if (ref($value) eq 'ARRAY') {
1745: if ($key eq 'options') {
1.48 matthew 1746: $Partdata{$part}->{'_Options'}=$value;
1.25 matthew 1747: } elsif ($key eq 'concepts') {
1.48 matthew 1748: $Partdata{$part}->{'_Concepts'}=$value;
1.25 matthew 1749: } elsif ($key =~ /^concept\.(.*)$/) {
1750: my $concept = $1;
1751: foreach my $foil (@$value) {
1.48 matthew 1752: $Partdata{$part}->{'_Foils'}->{$foil}->{'_Concept'}=
1.36 matthew 1753: $concept;
1.25 matthew 1754: }
1755: }
1756: } else {
1757: if ($key=~ /^foil\.text\.(.*)$/) {
1758: my $foil = $1;
1.48 matthew 1759: $Partdata{$part}->{'_Foils'}->{$foil}->{'name'}=$foil;
1.43 matthew 1760: $value =~ s/(\s*$|^\s*)//g;
1.48 matthew 1761: $Partdata{$part}->{'_Foils'}->{$foil}->{'text'}=$value;
1.25 matthew 1762: } elsif ($key =~ /^foil\.value\.(.*)$/) {
1763: my $foil = $1;
1.48 matthew 1764: $Partdata{$part}->{'_Foils'}->{$foil}->{'value'}=$value;
1.25 matthew 1765: }
1.47 matthew 1766: }
1767: }
1768: }
1769: return %Partdata;
1770: }
1771:
1.23 matthew 1772: 1;
1.1 stredwic 1773:
1774: __END__
1.48 matthew 1775:
1776: #####
1777: # partdata{part}->{_Foils}->{foilid}->{'name'} = $
1778: # ->{'text'} = $
1779: # ->{'value'} = $
1780: # ->{'_Concept'} = $
1781: # partdata{part}->{_Options} = @
1782: # partdata{part}->{_Concepts} = @
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>