[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm lonstatistics.pm /interface/statistics lonpercentage.pm lonproblemstatistics.pm doc/loncapafiles loncapafiles.lpml

stredwic lon-capa-cvs@mail.lon-capa.org
Fri, 30 Aug 2002 15:35:08 -0000


This is a MIME encoded message

--stredwic1030721708
Content-Type: text/plain

stredwic		Fri Aug 30 11:35:08 2002 EDT

  Added files:                 
    /loncom/interface/statistics	lonpercentage.pm 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom/interface	lonhtmlcommon.pm lonstatistics.pm 
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  Fixed an error for map selection in problem statistics.  Added a new 
  module that will display a graph of percentage correctness for
  a problem or series of problems based on input.  It doesn't quite
  look correct yet, because of graph.gif.  I will have to edit graph.gif
  in order to get ranges for the x axis etc.  This was also an 
  experiment to see multiple dependent selections.  Will probably do
  that with student assessment next, but with students.
  
  
--stredwic1030721708
Content-Type: text/plain
Content-Disposition: attachment; filename="stredwic-20020830113508.txt"

Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.168 doc/loncapafiles/loncapafiles.lpml:1.169
--- doc/loncapafiles/loncapafiles.lpml:1.168	Wed Aug 28 15:42:48 2002
+++ doc/loncapafiles/loncapafiles.lpml	Fri Aug 30 11:35:07 2002
@@ -3,7 +3,7 @@
 <!-- loncapafiles.lpml -->
 <!-- Scott Harrison -->
 
-<!-- $Id: loncapafiles.lpml,v 1.168 2002/08/28 19:42:48 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.169 2002/08/30 15:35:07 stredwic Exp $ -->
 
 <!--
 
@@ -1723,6 +1723,16 @@
 <categoryname>handler</categoryname>
 <description>
 The module that generate the html for the Problem Statistics web pages.
+</description>
+<status>works/unverified</status>
+</file>
+<file>
+<source>loncom/interface/statistics/lonpercentage.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/lonpercentage.pm
+</target>
+<categoryname>handler</categoryname>
+<description>
+The module that generate the html for the Percentage graph web pages.
 </description>
 <status>works/unverified</status>
 </file>
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.8 loncom/interface/lonhtmlcommon.pm:1.9
--- loncom/interface/lonhtmlcommon.pm:1.8	Wed Aug 21 13:18:08 2002
+++ loncom/interface/lonhtmlcommon.pm	Fri Aug 30 11:35:08 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.8 2002/08/21 17:18:08 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.9 2002/08/30 15:35:08 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -79,6 +79,76 @@
         $Str .= ' selected';
     }
     $Str .= '>All Maps</option>'."\n";
+
+    $Str .= '</select>'."\n";
+
+    return $Str;
+}
+
+sub ProblemOptions {
+    my ($data, $page, $map, $formName)=@_;
+    my $Str = '';
+    $Str .= '<select name="';
+    $Str .= (($page)?$page:'').'ProblemSelect"';
+    if($formName) {
+        $Str .= ' onchange="document.'.$formName.'.submit()"';
+    }
+    $Str .= '>'."\n";
+
+    my $selected = 0;
+    foreach my $sequence (split(':',$data->{'orderedSequences'})) {
+	if($data->{$sequence.':title'} eq $map || $map eq 'All Maps') {
+	    foreach my $problem (split(':', $data->{$sequence.':problems'})) {
+		$Str .= '<option';
+		if($data->{$page.'ProblemSelect'} eq 
+		   $data->{$problem.':title'}) {
+		    $Str .= ' selected';
+		    $selected = 1;
+		}
+		$Str .= '>'.$data->{$problem.':title'}.'</option>'."\n";
+	    }
+	}
+    }
+    $Str .= '<option';
+    if(!$selected) {
+        $Str .= ' selected';
+    }
+    $Str .= '>All Problems</option>'."\n";
+
+    $Str .= '</select>'."\n";
+
+    return $Str;
+}
+
+sub PartOptions {
+    my ($data, $page, $parts, $formName)=@_;
+    my $Str = '';
+
+    if(!defined($parts)) {
+	return '';
+    }
+
+    $Str .= '<select name="';
+    $Str .= (($page)?$page:'').'PartSelect"';
+    if($formName) {
+        $Str .= ' onchange="document.'.$formName.'.submit()"';
+    }
+    $Str .= '>'."\n";
+
+    my $selected = 0;
+    foreach my $part (@$parts) {
+	$Str .= '<option';
+	if($data->{$page.'PartSelect'} eq $part) {
+	    $Str .= ' selected';
+	    $selected = 1;
+	}
+	$Str .= '>'.$part.'</option>'."\n";	     
+    }
+    $Str .= '<option';
+    if(!$selected) {
+        $Str .= ' selected';
+    }
+    $Str .= '>All Parts</option>'."\n";
 
     $Str .= '</select>'."\n";
 
Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.48 loncom/interface/lonstatistics.pm:1.49
--- loncom/interface/lonstatistics.pm:1.48	Wed Aug 28 18:42:15 2002
+++ loncom/interface/lonstatistics.pm	Fri Aug 30 11:35:08 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.48 2002/08/28 22:42:15 stredwic Exp $
+# $Id: lonstatistics.pm,v 1.49 2002/08/30 15:35:08 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,6 +47,7 @@
 use Apache::lonproblemanalysis;
 use Apache::lonproblemstatistics;
 use Apache::lonstudentassessment;
+use Apache::lonpercentage;
 use HTML::TokeParser;
 use GDBM_File;
 
@@ -84,6 +85,10 @@
     &CheckFormElement($cache, 'download', 'download', 'false');
     &CheckFormElement($cache, 'StatisticsMaps', 
                       'StatisticsMaps', 'All Maps');
+    &CheckFormElement($cache, 'StatisticsProblemSelect',
+		      'StatisticsProblemSelect', 'All Problems');
+    &CheckFormElement($cache, 'StatisticsPartSelect',
+		      'StatisticsPartSelect', 'All Parts');
     if(defined($ENV{'form.Section'})) {
         my @sectionsSelected = (ref($ENV{'form.Section'}) ?
                                @{$ENV{'form.Section'}} :
@@ -122,7 +127,8 @@
                       'ProblemStatisticsAscend', 'Ascending');
     &CheckFormElement($cache, 'ProblemStatisticsSort',
                       'ProblemStatisticsSort', 'Homework Sets Order');
-    &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 'Hide Legend');
+    &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend', 
+		      'Hide Legend');
     &CheckFormElement($cache, 'SortProblems', 'SortProblems', 
                       'Sort Within Sequence');
 
@@ -507,6 +513,7 @@
     my %reports = ('classlist'          => 'Class list',
                    'problem_statistics' => 'Problem Statistics',
                    'student_assessment' => 'Student Assessment',
+		   'percentage'         => 'Percentage Graphs',
 #                   'activitylog'        => 'Activity Log',
                    'reportSelected'     => 'Class list');
 
@@ -586,6 +593,9 @@
     } elsif($GoToPage eq 'Class list') {
         &BuildClasslist($cacheDB, $students, \@studentInformation,
                         \@headings, $r);
+    } elsif($GoToPage eq 'Percentage Graphs') {
+	&Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
+						     $courseID, $c, $r);
     }
 
     $r->print('</form>'."\n");
Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.30 loncom/interface/statistics/lonproblemstatistics.pm:1.31
--- loncom/interface/statistics/lonproblemstatistics.pm:1.30	Thu Aug 15 10:15:20 2002
+++ loncom/interface/statistics/lonproblemstatistics.pm	Fri Aug 30 11:35:08 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonproblemstatistics.pm,v 1.30 2002/08/15 14:15:20 stredwic Exp $
+# $Id: lonproblemstatistics.pm,v 1.31 2002/08/30 15:35:08 stredwic Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -173,15 +173,15 @@
     $Ptr .= '<table border="0" cellspacing="5"><tbody>';
     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
     $Ptr .= '<td align="left">';
-    $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
+    $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'Statistics',
                                                'Statistics');
     $Ptr .= '</td></tr>'."\n";
     $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
     $Ptr .= '<td align="left">'."\n";
     $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
-                                            $cache{'ProblemStatisticsAscend'}, 
-                                            'ProblemStatistics',
-                                            'Statistics');
+                                           $cache{'ProblemStatisticsAscend'}, 
+                                           'ProblemStatistics',
+                                           'Statistics');
     $Ptr .= '</td></tr>'."\n";
     $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
     $Ptr .= '</td>'."\n";
@@ -507,8 +507,8 @@
     $Ptr .= '<b>Dis.F.</b></td>';
     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
     $Ptr .= 'problem according to a Criterion<br>';
-    $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
-    $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
+    $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
+    $Ptr .= 'and %27 Lower Students]</b><br>';
     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';

Index: loncom/interface/statistics/lonpercentage.pm
+++ loncom/interface/statistics/lonpercentage.pm
# The LearningOnline Network with CAPA
# (Publication Handler
#
# $Id: lonpercentage.pm,v 1.1 2002/08/30 15:35:08 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###

package Apache::lonpercentage;

use strict;
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;

#my $jr;

sub BuildPercentageGraph {
    my ($cacheDB, $students, $courseID, $c, $r)=@_;

    my %cache;
    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        $r->print('Unable to tie database.6');
        return;
    }

    $r->print(&CreateInterface(\%cache));
    $r->rflush();
    untie(%cache);

    my ($result) = &InitializeSelectedStudents($cacheDB, $students, 
					       $courseID, $c, $r);
    if($result ne 'OK' || $c->aborted()) {
        return;
    }

    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        $r->print('Unable to tie database.6');
        return;
    }

    my ($Ptr, $percentage) = &GraphData(\%cache, $students);
    $r->print($Ptr.'<br><br>');

    $r->print(&TableData(\%cache, $percentage));

    untie(%cache);

    return;
}

sub CreateInterface {
    my ($cache)=@_;

    my $Ptr = '';
    $Ptr .= '<table border="0" cellspacing="5"><tbody>';
    $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
    $Ptr .= '<td align="left">';
    $Ptr .= &Apache::lonhtmlcommon::MapOptions($cache, 'Statistics',
                                               'Statistics');
    $Ptr .= '</td>'."\n";

    my $sequence = $cache->{'StatisticsMaps'};
    if($sequence ne 'All Maps') {
	$Ptr .= '<td align="right">'."\n";
	$Ptr .= &Apache::lonhtmlcommon::ProblemOptions($cache,
						       'Statistics',
						       $sequence,
						       'Statistics');
	$Ptr .= '<td>'."\n";

	my $problem = $cache->{'StatisticsProblemSelect'};
	if($problem ne 'All Problems') {
	    my $parts = &GetParts($cache, $sequence, $problem);
	    if(scalar(@$parts) > 0) {
		$Ptr .= '<td align="right">'."\n";
		$Ptr .= &Apache::lonhtmlcommon::PartOptions($cache,
							'Statistics',
							$parts,
							'Statistics');
		$Ptr .= '</td>'."\n";
	    }
	}
    }

    $Ptr .= '</tr>'."\n";

    $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
    $Ptr .= '</td>'."\n";
    $Ptr .= '<td align="left">'."\n";
    my @sections = split(':',$cache->{'sectionList'});
    my @sectionsSelected = split(':',$cache->{'sectionsSelected'});
    $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
                                                          \@sectionsSelected,
                                                          'Statistics');
    $Ptr .= '</td></tr>'."\n";
    $Ptr .= '</table>';

    return $Ptr;
}

sub GetParts {
    my ($cache,$sequence,$problem)=@_;
    my @parts = ();

    foreach my $sequenceNumber (split(':',$cache->{'orderedSequences'})) {
	if($cache->{$sequenceNumber.':title'} eq $sequence) {
	    foreach my $problemNumber (split(':', 
				     $cache->{$sequenceNumber.':problems'})) {
		if($cache->{$problemNumber.':title'} eq $problem) {
		    @parts = split(':', 
		       $cache->{$sequenceNumber.':'.$problemNumber.':parts'});
		}
	    }
	}
    }
    
    return \@parts;
}

sub InitializeSelectedStudents {
    my ($cacheDB, $students, $courseID, $c, $r)=@_;
    my %cache;

    unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
        $r->print('Unable to tie database1.1.');
        return ('ERROR');
    }

    # Remove students who don't have the proper section.
    my @sectionsSelected = split(':',$cache{'sectionsSelected'});
    for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
        $studentIndex--) {
        my $value = $cache{$students->[$studentIndex].':section'};
        my $found = 0;
        foreach (@sectionsSelected) {
            if($_ eq 'none') {
                if($value eq '' || !defined($value) || $value eq ' ') {
                    $found = 1;
                    last;
                }
            } else {
                if($value eq $_) {
                    $found = 1;
                    last;
                }
            }
        }
        if($found == 0) {
            splice(@$students, $studentIndex, 1);
        }
    }

    untie(%cache);

    &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
							      'true',
							      $cacheDB,
							      'true', 
							      'true',
							      $courseID,
							      $r, $c);

    return ('OK');
}

sub GraphData {
    my ($cache,$students)=@_;

    my $sequenceSelected = $cache->{'StatisticsMaps'};
    my $problemSelected  = $cache->{'StatisticsProblemSelect'};
    my $partSelected     = $cache->{'StatisticsPartSelect'};

    my %percentages;
    my $Ptr = '';

    foreach(@$students) {
	my $totalCorrect = 0;
	my $totalProblems = 0;

	foreach my $sequence (split(':',$cache->{'orderedSequences'})) {
	    next if($cache->{$sequence.':title'} ne $sequenceSelected &&
		    $sequenceSelected ne 'All Maps');
	    foreach my $problem (split(':',$cache->{$sequence.':problems'})) {
		next if($cache->{$problem.':title'} ne $problemSelected &&
			$problemSelected ne 'All Problems' && 
			$sequenceSelected ne 'All Maps');
		foreach my $part (split(':',$cache->{$sequence.':'.$problem.
						     ':parts'})) {
		    next if($part ne $partSelected && 
			    $partSelected ne 'All Parts' &&
			    $problemSelected ne 'All Problems' && 
			    $sequenceSelected ne 'All Maps');
		    my $code = $cache->{$_.':'.$problem.':'.$part.':code'};
		    if($code eq '*' || $code eq '+') {
			$totalCorrect++;
			$totalProblems++;
		    } elsif($code ne 'x') {
			$totalProblems++;
		    }
		}
	    }
	}

	my $percent = sprintf("%d", ($totalProblems) ?
			      (($totalCorrect/$totalProblems)*100) : 0);
	if(defined($percentages{$percent})) {
	    $percentages{$percent} .= ':::'.$_;
	} else {
	    $percentages{$percent} = $_;
	}
    }

    my @percent = ();
    my @percentCount = ();
    my $max = 0;
    foreach my $key (sort(keys(%percentages))) {
	push(@percent, $key);
	my $count = scalar(split(':::', $percentages{$key}));
	if($count > $max) {
	    $max = $count;
	}
	push(@percentCount, $count);
    }

    my @GData = ('', 'Percentage', 'Number_of_Students', 
		 $max, scalar(@percent), 
                 join(',',@percent), join(',', @percentCount));

    $Ptr .= '</form>'."\n";
    $Ptr .= '<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData));
    $Ptr .= '" border="1" />';
    $Ptr .= '<form>'."\n";

    return ($Ptr, \%percentages);
}

sub TableData {
    my($cache,$percentage)=@_;
    my $Ptr;

    $Ptr .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
    $Ptr .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";

    $Ptr .= '<tr>'."\n";
    $Ptr .= '<td>Percent Correct</td><td>Students</td>';
    $Ptr .= '</tr>'."\n";

    my $alternate=0;
    foreach (sort(keys(%$percentage))) {
        if($alternate) {
            $Ptr .= '<tr bgcolor="#ffffe6">';
        } else {
            $Ptr .= '<tr bgcolor="#ffffc6">';
        }
        $alternate = ($alternate + 1) % 2;

	$Ptr .= '<td>'.$_.'</td><td>';

	foreach my $name (sort(split(':::', $percentage->{$_}))) {
	    $Ptr .= '<a href="/adm/statistics?reportSelected=';
	    $Ptr .= &Apache::lonnet::escape('Student Assessment');
	    $Ptr .= '&StudentAssessmentStudent=';
	    $Ptr .= &Apache::lonnet::escape($cache->{$name.':fullname'}).'">';
	    $Ptr .= $cache->{$name.':fullname'};
	    $Ptr .= '</a>,&nbsp&nbsp';
        }

	$Ptr .= '</td></tr>'."\n";
    }

    $Ptr .= '</tr>'."\n";
    $Ptr .= '</table></td></tr></table>'."\n";

    return $Ptr;
}

1;
__END__

--stredwic1030721708--