Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.35
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.33 matthew 3:
1.35 ! matthew 4: # $Id: lonproblemanalysis.pm,v 1.34 2003/10/13 21:12:56 matthew Exp $
1.1 stredwic 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.11 minaeibi 29: package Apache::lonproblemanalysis;
1.1 stredwic 30:
31: use strict;
32: use Apache::lonnet();
1.25 matthew 33: use Apache::loncommon();
1.7 stredwic 34: use Apache::lonhtmlcommon();
1.23 matthew 35: use Apache::loncoursedata();
36: use Apache::lonstatistics;
37: use Apache::lonlocal;
1.2 stredwic 38:
1.1 stredwic 39: sub BuildProblemAnalysisPage {
1.23 matthew 40: my ($r,$c)=@_;
1.24 matthew 41: $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
1.25 matthew 42: $r->print(&CreateInterface());
1.28 matthew 43: #
44: my @Students = @Apache::lonstatistics::Students;
45: #
1.33 matthew 46: if (exists($ENV{'form.updatecaches'}) ||
47: (exists($ENV{'form.firstanalysis'}) &&
48: $ENV{'form.firstanalysis'} ne 'no')) {
49: &Apache::lonstatistics::Gather_Full_Student_Data($r);
50: }
51: if (! exists($ENV{'form.firstanalysis'})) {
52: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
53: } else {
54: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
55: }
56: if (exists($ENV{'form.problemchoice'}) &&
57: ! exists($ENV{'form.SelectAnother'})) {
1.31 matthew 58: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
59: &mt('Analyze Problem Again').'" />');
60: $r->print(' 'x5);
61: $r->print('<input type="submit" name="ClearCache" value="'.
62: &mt('Clear Caches').'" />');
63: $r->print(' 'x5);
1.33 matthew 64: $r->print('<input type="submit" name="updatecaches" value="'.
65: &mt('Update Student Data').'" />');
66: $r->print(' 'x5);
1.31 matthew 67: $r->print('<input type="hidden" name="problemchoice" value="'.
68: $ENV{'form.problemchoice'}.'" />');
69: $r->print('<input type="submit" name="SelectAnother" value="'.
70: &mt('Choose a different resource').'" />');
71: $r->print(' 'x5);
72: #
1.25 matthew 73: $r->print('<hr />');
1.23 matthew 74: #
1.25 matthew 75: my ($symb,$part,$resid) = &get_problem_symb(
1.23 matthew 76: &Apache::lonnet::unescape($ENV{'form.problemchoice'})
77: );
1.28 matthew 78: #
1.23 matthew 79: my $resource = &get_resource_from_symb($symb);
80: if (defined($resource)) {
1.25 matthew 81: my %Data = &get_problem_data($resource->{'src'});
82: my $ORdata = $Data{$part.'.'.$resid};
83: ##
1.26 matthew 84: ## Render the problem
1.25 matthew 85: my $base;
86: ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
87: $base = "http://".$ENV{'SERVER_NAME'}.$base;
1.26 matthew 88: my $rendered_problem =
89: &Apache::lonnet::ssi_body($resource->{'src'});
1.30 matthew 90: $rendered_problem =~ s/<\s*form\s*/<nop /g;
91: $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
1.26 matthew 92: $r->print('<table bgcolor="ffffff"><tr><td>'.
1.25 matthew 93: '<base href="'.$base.'" />'.
1.26 matthew 94: $rendered_problem.
95: '</td></tr></table>');
1.25 matthew 96: ##
97: ## Analyze the problem
1.26 matthew 98: my $PerformanceData =
99: &Apache::loncoursedata::get_optionresponse_data
1.28 matthew 100: (\@Students,$symb,$resid);
1.26 matthew 101: if (defined($PerformanceData) &&
102: ref($PerformanceData) eq 'ARRAY') {
1.28 matthew 103: if ($ENV{'form.AnalyzeBy'} eq 'Tries') {
1.33 matthew 104: my $analysis_html = &tries_analysis($PerformanceData,
105: $ORdata);
106: $r->print($analysis_html);
107: } elsif ($ENV{'form.AnalyzeBy'} eq 'Time') {
108: my $analysis_html = &time_analysis($PerformanceData,
1.28 matthew 109: $ORdata);
1.26 matthew 110: $r->print($analysis_html);
1.28 matthew 111: } else {
112: $r->print('<h2>'.
113: &mt('The analysis you have selected is '.
114: 'not supported at this time').
115: '</h2>');
116: }
1.26 matthew 117: } else {
118: $r->print('<h2>'.
119: &mt('There is no student data for this problem.').
120: '</h2>');
121: }
1.23 matthew 122: } else {
123: $r->print('resource is undefined');
1.7 stredwic 124: }
1.23 matthew 125: $r->print('<hr />');
1.25 matthew 126: } else {
1.31 matthew 127: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
128: &mt('Analyze Problem').'" />');
129: $r->print(' 'x5);
1.27 matthew 130: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.31 matthew 131: $r->print(&OptionResponseProblemSelector());
1.1 stredwic 132: }
133: }
134:
1.25 matthew 135:
1.33 matthew 136: #########################################################
137: #########################################################
138: ##
139: ## Misc interface routines use by analysis code
140: ##
141: #########################################################
142: #########################################################
143: sub build_foil_index {
144: my ($ORdata) = @_;
145: my @Foils = sort(keys(%{$ORdata->{'Foiltext'}}));
1.25 matthew 146: my %Row_Label;
147: foreach my $foilid (@Foils) {
148: my $value = $ORdata->{'Foiltext'}->{$foilid};
149: $Row_Label{$foilid} = $ORdata->{'Foiltext'}->{$foilid};
150: }
1.31 matthew 151: #
152: # Build up the table of row labels.
153: my $table = '<table border="1" >'."\n";
1.32 matthew 154: $table .= '<tr><th>'.&mt('Foil Number').'</th>'.
155: '<th>'.&mt('Foil Text')."</th></tr>\n";
1.31 matthew 156: my $index = 1;
157: foreach my $foilid (@Foils) {
158: $table .= '<tr><td>'.$index.'</td>'.
159: '<td>'.$Row_Label{$foilid}."</td></tr>\n";
160: } continue {
161: $index++;
1.25 matthew 162: }
1.31 matthew 163: $table .= "</table>\n";
1.33 matthew 164: return ($table,@Foils);
165: }
166:
167: #########################################################
168: #########################################################
169: ##
170: ## Tries Analysis
171: ##
172: #########################################################
173: #########################################################
174: sub tries_analysis {
175: my ($PerformanceData,$ORdata) = @_;
176: my $mintries = 1;
177: my $maxtries = $ENV{'form.NumPlots'};
178: my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
179: $mintries,$maxtries);
180: my ($table,@Foils) = &build_foil_index($ORdata);
1.31 matthew 181: #
182: # Compute the data neccessary to make the plots
1.25 matthew 183: my @PlotData;
184: my @CumulativePlotData;
185: foreach my $foilid (@Foils) {
186: for (my $i=$mintries;$i<=$maxtries;$i++) {
187: #
188: # Gather the per-attempt data
189: push (@{$PlotData[$i]->{'good'}},
190: $ResponseData{$foilid}->[$i]->{'percent_corr'});
191: push (@{$PlotData[$i]->{'bad'}},
192: 100-$ResponseData{$foilid}->[$i]->{'percent_corr'});
1.31 matthew 193: #
194: # Someday we may need the cumulative data and I think
195: # this is a neat way of computing it as we go along.
1.25 matthew 196: push (@{$CumulativePlotData[$i]->{'good'}},
197: $CumulativePlotData[-1]->{'good'}+
198: $ResponseData{$foilid}->[$i]->{'correct'});
199: push (@{$CumulativePlotData[$i]->{'bad'}},
200: $CumulativePlotData[-1]->{'bad'}+
201: $ResponseData{$foilid}->[$i]->{'incorrect'});
202: }
203: }
1.31 matthew 204: #
205: # Build a table for the plots
206: $table .= "<table>\n";
207: my @Plots;
1.25 matthew 208: for (my $i=$mintries;$i<=$maxtries;$i++) {
1.27 matthew 209: my $minstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
210: my $maxstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
211: foreach my $foilid (@Foils) {
212: if ($minstu > $ResponseData{$foilid}->[$i]->{'total'}) {
213: $minstu = $ResponseData{$foilid}->[$i]->{'total'};
214: }
215: if ($maxstu < $ResponseData{$foilid}->[$i]->{'total'}) {
216: $maxstu = $ResponseData{$foilid}->[$i]->{'total'};
217: }
218: }
1.28 matthew 219: $maxstu = 0 if (! $maxstu);
220: $minstu = 0 if (! $minstu);
1.35 ! matthew 221: my $title;
1.27 matthew 222: if ($maxstu == $minstu) {
1.35 ! matthew 223: $title = 'Attempt '.$i.', '.$maxstu.' students';
1.27 matthew 224: } else {
1.35 ! matthew 225: $title = 'Attempt '.$i.', '.$minstu.'-'.$maxstu.' students';
1.27 matthew 226: }
1.35 ! matthew 227: my $graphlink = &Apache::loncommon::DrawGraph($title,
! 228: 'Foil Number',
! 229: 'Percent Correct',
! 230: 100,
! 231: $PlotData[$i]->{'good'},
! 232: $PlotData[$i]->{'bad'});
1.31 matthew 233: push(@Plots,$graphlink);
1.25 matthew 234: }
1.31 matthew 235: #
236: # Should this be something the user can set? Too many dialogs!
237: my $plots_per_row = 2;
238: while (my $plotlink = shift(@Plots)) {
239: $table .= '<tr><td>'.$plotlink.'</td>';
240: for (my $i=1;$i<$plots_per_row;$i++) {
241: if ($plotlink = shift(@Plots)) {
242: $table .= '<td>'.$plotlink.'</td>';
243: } else {
244: $table .= '<td></td>';
245: }
246: }
247: $table .= "</tr>\n";
1.25 matthew 248: }
1.31 matthew 249: $table .= "</table>\n";
1.25 matthew 250: return ($table);
251: }
252:
253: sub analyze_option_data_by_tries {
1.26 matthew 254: my ($PerformanceData,$mintries,$maxtries) = @_;
1.25 matthew 255: my %Trydata;
256: $mintries = 1 if (! defined($mintries) || $mintries < 1);
257: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26 matthew 258: foreach my $row (@$PerformanceData) {
259: next if (! defined($row));
1.25 matthew 260: my ($grading,$submission,$time,$tries) = @$row;
261: my @Foilgrades = split('&',$grading);
262: my @Foilsubs = split('&',$submission);
263: for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
264: if ($tries == $numtries) {
265: foreach my $foilgrade (@Foilgrades) {
266: my ($foilid,$correct) = split('=',$foilgrade);
267: if ($correct) {
268: $Trydata{$foilid}->[$numtries]->{'correct'}++;
269: } else {
270: $Trydata{$foilid}->[$numtries]->{'incorrect'}++;
271: }
272: }
273: }
274: }
275: }
276: foreach my $foilid (keys(%Trydata)) {
277: foreach my $tryhash (@{$Trydata{$foilid}}) {
278: next if ((! exists($tryhash->{'correct'}) &&
279: ! exists($tryhash->{'incorrect'})) ||
280: ($tryhash->{'correct'} < 1 &&
281: $tryhash->{'incorrect'} < 1));
1.27 matthew 282: $tryhash->{'total'} = $tryhash->{'correct'} +
283: $tryhash->{'incorrect'};
1.25 matthew 284: $tryhash->{'percent_corr'} = 100 *
285: ($tryhash->{'correct'} /
286: ($tryhash->{'correct'} + $tryhash->{'incorrect'})
287: );
288: }
289: }
290: return %Trydata;
291: }
292:
1.33 matthew 293: #########################################################
294: #########################################################
295: ##
296: ## Time Analysis
297: ##
298: #########################################################
299: #########################################################
300: sub time_analysis {
301: my ($PerformanceData,$ORdata) = @_;
302: my $num_plots = $ENV{'form.NumPlots'};
303: my ($table,@Foils) = &build_foil_index($ORdata);
304: my $num_data = scalar(@$PerformanceData)-1;
305: my $percent = sprintf('%2f',100/$num_plots);
306: for (my $i=0;$i<$num_plots;$i++) {
1.34 matthew 307: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
308: ('startdate_'.$i);
309: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
310: ('enddate_'.$i);
311: my ($begin_index,$end_index,$plottitle,$plothtml,$data);
312: if (! defined($starttime) || ! defined($endtime)) {
313: $begin_index = $i*int($num_data/$num_plots);
314: $end_index = ($i+1)*int($num_data/$num_plots);
315: my $lownum = sprintf('%2.1f',$i*$percent);
316: $lownum =~ s/(\.0)$//;
317: my $highnum = sprintf('%2.1f',($i+1)*$percent);
318: $highnum =~ s/(\.0)$//;
319: $plottitle = $lownum.'% to '.$highnum.'% of submissions';
320: } else {
321: my $j;
322: while (++$j < scalar(@$PerformanceData)) {
323: last if ($PerformanceData->[$j]->[2] > $starttime);
324: }
325: $begin_index = $j;
326: while (++$j < scalar(@$PerformanceData)) {
327: last if ($PerformanceData->[$j]->[2] > $endtime);
328: }
329: $end_index = $j;
1.35 ! matthew 330: $plottitle = 'Tries plot '.($i+1);
1.34 matthew 331: }
332:
333: ($plothtml,$starttime,$endtime,$data) =
1.33 matthew 334: &analyze_option_data_by_time($PerformanceData,
335: $begin_index,$end_index,
1.34 matthew 336: $plottitle,
1.33 matthew 337: @Foils);
1.34 matthew 338: my $startdateform = &Apache::lonhtmlcommon::date_setter
339: ('Statistics','startdate_'.$i,$starttime);
340: my $enddateform = &Apache::lonhtmlcommon::date_setter
341: ('Statistics','enddate_'.$i,$endtime);
342: $plothtml.= "<br />\n".
343: "<b>Start Time</b>: "." ".$startdateform."<br />\n".
344: "<b>End Time</b> : "." ".$enddateform."<br />\n";
1.33 matthew 345: $table.=$plothtml;
346: }
347: return $table;
348: }
349:
350: sub analyze_option_data_by_time {
351: my ($PerformanceData,$begin_index,$end_index,$description,@Foils) = @_;
352: my %TimeData;
353: #
354: # Get the start and end times for this segment of the plot
355: my $starttime = $PerformanceData->[$begin_index]->[2];
356: my $endtime = $PerformanceData->[$end_index ]->[2];
357: #
358: # Compute the number getting the foils correct or incorrects
359: for (my $i=$begin_index;$i<=$end_index;$i++) {
360: my $row = $PerformanceData->[$i];
361: next if (! defined($row));
362: my ($grading,$submission,$time,$tries) = @$row;
363: my @Foilgrades = split('&',$grading);
364: my @Foilsubs = split('&',$submission);
365: foreach my $foilgrade (@Foilgrades) {
366: my ($foilid,$correct) = split('=',$foilgrade);
367: if ($correct) {
368: $TimeData{$foilid}->{'correct'}++;
369: } else {
370: $TimeData{$foilid}->{'incorrect'}++;
371: }
372: }
373: }
374: #
375: # Compute the total and percent correct
376: my @Plotdata1;
377: my @Plotdata2;
378: foreach my $foilid (@Foils) {
379: if (! exists($TimeData{$foilid}->{'correct'})) {
380: $TimeData{$foilid}->{'correct'} = 0;
381: }
382: if (! exists($TimeData{$foilid}->{'incorrect'})) {
383: $TimeData{$foilid}->{'incorrect'} = 0;
384: }
385: $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
386: $TimeData{$foilid}->{'incorrect'};
387: $TimeData{$foilid}->{'percent_corr'} = 100 *
388: $TimeData{$foilid}->{'correct'} /
389: $TimeData{$foilid}->{'total'};
390: push (@Plotdata1, $TimeData{$foilid}->{'percent_corr'});
391: push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
392: }
393: #
394: # Create the plot
395: my $graphlink = &Apache::loncommon::DrawGraph
396: ($description,#'Time Interval Analysis',
397: 'Foil Number',
398: 'Percent Correct / Incorrect',
399: 100,
400: \@Plotdata1,\@Plotdata2);
401: #
402: return ($graphlink,$starttime,$endtime,\%TimeData);
1.1 stredwic 403: }
404:
1.33 matthew 405:
406:
407:
408: #########################################################
409: #########################################################
410: ##
411: ## Interface
412: ##
413: #########################################################
414: #########################################################
1.23 matthew 415: sub CreateInterface {
1.28 matthew 416: ##
417: ## Environment variable initialization
418: if (! exists$ENV{'form.AnalyzeBy'}) {
419: $ENV{'form.AnalyzeBy'} = 'Tries';
420: }
421: ##
422: ## Build the menu
1.7 stredwic 423: my $Str = '';
1.23 matthew 424: $Str .= '<table cellspacing="5">'."\n";
425: $Str .= '<tr>';
426: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
427: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.31 matthew 428: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
429: $Str .= '<td align="center"> </td>';
1.23 matthew 430: $Str .= '</tr>'."\n";
1.31 matthew 431: ##
432: ##
1.23 matthew 433: $Str .= '<tr><td align="center">'."\n";
434: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28 matthew 435: $Str .= '</td>';
436: #
437: $Str .= '<td align="center">';
1.23 matthew 438: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28 matthew 439: $Str .= '</td>';
440: #
1.31 matthew 441: # $Str .= '<td align="center">';
1.23 matthew 442: my $only_seq_with_assessments = sub {
443: my $s=shift;
444: if ($s->{'num_assess'} < 1) {
445: return 0;
446: } else {
447: return 1;
448: }
449: };
1.31 matthew 450: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23 matthew 451: $only_seq_with_assessments);
1.31 matthew 452: # $Str .= '</td>';
1.28 matthew 453: #
454: $Str .= '<td>';
1.31 matthew 455: $Str .= '<nobr>'.&mt('Analyze By ');
456: $Str .='<select name="AnalyzeBy" >';
457: #
458: $Str .= '<option value="Tries" ';
459: if (! exists($ENV{'form.AnalyzeBy'}) || $ENV{'form.AnalyzeBy'} eq 'Tries'){
460: # Default to Tries
461: $Str .= ' selected ';
462: }
463: $Str .= '>'.&mt('Tries').'</option>';
464: #
465: $Str .= '<option value="Time" ';
466: $Str .= ' selected ' if ($ENV{'form.AnalyzeBy'} eq 'Time');
467: $Str .= '>'.&mt('Time').'</option>';
468: $Str .= '</select></nobr><br />';
469: #
470: $Str .= '<br /><nobr>'.&mt('Number of Plots:');
471: $Str .= '<select name="NumPlots">';
472: if (! exists($ENV{'form.NumPlots'})
473: || $ENV{'form.NumPlots'} < 1
474: || $ENV{'form.NumPlots'} > 20) {
1.33 matthew 475: $ENV{'form.NumPlots'} = 5;
1.31 matthew 476: }
477: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
478: $Str .= '<option value="'.$i.'" ';
479: if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
480: $Str .= '>'.$i.'</option>';
1.28 matthew 481: }
1.31 matthew 482: $Str .= '</select></nobr>';
1.28 matthew 483: $Str .= '</td>';
484: #
485: $Str .= '</tr>'."\n";
1.23 matthew 486: $Str .= '</table>'."\n";
487: return ($Str);
488: }
489:
490: sub OptionResponseProblemSelector {
491: my $Str;
492: $Str = "\n<table>\n";
493: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
494: next if ($seq->{'num_assess'}<1);
495: my $seq_str = '';
496: foreach my $res (@{$seq->{'contents'}}) {
497: # &Apache::lonnet::logthis('checking '.$res->{'title'});
1.26 matthew 498: next if ($res->{'type'} ne 'assessment');
1.23 matthew 499: foreach my $part (@{$res->{'parts'}}) {
500: my $partdata = $res->{'partdata'}->{$part};
501: if (! exists($partdata->{'option'}) ||
502: $partdata->{'option'} == 0) {
503: next;
504: }
505: for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
506: my $respid = $partdata->{'ResponseIds'}->[$i];
507: my $resptype = $partdata->{'ResponseTypes'}->[$i];
508: if ($resptype eq 'option') {
1.25 matthew 509: my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid);
1.23 matthew 510: my $checked = '';
511: if ($ENV{'form.problemchoice'} eq $value) {
512: $checked = 'checked ';
513: }
514: $seq_str .= '<tr><td>'.
515: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
516: '</td><td>'.
517: '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
518: if ($partdata->{'option'} > 1) {
519: $seq_str .= &mt('response').' '.$respid;
520: }
521: $seq_str .= "</td></tr>\n";
1.11 minaeibi 522: }
523: }
524: }
525: }
1.23 matthew 526: if ($seq_str ne '') {
527: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
528: "</tr>\n".$seq_str;
529: }
1.11 minaeibi 530: }
1.23 matthew 531: $Str .= "</table>\n";
532: return $Str;
1.33 matthew 533: }
534:
535: #########################################################
536: #########################################################
537: ##
538: ## Misc functions
539: ##
540: #########################################################
541: #########################################################
542: sub get_problem_symb {
543: my $problemstring = shift();
544: my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
545: return ($symb,$partid,$resid);
1.11 minaeibi 546: }
547:
1.23 matthew 548: sub get_resource_from_symb {
549: my ($symb) = @_;
550: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
551: foreach my $res (@{$seq->{'contents'}}) {
552: if ($res->{'symb'} eq $symb) {
553: return $res;
1.2 stredwic 554: }
1.1 stredwic 555: }
556: }
1.23 matthew 557: return undef;
1.1 stredwic 558: }
559:
1.25 matthew 560: sub get_problem_data {
561: my ($url) = @_;
562: # my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
563: # 'grade_username' => $sname,
564: # 'grade_domain' => $sdom,
565: # 'grade_courseid' => $cid,
566: # 'grade_symb' => $symb));
567: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
1.23 matthew 568: (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
1.25 matthew 569: my %Answer;
1.23 matthew 570: %Answer=&Apache::lonnet::str2hash($Answ);
1.25 matthew 571: # &Apache::lonnet::logthis('keys of %Answer = '.join(', ',(keys(%Answer))));
572: # &Apache::lonnet::logthis('$Answer{parts} = '.
573: # join(', ',@{$Answer{'parts'}}));
574: my %Partdata;
575: foreach my $part (@{$Answer{'parts'}}) {
576: while (my($key,$value) = each(%Answer)) {
577: next if ($key !~ /^$part/);
578: $key =~ s/^$part\.//;
579: if (ref($value) eq 'ARRAY') {
580: if ($key eq 'options') {
581: $Partdata{$part}->{'Options'}=$value;
582: } elsif ($key eq 'concepts') {
583: $Partdata{$part}->{'Concepts'}=$value;
584: } elsif ($key =~ /^concept\.(.*)$/) {
585: my $concept = $1;
586: foreach my $foil (@$value) {
587: $Partdata{$part}->{$foil}->{'Concept'}=$concept;
588: }
589: }
1.26 matthew 590: # &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
591: # join(', ',@$value));
1.25 matthew 592: } else {
593: $value =~ s/^\s*//g;
594: $value =~ s/\s*$//g;
595: if ($key=~ /^foil\.text\.(.*)$/) {
596: my $foil = $1;
597: $Partdata{$part}->{'Foiltext'}->{$foil}=$value;
598: } elsif ($key =~ /^foil\.value\.(.*)$/) {
599: my $foil = $1;
600: $Partdata{$part}->{'FoilValues'}->{$foil}=$value;
601: }
1.26 matthew 602: # &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
1.25 matthew 603: }
604: }
1.23 matthew 605: }
606:
1.25 matthew 607: # my $parts='';
608: # foreach my $elm (@{$Answer{"parts"}}) {
609: # $parts.="$elm,";
610: # }
611: # chop($parts);
612: # my $conc='';
613: # foreach my $elm (@{$Answer{"$parts.concepts"}}) {
614: # $conc.="$elm@";
615: # }
616: # chop($conc);
617: #
618: # @Concepts=split(/\@/,$conc);
619: # foreach my $concept (@{$Answer{"$parts.concepts"}}) {
620: # foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
621: # $foil_to_concept{$foil} = $concept;
622: # #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
623: # }
624: # }
625: # return $symb;
626: return %Partdata;
1.1 stredwic 627: }
628:
1.23 matthew 629: 1;
1.1 stredwic 630:
631: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>