--- loncom/interface/statistics/lonproblemanalysis.pm 2003/09/29 21:13:23 1.24
+++ loncom/interface/statistics/lonproblemanalysis.pm 2003/10/17 22:05:45 1.42
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonproblemanalysis.pm,v 1.24 2003/09/29 21:13:23 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.42 2003/10/17 22:05:45 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -24,82 +24,744 @@
#
# http://www.lon-capa.org/
#
-# (Navigate problems for statistical reports
-# YEAR=2002
-# 5/12,7/26,9/7,11/22 Behrouz Minaei
-#
-###
package Apache::lonproblemanalysis;
use strict;
use Apache::lonnet();
+use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::loncoursedata();
use Apache::lonstatistics;
use Apache::lonlocal;
+use HTML::Entities();
+use Time::Local();
+
+my $plotcolors = ['#33ff00',
+ '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
+ '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
+ ];
sub BuildProblemAnalysisPage {
my ($r,$c)=@_;
$r->print('
'.&mt('Option Response Problem Analysis').'
');
- if (exists($ENV{'form.problemchoice'})) {
- # This is me getting around my own cleverness:
- &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
- undef);
+ $r->print(&CreateInterface());
+ #
+ my @Students = @Apache::lonstatistics::Students;
+ #
+ if (exists($ENV{'form.ClearCache'}) ||
+ exists($ENV{'form.updatecaches'}) ||
+ (exists($ENV{'form.firstanalysis'}) &&
+ $ENV{'form.firstanalysis'} ne 'no')) {
+ &Apache::lonstatistics::Gather_Full_Student_Data($r);
+ }
+ if (! exists($ENV{'form.firstanalysis'})) {
+ $r->print('');
+ } else {
+ $r->print('');
+ }
+ $r->rflush();
+ if (exists($ENV{'form.problemchoice'}) &&
+ ! exists($ENV{'form.SelectAnother'})) {
+ $r->print('');
+ $r->print(' 'x5);
+ $r->print('');
+ $r->print(' 'x5);
+ $r->print('');
+ $r->print(' 'x5);
+ $r->print('');
+ $r->print('');
+ $r->print(' 'x5);
#
- my ($symb,$id) = &get_problem_symb(
+ $r->print('');
+ #
+ my ($symb,$part,$resid) = &get_problem_symb(
&Apache::lonnet::unescape($ENV{'form.problemchoice'})
);
- $r->print('');
+ #
my $resource = &get_resource_from_symb($symb);
if (defined($resource)) {
+ $r->print('
'.$resource->{'src'}.'
');
+ my %Data = &get_problem_data($resource->{'src'});
+ my $ORdata = $Data{$part.'.'.$resid};
+ ##
+ ## Render the problem
+ my $base;
+ ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
+ $base = "http://".$ENV{'SERVER_NAME'}.$base;
+ my $rendered_problem =
+ &Apache::lonnet::ssi_body($resource->{'src'});
+ $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g;
$r->print('
'.
- # Oh this is dumb! Need to rewrite relative links
- # otherwise images (for example) will not show.
- &Apache::lonnet::ssi_body($resource->{'src'}).
+ ''.
+ $rendered_problem.
'
');
+ ##
+ ## Analyze the problem
+ my $PerformanceData =
+ &Apache::loncoursedata::get_optionresponse_data
+ (\@Students,$symb,$resid);
+ if (defined($PerformanceData) &&
+ ref($PerformanceData) eq 'ARRAY') {
+ if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
+ my $analysis_html = &tries_analysis($PerformanceData,
+ $ORdata);
+ $r->print($analysis_html);
+ } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
+ my $analysis_html = &time_analysis($PerformanceData,
+ $ORdata);
+ $r->print($analysis_html);
+ } else {
+ $r->print('
'.
+ &mt('The analysis you have selected is '.
+ 'not supported at this time').
+ '
');
+ }
+ } else {
+ $r->print('
'.
+ &mt('There is no student data for this problem.').
+ '
');
+ }
} else {
$r->print('resource is undefined');
}
- $r->print('');
- $r->print("render problem\n");
- $r->print("image tag for plot\n");
- $r->print("plot key\n");
- $r->print('');
- $r->print("
');
+ $r->print(&OptionResponseProblemSelector());
}
- $r->print('');
- $r->print(&CreateInterface());
- if (! exists($ENV{'form.analysisfirstcall'})) {
- return;
+}
+
+#########################################################
+#########################################################
+##
+## Misc interface routines use by analysis code
+##
+#########################################################
+#########################################################
+sub build_foil_index {
+ my ($ORdata) = @_;
+ return if (! exists($ORdata->{'Foils'}));
+ my %Foildata = %{$ORdata->{'Foils'}};
+ my @Foils = sort(keys(%Foildata));
+ my %Concepts;
+ foreach my $foilid (@Foils) {
+ push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}},
+ $foilid);
+ }
+ undef(@Foils);
+ # Having gathered the concept information in a hash, we now translate it
+ # into an array because we need to be consistent about order.
+ # Also put the foils in order, too.
+ my $sortfunction = sub {
+ my %Numbers = (one => 1,
+ two => 2,
+ three => 3,
+ four => 4,
+ five => 5,
+ six => 6,
+ seven => 7,
+ eight => 8,
+ nine => 9,
+ ten => 10,);
+ my $a1 = $a;
+ my $b1 = $b;
+ if (exists($Numbers{lc($a)})) {
+ $a1 = $Numbers{lc($a)};
+ }
+ if (exists($Numbers{lc($b)})) {
+ $b1 = $Numbers{lc($b)};
+ }
+ $a1 cmp $b1;
+ };
+ my @Concepts;
+ foreach my $concept (sort $sortfunction (keys(%Concepts))) {
+ push(@Concepts,{ name => $concept,
+ foils => [@{$Concepts{$concept}}]});
+ push(@Foils,(@{$Concepts{$concept}}));
+ }
+ #
+ # Build up the table of row labels.
+ my $table = '
'."\n";
+ if (@Concepts > 1) {
+ $table .= '
'.
+ '
'.&mt('Concept Number').'
'.
+ '
'.&mt('Concept').'
'.
+ '
'.&mt('Foil Number').'
'.
+ '
'.&mt('Foil Name').'
'.
+ '
'.&mt('Foil Text').'
'.
+ '
'.&mt('Correct Value').'
'.
+ "
\n";
+ } else {
+ $table .= '
'.
+ '
'.&mt('Foil Number').'
'.
+ '
'.&mt('Foil Name').'
'.
+ '
'.&mt('Foil Text').'
'.
+ '
'.&mt('Correct Value').'
'.
+ "
\n";
+ }
+ my $conceptindex = 1;
+ my $foilindex = 1;
+ foreach my $concept (@Concepts) {
+ my @FoilsInConcept = @{$concept->{'foils'}};
+ my $firstfoil = shift(@FoilsInConcept);
+ if (@Concepts > 1) {
+ $table .= '
'.
+ '
'.$conceptindex.'
'.
+ '
'.$concept->{'name'}.'
'.
+ '
'.$foilindex++.'
'.
+ '
'.$Foildata{$firstfoil}->{'name'}.'
'.
+ '
'.$Foildata{$firstfoil}->{'text'}.'
'.
+ '
'.$Foildata{$firstfoil}->{'value'}.'
'.
+ "
\n";
+ } else {
+ $table .= '
'.
+ '
'.$foilindex++.'
'.
+ '
'.$Foildata{$firstfoil}->{'name'}.'
'.
+ '
'.$Foildata{$firstfoil}->{'text'}.'
'.
+ '
'.$Foildata{$firstfoil}->{'value'}.'
'.
+ "
\n";
+ }
+ foreach my $foilid (@FoilsInConcept) {
+ if (@Concepts > 1) {
+ $table .= '
'.
+ '
'.
+ '
'.
+ '
'.$foilindex.'
'.
+ '
'.$Foildata{$foilid}->{'name'}.'
'.
+ '
'.$Foildata{$foilid}->{'text'}.'
'.
+ '
'.$Foildata{$foilid}->{'value'}.'
'.
+ "
\n";
+ } else {
+ $table .= '
'.
+ '
'.$foilindex.'
'.
+ '
'.$Foildata{$foilid}->{'name'}.'
'.
+ '
'.$Foildata{$foilid}->{'text'}.'
'.
+ '
'.$Foildata{$foilid}->{'value'}.'
'.
+ "
\n";
+ }
+ } continue {
+ $foilindex++;
+ }
+ } continue {
+ $conceptindex++;
}
- # Okay, they asked for data, so make sure we get the latest data.
- &Apache::lonnet::logthis('got here for some reason');
-# &Apache::lonstatistics::Gather_Full_Student_Data($r);
- $r->print(&OptionResponseProblemSelector());
+ $table .= "
\n";
+ #
+ # Build option index with color stuff
+ return ($table,\@Foils,\@Concepts);
}
-sub get_problem_symb {
- my $problemstring = shift();
- my ($symb,$id) = ($problemstring=~ /^(.*):([^:]*)$/);
- return ($symb,$id);
+sub build_option_index {
+ my ($ORdata)= @_;
+ my $table = "
\n";
+ my $optionindex = 0;
+ my @Rows;
+ foreach my $option (&mt('correct option chosen'),@{$ORdata->{'Options'}}) {
+ push (@Rows,
+ '