[LON-CAPA-cvs] cvs: loncom /interface/statistics lonproblemanalysis.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 16 Jan 2004 15:33:40 -0000
This is a MIME encoded message
--matthew1074267220
Content-Type: text/plain
matthew Fri Jan 16 10:33:40 2004 EDT
Modified files:
/loncom/interface/statistics lonproblemanalysis.pm
Log:
Bug 2556: Previous and Next problem buttons on detailed problem analysis.
--matthew1074267220
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040116103340.txt"
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.53 loncom/interface/statistics/lonproblemanalysis.pm:1.54
--- loncom/interface/statistics/lonproblemanalysis.pm:1.53 Thu Jan 8 14:20:12 2004
+++ loncom/interface/statistics/lonproblemanalysis.pm Fri Jan 16 10:33:40 2004
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonproblemanalysis.pm,v 1.53 2004/01/08 19:20:12 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.54 2004/01/16 15:33:40 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,8 +42,13 @@
'#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
];
-my @SubmitButtons = ({ name => 'ProblemAnalyis',
+my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
+ text => 'Previous Problem' },
+ { name => 'ProblemAnalysis',
text => 'Analyze Problem Again' },
+ { name => 'NextProblemAnalysis',
+ text => 'Next Problem' },
+ { name => 'break'},
{ name => 'ClearCache',
text => 'Clear Caches' },
{ name => 'updatecaches',
@@ -112,34 +117,57 @@
if (exists($ENV{'form.problemchoice'}) &&
! exists($ENV{'form.SelectAnother'})) {
foreach my $button (@SubmitButtons) {
- $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
- 'value="'.&mt($button->{'text'}).'" />');
- $r->print(' 'x5);
+ if ($button->{'name'} eq 'break') {
+ $r->print("<br />\n");
+ } else {
+ $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
+ 'value="'.&mt($button->{'text'}).'" />');
+ $r->print(' 'x5);
+ }
}
- $r->print('<input type="hidden" name="problemchoice" value="'.
- $ENV{'form.problemchoice'}.'" />');
#
$r->print('<hr />');
- #
- my ($symb,$part,$resid,$resptype) = &get_problem_symb(
- &Apache::lonnet::unescape($ENV{'form.problemchoice'}));
$r->rflush();
#
- my $resource = &get_resource_from_symb($symb);
- if (! defined($resource) || ! defined($resptype)) {
+ # Determine which problem we are to analyze
+ my $current_problem = &get_target_from_id($ENV{'form.problemchoice'});
+ #
+ my ($prev,$curr,$next) = &get_prev_curr_next($current_problem);
+ if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
+ $current_problem = $prev;
+ } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
+ $current_problem = $next;
+ } else {
+ $current_problem = $curr;
+ }
+ #
+ # Store the current problem choice and send it out in the form
+ $ENV{'form.problemchoice'} = &make_target_id($current_problem);
+ $r->print('<input type="hidden" name="problemchoice" value="'.
+ $ENV{'form.problemchoice'}.'" />');
+ #
+ if (! defined($current_problem->{'resource'})) {
$r->print('resource is undefined');
} else {
+ my $resource = $current_problem->{'resource'};
$r->print('<h1>'.$resource->{'title'}.'</h1>');
$r->print('<h3>'.$resource->{'src'}.'</h3>');
$r->print(&render_resource($resource));
$r->rflush();
my %Data = &get_problem_data($resource->{'src'});
- my $ProblemData = $Data{$part.'.'.$resid};
- if ($resptype eq 'option') {
- &OptionResponseAnalysis($r,$resource,$resid,$ProblemData,
+ my $ProblemData = $Data{$current_problem->{'part'}.
+ '.'.
+ $current_problem->{'respid'}};
+ if ($current_problem->{'resptype'} eq 'option') {
+ &OptionResponseAnalysis($r,$resource,
+ $current_problem->{'respid'},
+ $ProblemData,
\@Students);
- } elsif ($resptype eq 'radiobutton') {
- &RadioResponseAnalysis($r,$resource,$part,$resid,$ProblemData,
+ } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
+ &RadioResponseAnalysis($r,$resource,
+ $current_problem->{'part'},
+ $current_problem->{'respid'},
+ $ProblemData,
\@Students);
} else {
$r->print('<h2>This analysis is not supported</h2>');
@@ -355,10 +383,10 @@
#########################################################
#########################################################
sub OptionResponseAnalysis {
- my ($r,$resource,$resid,$ProblemData,$Students) = @_;
+ my ($r,$resource,$respid,$ProblemData,$Students) = @_;
my $PerformanceData =
&Apache::loncoursedata::get_response_data
- ($Students,$resource->{'symb'},$resid);
+ ($Students,$resource->{'symb'},$respid);
if (! defined($PerformanceData) ||
ref($PerformanceData) ne 'ARRAY' ) {
$r->print('<h2>'.
@@ -1491,9 +1519,10 @@
my $resptype = $partdata->{'ResponseTypes'}->[$i];
if ($resptype eq 'option' ){
# if ($resptype eq 'option' || $resptype eq 'radiobutton') {
- my $value =
- &Apache::lonnet::escape($res->{'symb'}.':'.$part.
- ':'.$respid.':'.$resptype);
+ my $value = &make_target_id({symb=>$res->{'symb'},
+ part=>$part,
+ respid=>$respid,
+ resptype=>$resptype});
my $checked = '';
if ($ENV{'form.problemchoice'} eq $value) {
$checked = 'checked ';
@@ -1533,9 +1562,14 @@
#########################################################
sub get_problem_symb {
my $problemstring = shift();
- my ($symb,$partid,$resid,$resptype) =
- ($problemstring=~ /^(.*):([^:]*):([^:]*):([^:]*)$/);
- return ($symb,$partid,$resid,$resptype);
+ &Apache::lonnet::logthis('problemstring = '.$problemstring);
+ my ($symb,$partid,$respid,$resptype) = split(':',$problemstring);
+ &Apache::lonnet::logthis("\n".
+ join(" --- \n",split(':',$problemstring)));
+ return ({ symb => $symb,
+ part => $partid,
+ respid => $respid,
+ type => $resptype } );
}
sub get_resource_from_symb {
@@ -1550,6 +1584,100 @@
return undef;
}
+sub get_prev_curr_next {
+ my ($target) = @_;
+ while(my($k,$v) = each(%$target)) {
+ &Apache::lonnet::logthis($k.' = '.$v);
+ }
+ #
+ # Build an array with the data we need to search through
+ my @Resource;
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ foreach my $res (@{$seq->{'contents'}}) {
+ next if ($res->{'type'} ne 'assessment');
+ foreach my $part (@{$res->{'parts'}}) {
+ my $partdata = $res->{'partdata'}->{$part};
+ for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
+ my $respid = $partdata->{'ResponseIds'}->[$i];
+ my $resptype = $partdata->{'ResponseTypes'}->[$i];
+ next if ($resptype ne 'option');
+ push (@Resource,
+ { symb => $res->{symb},
+ part => $part,
+ respid => $partdata->{'ResponseIds'}->[$i],
+ resource => $res,
+ resptype => $resptype
+ } );
+ }
+ }
+ }
+ }
+ #
+ &Apache::lonnet::logthis('size of @Resource = '.scalar(@Resource));
+ #
+ # Get the index of the current situation
+ my $curr_idx;
+ for ($curr_idx=0;$curr_idx<$#Resource;$curr_idx++) {
+ my $curr_item = $Resource[$curr_idx];
+ &Apache::lonnet::logthis('-----------------------------------');
+ while(my($k,$v) = each(%$curr_item)) {
+ &Apache::lonnet::logthis($k.' = '.$v);
+ }
+ last if ($curr_item->{'symb'} eq $target->{'symb'} &&
+ $curr_item->{'part'} eq $target->{'part'} &&
+ $curr_item->{'respid'} eq $target->{'respid'} &&
+ $curr_item->{'resptype'} eq $target->{'resptype'});
+ }
+ my $curr_item = $Resource[$curr_idx];
+ if ($curr_item->{'symb'} ne $target->{'symb'} ||
+ $curr_item->{'part'} ne $target->{'part'} ||
+ $curr_item->{'respid'} ne $target->{'respid'} ||
+ $curr_item->{'resptype'} ne $target->{'resptype'}){
+ # bogus symb - return nothing
+ &Apache::lonnet::logthis('bailing out');
+ return (undef,undef,undef);
+ }
+ #
+ # Now just pick up the data we need
+ my ($prev,$curr,$next);
+ if ($curr_idx == 0) {
+ $prev = undef;
+ $curr = $Resource[$curr_idx ];
+ $next = $Resource[$curr_idx+1];
+ } elsif ($curr_idx == $#Resource) {
+ $prev = $Resource[$curr_idx-1];
+ $curr = $Resource[$curr_idx ];
+ $next = undef;
+ } else {
+ $prev = $Resource[$curr_idx-1];
+ $curr = $Resource[$curr_idx ];
+ $next = $Resource[$curr_idx+1];
+ }
+ return ($prev,$curr,$next);
+}
+
+sub make_target_id {
+ my ($target) = @_;
+ my $id = &Apache::lonnet::escape($target->{'symb'}).':'.
+ &Apache::lonnet::escape($target->{'part'}).':'.
+ &Apache::lonnet::escape($target->{'respid'}).':'.
+ &Apache::lonnet::escape($target->{'resptype'});
+ return $id;
+}
+
+sub get_target_from_id {
+ my ($id) = @_;
+ &Apache::lonnet::logthis('id = '.$id);
+ my ($symb,$part,$respid,$resptype) = split(':',$id);
+ &Apache::lonnet::logthis('get_target_from_id:symb='.$symb);
+ &Apache::lonnet::logthis('get_target_from_id:symb='.$part);
+ &Apache::lonnet::logthis('get_target_from_id:symb='.$respid);
+ &Apache::lonnet::logthis('get_target_from_id:symb='.$resptype);
+ return ({ symb =>&Apache::lonnet::unescape($symb),
+ part =>&Apache::lonnet::unescape($part),
+ respid =>&Apache::lonnet::unescape($respid),
+ resptype =>&Apache::lonnet::unescape($resptype)});
+}
#########################################################
#########################################################
--matthew1074267220--