--- loncom/interface/statistics/lonstathelpers.pm 2004/02/19 20:17:01 1.4
+++ loncom/interface/statistics/lonstathelpers.pm 2004/03/08 19:12:18 1.6
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonstathelpers.pm,v 1.4 2004/02/19 20:17:01 matthew Exp $
+# $Id: lonstathelpers.pm,v 1.6 2004/03/08 19:12:18 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -145,7 +145,7 @@ sub ProblemSelector {
$resptype.'
'.
''.$title.' ';
# ''.$resptype.' '.$res->{'title'}.' ';
- if ($partdata->{'option'} > 1) {
+ if (scalar(@{$partdata->{'ResponseIds'}}) > 1) {
$seq_str .= &mt('response').' '.$respid;
}
$seq_str .= " | \n";
@@ -354,6 +354,12 @@ Inputs: $resource: a resource object
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
#####################################################
@@ -371,8 +377,35 @@ sub analyze_problem_as_student {
'grade_courseid' => $courseid));
(my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
my %Answer=&Apache::lonnet::str2hash($Answ);
- my $prefix = $partid.'.'.$respid;
- my $key = $prefix.'.answer';
+ #
+ if (! defined($partid)) {
+ # If you do not specify a partid, you get them all.
+ foreach my $partid (@{$resource->{'parts'}}) {
+ my $partdata = $resource->{'partdata'}->{$partid};
+ foreach my $respid (@{$partdata->{'ResponseIds'}}) {
+ my $prefix = $partid.'.'.$respid;
+ my $key = $prefix.'.answer';
+ $returnvalue->{$key} = &get_answer($prefix,$key,%Answer);
+ }
+ }
+ } elsif (! defined($respid)) {
+ my $partdata = $resource->{'partdata'}->{$partid};
+ foreach my $respid (@{$partdata->{'ResponseIds'}}) {
+ my $prefix = $partid.'.'.$respid;
+ my $key = $prefix.'.answer';
+ $returnvalue->{$key} = &get_answer($prefix,$key,%Answer);
+ }
+ } else {
+ my $prefix = $partid.'.'.$respid;
+ my $key = $prefix.'.answer';
+ $returnvalue = &get_answer($prefix,$key,%Answer);
+ }
+ return $returnvalue;
+}
+
+sub get_answer {
+ my ($prefix,$key,%Answer) = @_;
+ my $returnvalue;
if (exists($Answer{$key})) {
my $student_answer = $Answer{$key}->[0];
if (! defined($student_answer)) {
@@ -404,7 +437,6 @@ sub analyze_problem_as_student {
return $returnvalue;
}
-
##
## The following is copied from datecalc1.pl, part of the
## Spreadsheet::WriteExcel CPAN module.
@@ -654,6 +686,82 @@ sub get_problem_data {
}
####################################################
+####################################################
+
+=pod
+
+=item &limit_by_time()
+
+=cut
+
+####################################################
+####################################################
+sub limit_by_time_form {
+ my $Starttime_form = '';
+ my $starttime = &Apache::lonhtmlcommon::get_date_from_form
+ ('limitby_startdate');
+ my $endtime = &Apache::lonhtmlcommon::get_date_from_form
+ ('limitby_enddate');
+ if (! defined($endtime)) {
+ $endtime = time;
+ }
+ if (! defined($starttime)) {
+ $starttime = $endtime - 60*60*24*7;
+ }
+ my $state;
+ if (&limit_by_time()) {
+ $state = '';
+ } else {
+ $state = 'disabled';
+ }
+ my $startdateform = &Apache::lonhtmlcommon::date_setter
+ ('Statistics','limitby_startdate',$starttime,undef,undef,$state);
+ my $enddateform = &Apache::lonhtmlcommon::date_setter
+ ('Statistics','limitby_enddate',$endtime,undef,undef,$state);
+ my $Str;
+ $Str .= '';
+ $Str .= '';
+ return $Str;
+}
+
+sub limit_by_time {
+ if (exists($ENV{'form.limit_by_time'}) &&
+ $ENV{'form.limit_by_time'} ne '' ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub get_time_limits {
+ my $starttime = &Apache::lonhtmlcommon::get_date_from_form
+ ('limitby_startdate');
+ my $endtime = &Apache::lonhtmlcommon::get_date_from_form
+ ('limitby_enddate');
+ return ($starttime,$endtime);
+}
+
+####################################################
####################################################
=pod