');
+ $r->print(&OptionResponseProblemSelector());
}
-
- $Str .= &IntervalOptions($cache{'Interval'});
- $Str .= &OptionResponseTable($cache{'OptionResponses'});
-
- untie(%cache);
-
- return $Str;
}
-sub BuildAnalyzePage {
- my ($cacheDB, $students, $courseID)=@_;
-
- my $Str = '';
- my %cache;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- $Str .= 'Unable to tie database.';
- return $Str;
- }
-
- my $uri = $cache{'AnalyzeURI'},
- my $part = $cache{'AnalyzePart'},
- my $problem = $cache{'AnalyzeProblem'},
- my $title = $cache{'AnalyzeTitle'},
- my $interval = $cache{'Interval'},
-
- my %ConceptData;
- $ConceptData{"Interval"} = $interval;
-
- #Initialize the option response true answers
- my ($Concepts, $foil_to_concept, $answer) = &InitAnalysis($uri, $part,
- $problem,
- $students->[0],
- $courseID);
-
- #compute the intervals
- &Interval($part, $problem, $interval, $Concepts, \%ConceptData);
-
- $title =~ s/\ /"_"/eg;
- $Str .= ' '.$uri.'';
-
- #Java script Progress window
- &Create_PrgWin();
- &Update_PrgWin("Starting-to-analyze-problem");
- for (my $index=0;$index<(scalar @$students);$index++) {
- &Update_PrgWin($index);
- &OpStatus($problem, $students->[$index], $courseID, $answer);
- }
- &Close_PrgWin();
-
- $Str .= ' ';
- for (my $k=0; $k<$interval; $k++ ) {
- $Str .= &DrawGraph($k, $title, $Concepts, \%ConceptData);
- }
- for (my $k=0; $k<$interval; $k++ ) {
- $Str .= &DrawTable($k, $Concepts, \%ConceptData);
- }
-#$Apache::lonxml::debug=1;
-#&Apache::lonhomework::showhash(%ConceptData);
-#$Apache::lonxml::debug=0;
- my $Answ=&Apache::lonnet::ssi($uri);
- $Str .= ' Here you can see the Problem: '.$Answ;
- untie(%cache);
-
- return $Str;
+#########################################################
+#########################################################
+##
+## Misc interface routines use by analysis code
+##
+#########################################################
+#########################################################
+sub build_foil_index {
+ my ($ORdata) = @_;
+ my @Foils = sort(keys(%{$ORdata->{'Foiltext'}}));
+ my %Row_Label;
+ foreach my $foilid (@Foils) {
+ my $value = $ORdata->{'Foiltext'}->{$foilid};
+ $Row_Label{$foilid} = $ORdata->{'Foiltext'}->{$foilid};
+ }
+ #
+ # Build up the table of row labels.
+ my $table = '
'."\n";
+ $table .= '
'.&mt('Foil Number').'
'.
+ '
'.&mt('Foil Text')."
\n";
+ my $index = 1;
+ foreach my $foilid (@Foils) {
+ $table .= '
'.$index.'
'.
+ '
'.$Row_Label{$foilid}."
\n";
+ } continue {
+ $index++;
+ }
+ $table .= "
\n";
+ return ($table,@Foils);
}
-#---- Problem Analysis Web Page ----------------------------------------------
-
-sub IntervalOptions {
- my ($selectedInterval)=@_;
-
- my $interval = 1;
- for(my $n=1; $n<=7; $n++) {
- if($selectedInterval == $n) {
- $interval = $n;
+#########################################################
+#########################################################
+##
+## Tries Analysis
+##
+#########################################################
+#########################################################
+sub tries_analysis {
+ my ($PerformanceData,$ORdata) = @_;
+ my $mintries = 1;
+ my $maxtries = $ENV{'form.NumPlots'};
+ my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
+ $mintries,$maxtries);
+ my ($table,@Foils) = &build_foil_index($ORdata);
+ #
+ # Compute the data neccessary to make the plots
+ my @PlotData;
+ my @CumulativePlotData;
+ foreach my $foilid (@Foils) {
+ for (my $i=$mintries;$i<=$maxtries;$i++) {
+ #
+ # Gather the per-attempt data
+ push (@{$PlotData[$i]->{'good'}},
+ $ResponseData{$foilid}->[$i]->{'percent_corr'});
+ push (@{$PlotData[$i]->{'bad'}},
+ 100-$ResponseData{$foilid}->[$i]->{'percent_corr'});
+ #
+ # Someday we may need the cumulative data and I think
+ # this is a neat way of computing it as we go along.
+ push (@{$CumulativePlotData[$i]->{'good'}},
+ $CumulativePlotData[-1]->{'good'}+
+ $ResponseData{$foilid}->[$i]->{'correct'});
+ push (@{$CumulativePlotData[$i]->{'bad'}},
+ $CumulativePlotData[-1]->{'bad'}+
+ $ResponseData{$foilid}->[$i]->{'incorrect'});
}
}
-
- my $Ptr = ' Select number of intervals'."\n".
- ''."\n";
+ #
+ # Should this be something the user can set? Too many dialogs!
+ my $plots_per_row = 2;
+ while (my $plotlink = shift(@Plots)) {
+ $table .= '
'.$plotlink.'
';
+ for (my $i=1;$i<$plots_per_row;$i++) {
+ if ($plotlink = shift(@Plots)) {
+ $table .= '
'.$plotlink.'
';
+ } else {
+ $table .= '
';
+ }
+ }
+ $table .= "
\n";
+ }
+ $table .= "\n";
+ return ($table);
+}
- return $Ptr;
+sub analyze_option_data_by_tries {
+ my ($PerformanceData,$mintries,$maxtries) = @_;
+ my %Trydata;
+ $mintries = 1 if (! defined($mintries) || $mintries < 1);
+ $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
+ foreach my $row (@$PerformanceData) {
+ next if (! defined($row));
+ my ($grading,$submission,$time,$tries) = @$row;
+ my @Foilgrades = split('&',$grading);
+ my @Foilsubs = split('&',$submission);
+ for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
+ if ($tries == $numtries) {
+ foreach my $foilgrade (@Foilgrades) {
+ my ($foilid,$correct) = split('=',$foilgrade);
+ if ($correct) {
+ $Trydata{$foilid}->[$numtries]->{'correct'}++;
+ } else {
+ $Trydata{$foilid}->[$numtries]->{'incorrect'}++;
+ }
+ }
+ }
+ }
+ }
+ foreach my $foilid (keys(%Trydata)) {
+ foreach my $tryhash (@{$Trydata{$foilid}}) {
+ next if ((! exists($tryhash->{'correct'}) &&
+ ! exists($tryhash->{'incorrect'})) ||
+ ($tryhash->{'correct'} < 1 &&
+ $tryhash->{'incorrect'} < 1));
+ $tryhash->{'total'} = $tryhash->{'correct'} +
+ $tryhash->{'incorrect'};
+ $tryhash->{'percent_corr'} = 100 *
+ ($tryhash->{'correct'} /
+ ($tryhash->{'correct'} + $tryhash->{'incorrect'})
+ );
+ }
+ }
+ return %Trydata;
}
-sub OptionResponseTable {
- my ($optionResponses)=@_;
- my $Str = '';
- $Str .= ' Option Response Problems in this course:'."\n";
- $Str .= '
'."\n";
- $Str .= "
\#
Problem Title
";
- $Str .= '
Resource
Analysis
'."\n";
-
- my $number=1;
- foreach (split(':::', $optionResponses)) {
- my ($uri,$title,$part,$problem)=split('::',$_);
- my $Temp = ''.$title.'';
- $Str .= '
';
- $Str .= '
'.$number.'
';
- $Str .= '
'.$Temp.'
';
- $Str .= '
'.$uri.'
';
- $Str .= '
'."\n";
- $number++;
+#########################################################
+#########################################################
+##
+## Time Analysis
+##
+#########################################################
+#########################################################
+sub time_analysis {
+ my ($PerformanceData,$ORdata) = @_;
+ my $num_plots = $ENV{'form.NumPlots'};
+ my ($table,@Foils) = &build_foil_index($ORdata);
+ my ($begin_index,$end_index);
+ my $num_data = scalar(@$PerformanceData)-1;
+ my $percent = sprintf('%2f',100/$num_plots);
+ for (my $i=0;$i<$num_plots;$i++) {
+ $begin_index = $i*int($num_data/$num_plots);
+ $end_index = ($i+1)*int($num_data/$num_plots);
+ my $lownum = sprintf('%2.1f',$i*$percent);
+ $lownum =~ s/(\.0)$//;
+ my $highnum = sprintf('%2.1f',($i+1)*$percent);
+ $highnum =~ s/(\.0)$//;
+ my ($plothtml,$starttime,$endtime,$data) =
+ &analyze_option_data_by_time($PerformanceData,
+ $begin_index,$end_index,
+ $lownum.'% to '.$highnum.'% of submissions',
+ @Foils);
+ $table.=$plothtml;
}
- $Str .= '
'."\n";
+ return $table;
+}
- return $Str;
+sub analyze_option_data_by_time {
+ my ($PerformanceData,$begin_index,$end_index,$description,@Foils) = @_;
+ my %TimeData;
+ #
+ # Get the start and end times for this segment of the plot
+ my $starttime = $PerformanceData->[$begin_index]->[2];
+ my $endtime = $PerformanceData->[$end_index ]->[2];
+ #
+ # Compute the number getting the foils correct or incorrects
+ for (my $i=$begin_index;$i<=$end_index;$i++) {
+ my $row = $PerformanceData->[$i];
+ next if (! defined($row));
+ my ($grading,$submission,$time,$tries) = @$row;
+ my @Foilgrades = split('&',$grading);
+ my @Foilsubs = split('&',$submission);
+ foreach my $foilgrade (@Foilgrades) {
+ my ($foilid,$correct) = split('=',$foilgrade);
+ if ($correct) {
+ $TimeData{$foilid}->{'correct'}++;
+ } else {
+ $TimeData{$foilid}->{'incorrect'}++;
+ }
+ }
+ }
+ #
+ # Compute the total and percent correct
+ my @Plotdata1;
+ my @Plotdata2;
+ foreach my $foilid (@Foils) {
+ if (! exists($TimeData{$foilid}->{'correct'})) {
+ $TimeData{$foilid}->{'correct'} = 0;
+ }
+ if (! exists($TimeData{$foilid}->{'incorrect'})) {
+ $TimeData{$foilid}->{'incorrect'} = 0;
+ }
+ $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
+ $TimeData{$foilid}->{'incorrect'};
+ $TimeData{$foilid}->{'percent_corr'} = 100 *
+ $TimeData{$foilid}->{'correct'} /
+ $TimeData{$foilid}->{'total'};
+ push (@Plotdata1, $TimeData{$foilid}->{'percent_corr'});
+ push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
+ }
+ #
+ # Create the plot
+ my $graphlink = &Apache::loncommon::DrawGraph
+ ($description,#'Time Interval Analysis',
+ 'Foil Number',
+ 'Percent Correct / Incorrect',
+ 100,
+ \@Plotdata1,\@Plotdata2);
+ $graphlink .= " \n".
+ "Start Time: ".localtime($starttime)." \n".
+ "End Time: ".localtime($endtime)." \n";
+ #
+ return ($graphlink,$starttime,$endtime,\%TimeData);
}
-#---- END Problem Analysis Web Page ------------------------------------------
-#---- Analyze Web Page -------------------------------------------------------
-#restore the student submissions and finding the result
-sub OpStatus {
- my ($problem, $student, $courseID, $ConceptData, $foil_to_concept,
- $Answer)=@_;
- my ($username,$userdomain)=split(/':'/,$student);
- my $code='U';
- my %reshash=&Apache::lonnet::restore($problem, $courseID, $userdomain,
- $username);
- my @True = ();
- my @False = ();
- my $flag=0;
- if ($reshash{'version'}) {
- my $tries=0;
- &Apache::lonhomework::showhash(%$Answer);
- for (my $version=1;$version<=$reshash{'version'};$version++) {
- my $time=$reshash{"$version:timestamp"};
-
- foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
- if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
- my $Id1 = $1; my $Id2 = $2;
- #check if this is a repeat submission, if so skip it
- if ($reshash{"$version:resource.$Id1.previous"}) { next; }
- #if no solved this wasn't a real submission, ignore it
- if (!defined($reshash{"$version:resource.$Id1.solved"})) {
- &Apache::lonxml::debug("skipping ");
- next;
- }
- my $Resp = $reshash{"$version:$key"};
- my %submission=&Apache::lonnet::str2hash($Resp);
- foreach (keys %submission) {
- my $Ansr = $Answer->{"$Id1.$Id2.foil.value.$_"};
- if ($submission{$_}) {
- if ($submission{$_} eq $Ansr) {
- &Decide("true", $foil_to_concept->{$_},
- $time, $ConceptData);
- } else {
- &Decide("false", $foil_to_concept->{$_},
- $time, $ConceptData);}
- }
- }
- }
- }
- }
- }
-}
-
-sub DrawGraph {
- my ($k,$Src,$Concepts,$ConceptData)=@_;
- my $Max=0;
- my @data1;
- my @data2;
-
- # Adjust Data and find the Max
- for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
- my $tmp=$Concepts->[$n];
- $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
- $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
- my $Sum=$data1[$n]+$data2[$n];
- if($Max < $Sum) {
- $Max=$Sum;
- }
- }
- for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
- if ($data1[$n]+$data2[$n]<$Max) {
- $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
- }
- }
- my $P_No = (scalar @data1);
-
- if($Max > 1) {
- $Max += (10 - $Max % 10);
- $Max = int($Max);
- } else {
- $Max = 1;
- }
- my $Titr=($ConceptData->{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
-# $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
- my $GData = '';
- $GData = $Titr.'&Concepts&Answers&'.$Max.'&'.$P_No.'&';
- $GData .= (join(',',@data1)).'&'.(join(',',@data2));
-
- return '';
-}
-
-sub DrawTable {
- my ($k,$Concepts,$ConceptData)=@_;
- my $Max=0;
- my @data1;
- my @data2;
- my $Correct=0;
- my $Wrong=0;
- for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
- my $tmp=$Concepts->[$n];
- $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
- $Correct+=$data1[$n];
- $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
- $Wrong+=$data2[$n];
- my $Sum=$data1[$n]+$data2[$n];
- if($Max < $Sum) {
- $Max=$Sum;
- }
- }
- for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
- if ($data1[$n]+$data2[$n]<$Max) {
- $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
- }
+#########################################################
+#########################################################
+##
+## Interface
+##
+#########################################################
+#########################################################
+sub CreateInterface {
+ ##
+ ## Environment variable initialization
+ if (! exists$ENV{'form.AnalyzeBy'}) {
+ $ENV{'form.AnalyzeBy'} = 'Tries';
}
- my $P_No = (scalar @data1);
+ ##
+ ## Build the menu
my $Str = '';
-# $Str .= ' From: ['.localtime($ConceptData->{'Int.'.($k-1)});
-# $Str .= '] To: ['.localtime($ConceptData->{"Int.$k"}).']';
- $Str .= "\n".'