[LON-CAPA-cvs] cvs: loncom /interface/statistics lonstathelpers.pm lonstudentsubmissions.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Mon, 08 Nov 2004 15:14:52 -0000
matthew Mon Nov 8 10:14:52 2004 EDT
Modified files:
/loncom/interface/statistics lonstudentsubmissions.pm
lonstathelpers.pm
Log:
lonstathelpers: renamed &analyze_problem_as_student to &get_student_answer
as this is what it was doing. Added routine &analyze_problem_as_student
lonstudentsubmissions: Call get_student_answer instead of analyze_problem_as
_student.
Index: loncom/interface/statistics/lonstudentsubmissions.pm
diff -u loncom/interface/statistics/lonstudentsubmissions.pm:1.25 loncom/interface/statistics/lonstudentsubmissions.pm:1.26
--- loncom/interface/statistics/lonstudentsubmissions.pm:1.25 Fri Oct 8 12:40:54 2004
+++ loncom/interface/statistics/lonstudentsubmissions.pm Mon Nov 8 10:14:52 2004
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonstudentsubmissions.pm,v 1.25 2004/10/08 16:40:54 matthew Exp $
+# $Id: lonstudentsubmissions.pm,v 1.26 2004/11/08 15:14:52 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -383,7 +383,7 @@
#
my $correct = '';
if ($ENV{'form.correctans'} eq 'true') {
- $correct = &Apache::lonstathelpers::analyze_problem_as_student
+ $correct = &Apache::lonstathelpers::get_student_answer
($prob,$student->{'username'},$student->{'domain'},
$partid,$respid);
$correct = &html_format_sub($correct,'essay');
@@ -427,7 +427,7 @@
$submission = &html_format_sub($submission,$resptype);
my $correct = '';
if ($ENV{'form.correctans'} eq 'true') {
- $correct = &Apache::lonstathelpers::analyze_problem_as_student
+ $correct = &Apache::lonstathelpers::get_student_answer
($prob,$student->{'username'},$student->{'domain'},
$partid,$respid);
$correct = &html_format_sub($correct,$resptype);
@@ -683,7 +683,7 @@
$submission = &excel_format_response($submission,$resptype);
$worksheet->write($row,$col++,$submission);
if ($ENV{'form.correctans'} eq 'true') {
- my $correct = &Apache::lonstathelpers::analyze_problem_as_student
+ my $correct = &Apache::lonstathelpers::get_student_answer
($prob,$student->{'username'},$student->{'domain'},
$partid,$respid);
$correct =&excel_format_response($correct,$resptype);
@@ -885,7 +885,7 @@
my @rowdata;
push(@rowdata,$response->[&Apache::loncoursedata::RDs_submission()]);
if ($ENV{'form.correctans'} eq 'true') {
- my $correct = &Apache::lonstathelpers::analyze_problem_as_student
+ my $correct = &Apache::lonstathelpers::get_student_answer
($prob,$student->{'username'},$student->{'domain'},
$partid,$respid);
push(@rowdata,$correct);
Index: loncom/interface/statistics/lonstathelpers.pm
diff -u loncom/interface/statistics/lonstathelpers.pm:1.29 loncom/interface/statistics/lonstathelpers.pm:1.30
--- loncom/interface/statistics/lonstathelpers.pm:1.29 Wed Nov 3 11:13:08 2004
+++ loncom/interface/statistics/lonstathelpers.pm Mon Nov 8 10:14:52 2004
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonstathelpers.pm,v 1.29 2004/11/03 16:13:08 matthew Exp $
+# $Id: lonstathelpers.pm,v 1.30 2004/11/08 15:14:52 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -578,7 +578,7 @@
last if ($c->aborted());
my $sname = $student->{'username'};
my $sdom = $student->{'domain'};
- my $answer = &Apache::lonstathelpers::analyze_problem_as_student
+ my $answer = &Apache::lonstathelpers::get_student_answer
($resource,$sname,$sdom,$partid,$respid);
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
&mt('last student'));
@@ -599,27 +599,19 @@
=item analyze_problem_as_student
-Analyzes a homework problem for a student and returns the correct answer
-for the student. Attempts to put together an answer for problem types
-that do not natively support it.
+Analyzes a homework problem for a student
Inputs: $resource: a resource object
$sname, $sdom, $partid, $respid
-Returns: $answer
-
-If $partid and $respid are specified, $answer is simply a scalar containing
-the correct answer for the response.
-
-If $partid or $respid are undefined, $answer will be a hash reference with
-keys $partid.'.'.$respid.'.answer'.
+Returns: the problem analysis hash
=cut
#####################################################
#####################################################
sub analyze_problem_as_student {
- my ($resource,$sname,$sdom,$partid,$respid) = @_;
+ my ($resource,$sname,$sdom) = @_;
if (ref($resource) ne 'HASH') {
my $res = $resource;
$resource = { 'src' => $res->src,
@@ -630,12 +622,10 @@
[$res->responseIds($part)];
}
}
- my $returnvalue;
my $url = $resource->{'src'};
my $symb = $resource->{'symb'};
my $analysis = &get_from_analysis_cache($sname,$sdom,$symb);
if (! defined($analysis)) {
- &Apache::lonnet::logthis('uncached analysis');
my $courseid = $ENV{'request.course.id'};
my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze',
'grade_domain' => $sdom,
@@ -647,15 +637,62 @@
}
my %Answer=&Apache::lonnet::str2hash($analysis);
#
+ return \%Answer;
+}
+
+#####################################################
+#####################################################
+
+=pod
+
+=item get_student_answer
+
+Analyzes a homework problem for a particular student and returns the correct
+answer. Attempts to put together an answer for problem types
+that do not natively support it.
+
+Inputs: $resource: a resource object (from navmaps or hash from loncoursedata)
+ $sname, $sdom, $partid, $respid
+
+Returns: $answer
+
+If $partid and $respid are specified, $answer is simply a scalar containing
+the correct answer for the response.
+
+If $partid or $respid are undefined, $answer will be a hash reference with
+keys $partid.'.'.$respid.'.answer'.
+
+=cut
+
+#####################################################
+#####################################################
+sub get_student_answer {
+ my ($resource,$sname,$sdom,$partid,$respid) = @_;
+ #
+ if (ref($resource) ne 'HASH') {
+ my $res = $resource;
+ $resource = { 'src' => $res->src,
+ 'symb' => $res->symb,
+ 'parts' => $res->parts };
+ foreach my $part (@{$resource->{'parts'}}) {
+ $resource->{'partdata'}->{$part}->{'ResponseIds'}=
+ [$res->responseIds($part)];
+ }
+ }
+ #
+ my $analysis =
+ &analyze_problem_as_student($resource,$sname,$sdom);
my $answer;
foreach my $partid (@{$resource->{'parts'}}) {
my $partdata = $resource->{'partdata'}->{$partid};
foreach my $respid (@{$partdata->{'ResponseIds'}}) {
my $prefix = $partid.'.'.$respid;
my $key = $prefix.'.answer';
- $answer->{$partid}->{$respid} = &get_answer($prefix,$key,%Answer);
+ $answer->{$partid}->{$respid} =
+ &get_answer($prefix,$key,%$analysis);
}
}
+ my $returnvalue;
if (! defined($partid)) {
$returnvalue = $answer;
} elsif (! defined($respid)) {