';
- $Ptr .= 'Select Map '."\n";
- $Ptr .= ''."\n";
+=item $prev_student
- my $selected = 0;
- foreach my $sequence (split(':',$cache->{'orderedSequences'})) {
- $Ptr .= '{$page.'Map'} eq $cache->{$sequence.':title'}) {
- $Ptr .= ' selected';
- $selected = 1;
- }
- $Ptr .= '>'.$cache->{$sequence.':title'}.' '."\n";
- }
- $Ptr .= '';
- $Ptr .= 'Select Student '."\n";
- $Ptr .= ''."\n";
+=cut
- my $selected=0;
- foreach (@$students) {
- my ($name) = split(':',$_);
- $Ptr .= '{'title'} = $field;
+ $StudentData{$field}->{'base_width'} = length($field);
+ $StudentData{$field}->{'width'} =
+ $StudentData{$field}->{'base_width'};
+ }
+ #
+ # get the status requested
+ $enrollment_status = 'Active';
+ $enrollment_status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
+ #
+ # Process the classlist
+ while (my ($student,$student_data) = each (%$classlist)) {
+ my $studenthash = ();
+ for (my $i=0; $i< scalar(@$field_names);$i++) {
+ my $field = $field_names->[$i];
+ # Store the data
+ $studenthash->{$field}=$student_data->[$i];
+ # Keep track of the width of the fields
+ next if (! exists($StudentData{$field}));
+ my $length = length($student_data->[$i]);
+ if ($StudentData{$field}->{'width'} < $length) {
+ $StudentData{$field}->{'width'} = $length;
+ }
+ }
+ push (@FullClasslist,$studenthash);
+ #
+ # Build up a list of sections
+ my $section = $studenthash->{'section'};
+ if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
+ $studenthash->{'section'} = 'none';
+ $section = $studenthash->{'section'};
+ }
+ $Sections{$section}++;
+ #
+ # Only put in the list those students we are interested in
+ foreach my $sect (@SelectedSections) {
+ if ( (($sect eq 'all') ||
+ ($section eq $sect)) &&
+ (($studenthash->{'status'} eq $enrollment_status) ||
+ ($enrollment_status eq 'Any'))
+ ){
+ push (@Students,$studenthash);
+ last;
+ }
}
- $Ptr .= '>'.$name.' '."\n";
}
-
- $Ptr .= '{$name.':error'} =~ /course/) {
- my ($username)=split(':',$name);
- $Str .= 'No course data for student ';
- $Str .= ''.$username.'. ';
- return $Str;
+ #
+ # Sort the Students
+ my $sortby = 'fullname';
+ $sortby = $ENV{'form.sort'} if (exists($ENV{'form.sort'}));
+ my @TmpStudents = sort { $a->{$sortby} cmp $b->{$sortby} ||
+ $a->{'fullname'} cmp $b->{'fullname'} } @Students;
+ @Students = @TmpStudents;
+ #
+ # Now deal with that current student thing....
+ $curr_student = undef;
+ if (exists($ENV{'form.SelectedStudent'})) {
+ my ($current_uname,$current_dom) =
+ split(':',$ENV{'form.SelectedStudent'});
+ my $i;
+ for ($i = 0; $i<=$#Students; $i++) {
+ next if (($Students[$i]->{'username'} ne $current_uname) ||
+ ($Students[$i]->{'domain'} ne $current_dom));
+ $curr_student = $Students[$i];
+ last; # If we get here, we have our student.
+ }
+ if (defined($curr_student)) {
+ if ($i == 0) {
+ $prev_student = undef;
+ } else {
+ $prev_student = $Students[$i-1];
+ }
+ if ($i == $#Students) {
+ $next_student = undef;
+ } else {
+ $next_student = $Students[$i+1];
+ }
+ }
}
-
- $Str .= " \# Set Title ";
- $Str .= ' Results Tries '."\n";
-
- my $codes;
- my $attempts;
- foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
- if($cache->{'StudentAssessmentMap'} ne 'All Maps' &&
- $cache->{'StudentAssessmentMap'} ne $cache->{$sequence.':title'}) {
- next;
+ #
+ if (exists($ENV{'form.StudentData'})) {
+ if (ref($ENV{'form.StudentData'}) eq 'ARRAY') {
+ @SelectedStudentData = @{$ENV{'form.StudentData'}};
+ } else {
+ @SelectedStudentData = ($ENV{'form.StudentData'});
}
+ } else {
+ @SelectedStudentData = ('username');
+ }
+ foreach (@SelectedStudentData) {
+ if ($_ eq 'all') {
+ @SelectedStudentData = ('all');
+ last;
+ }
+ }
+ #
+ return;
+}
- $Str .= ''.$sequence.' ';
- $Str .= ''.$cache->{$sequence.':title'}.' ';
- $codes = '';
- $attempts = '';
- foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
- my $problem = $cache->{$problemID.':problem'};
- my $LatestVersion = $cache->{$name.':version:'.$problem};
-
- # Output dashes for all the parts of this problem if there
- # is no version information about the current problem.
- if(!$LatestVersion) {
- foreach my $part (split(/\:/,$cache->{$sequence.':'.
- $problemID.
- ':parts'})) {
- $codes .= "-,";
- $attempts .= "0,";
- }
- next;
- }
+#######################################################
+#######################################################
- my %partData=undef;
- # Initialize part data, display skips correctly
- # Skip refers to when a student made no submissions on that
- # part/problem.
- foreach my $part (split(/\:/,$cache->{$sequence.':'.
- $problemID.
- ':parts'})) {
- $partData{$part.':tries'}=0;
- $partData{$part.':code'}='-';
- }
+=pod
- # Looping through all the versions of each part, starting with the
- # oldest version. Basically, it gets the most recent
- # set of grade data for each part.
- for(my $Version=1; $Version<=$LatestVersion; $Version++) {
- foreach my $part (split(/\:/,$cache->{$sequence.':'.
- $problemID.
- ':parts'})) {
-
- if(!defined($cache->{$name.":$Version:$problem".
- ":resource.$part.solved"})) {
- # No grade for this submission, so skip
- next;
- }
+=item get_students
- my $tries=0;
- my $code='U';
+Returns a list of the selected students
- $tries = $cache->{$name.":$Version:$problem".
- ":resource.$part.tries"};
- $partData{$part.':tries'}=($tries) ? $tries : 0;
-
- my $val = $cache->{$name.":$Version:$problem".
- ":resource.$part.solved"};
- if ($val eq 'correct_by_student') {$code = 'Y';}
- elsif ($val eq 'correct_by_override') {$code = 'y';}
- elsif ($val eq 'incorrect_attempted') {$code = 'N';}
- elsif ($val eq 'incorrect_by_override'){$code = 'N';}
- elsif ($val eq 'excused') {$code = 'x';}
- $partData{$part.':code'}=$code;
- }
- }
+=cut
- # Loop through all the parts for the current problem in the
- # correct order and prepare the output
- foreach (split(/\:/,$cache->{$sequence.':'.$problemID.
- ':parts'})) {
- $codes .= $partData{$_.':code'}.',';
- $attempts .= $partData{$_.':tries'}.',';
- }
- }
- $codes =~ s/,$//;
- $attempts =~ s/,$//;
- $Str .= ''.$codes.' ';
- $Str .= ''.$attempts.' ';
- $Str .= ' '."\n";
+#######################################################
+#######################################################
+sub get_students {
+ if (! @Students) {
+ &PrepareClasslist()
}
-
- $Str .= '
'."\n";
-
- return $Str;
+ return @Students;
}
-#---- END Student Assessment Web Page ----------------------------------------
+#######################################################
+#######################################################
-#---- Menu Web Page ----------------------------------------------------------
+=pod
-sub Title {
- my ($downloadTime)=@_;
+=item ¤t_student()
- my $Ptr = '';
+Returns a pointer to a hash containing data about the currently
+selected student.
- $Ptr .= 'LON-CAPA Statistics '."\n";
- $Ptr .= ''."\n";
- $Ptr .= ''."\n";
- $Ptr .= ' '."\n";
- $Ptr .= ' Course : "';
- $Ptr .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
- $Ptr .= '" '."\n";
- $Ptr .= ''.$downloadTime.' ';
+=cut
- return $Ptr;
+#######################################################
+#######################################################
+sub current_student {
+ return $curr_student;
}
-sub CreateMenuForm {
- my ($cache)=@_;
- my $Ptr = '';
- $Ptr .= ' {'OptionResponses'})) {
- $Ptr .= ' {$cacheName} = $ENV{'form.'.$ENVName};
- } elsif(!defined($cache->{$cacheName})) {
- $cache->{$cacheName} = $default;
- }
+Returns a pointer to a hash containing data about the next student
+to be viewed.
- return;
-}
+=cut
-sub ProcessFormData{
- my ($cacheDB, $isCached)=@_;
- my %cache;
-
- if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
- # Select page to display
- if(defined($ENV{'form.ProblemStatistics'}) ||
- defined($ENV{'form.ProblemStatisticsRecalculate'}) ||
- defined($ENV{'form.DisplayCSVFormat'})) {
- $cache{'GoToPage'} = 'ProblemStatistics';
- &CheckFormElement(\%cache, 'DisplayCSVFormat',
- 'DisplayFormat', 'Display Table Format');
- &CheckFormElement(\%cache, 'Ascend','ProblemStatisticsAscend',
- 'Ascending');
- &CheckFormElement(\%cache, 'Maps', 'ProblemStatisticsMap',
- 'All Maps');
- } elsif(defined($ENV{'form.ProblemAnalysis'})) {
- $cache{'GoToPage'} = 'ProblemAnalysis';
- &CheckFormElement(\%cache, 'Interval', 'Interval', '1');
- } elsif(defined($ENV{'form.StudentAssessment'}) ||
- defined($ENV{'form.CreateStudentAssessment'}) ||
- defined($ENV{'form.NextStudent'}) ||
- defined($ENV{'form.PreviousStudent'})) {
- $cache{'GoToPage'} = 'StudentAssessment';
- if(defined($ENV{'form.NextStudent'})) {
- $cache{'StudentAssessmentMove'} = 'next';
- } elsif(defined($ENV{'form.PreviousStudent'})) {
- $cache{'StudentAssessmentMove'} = 'previous';
- } else {
- $cache{'StudentAssessmentMove'} = 'selected';
- }
- &CheckFormElement(\%cache, 'Maps', 'StudentAssessmentMap',
- 'All Maps');
+#######################################################
+#######################################################
+sub next_student {
+ return $next_student;
+}
- &CheckFormElement(\%cache, 'Students', 'StudentAssessmentStudent',
- 'No Student Selected');
- } elsif(defined($ENV{'form.DoDiffGraph'})) {
- $cache{'GoToPage'} = 'DoDiffGraph';
- } elsif(defined($ENV{'form.PercentWrongGraph'})) {
- $cache{'GoToPage'} = 'PercentWrongGraph';
- } elsif(defined($ENV{'form.ActivityLog'})) {
- $cache{'GoToPage'} = 'ActivityLog';
- } else {
- $cache{'GoToPage'} = 'Menu';
- }
+#######################################################
+#######################################################
- &CheckFormElement(\%cache, 'Status', 'Status', 'Active');
+=pod
- foreach (keys(%ENV)) {
- if(/form\.Analyze:::/) {
- $cache{'GoToPage'} = 'Analyze';
- my ($uri, $title, $part, $problem);
- (undef, $uri, $title, $part, $problem)=split(':::', $_);
- $cache{'AnalyzeURI'} = $uri;
- $cache{'AnalyzeTitle'} = $title;
- $cache{'AnalyzePart'} = $part;
- $cache{'AnalyzeProblem'} = $problem;
+=item &clear_sequence_variables()
- &CheckFormElement(\%cache, 'Interval', 'Interval', '1');
- }
- }
- }
+=cut
- return;
+#######################################################
+#######################################################
+sub clear_sequence_variables {
+ undef($top_map);
+ undef(@Sequences);
+ undef(@Assessments);
}
+#######################################################
+#######################################################
+
=pod
-=item &SortStudents()
+=item &SetSelectedMaps($elementname)
-Determines which students to display and in which order. Which are
-displayed are determined by their status(active/expired). The order
-is determined by the sort button pressed (default to username). The
-type of sorting is username, lastname, or section.
+Sets the @SelectedMaps array from $ENV{'form.'.$elementname};
-=over 4
+=cut
-Input: $students, $CacheData
+#######################################################
+#######################################################
+sub SetSelectedMaps {
+ my $elementname = shift;
+ if (exists($ENV{'form.'.$elementname})) {
+ if (ref($ENV{'form.'.$elementname})) {
+ @SelectedMaps = @{$ENV{'form.'.$elementname}};
+ } else {
+ @SelectedMaps = ($ENV{'form.'.$elementname});
+ }
+ } else {
+ @SelectedMaps = ('all');
+ }
+}
-$students: A array pointer to a list of students (username:domain)
-$CacheData: A pointer to the hash tied to the cached data
+#######################################################
+#######################################################
-Output: \@order
+=pod
-@order: An ordered list of students (username:domain)
+=item &Sequences_with_Assess()
-=back
+Returns an array containing the subset of @Sequences which contain
+assessments.
=cut
-sub SortStudents {
- my ($students,$cache)=@_;
+#######################################################
+#######################################################
+sub Sequences_with_Assess {
+ my ($mode) = @_;
+ $mode = 'selected' if (! defined($mode));
+ my @Sequences_to_Show;
+ foreach my $sequence (@Sequences) {
+ next if ($sequence->{'num_assess'} < 1);
+ if ($mode eq 'all') {
+ push (@Sequences_to_Show,$sequence);
+ } elsif ($mode eq 'selected') {
+ foreach my $map_symb (@SelectedMaps) {
+ if ($sequence->{'symb'} eq $map_symb || $map_symb eq 'all'){
+ push (@Sequences_to_Show,$sequence);
+ last; # Only put it in once
+ }
+ }
+ }
- my @sorted1Students=();
- foreach (@$students) {
- push(@sorted1Students, $_);
- }
-# my ($end,$start)=split(/\:/,$cache->{$_.':date'});
-# my $active=1;
-# my $now=time;
-# my $Status=$cache->{'form.Status'};
-# $Status = ($Status) ? $Status : 'Active';
-# if((($end) && $now > $end) && (($Status eq 'Active'))) {
-# $active=0;
-# }
-# if(($Status eq 'Expired') && ($end == 0 || $now < $end)) {
-# $active=0;
-# }
-# if($active) {
-# push(@sorted1Students, $_);
-# }
-# }
-
- my $Pos = $cache->{'form.ChartSort'};
- my %sortData;
- if($Pos eq 'Last Name') {
- for(my $index=0; $index{$sorted1Students[$index].':fullname'}}=
- $sorted1Students[$index];
- }
- } elsif($Pos eq 'Section') {
- for(my $index=0; $index{$sorted1Students[$index].':section'}.
- $sorted1Students[$index]}=$sorted1Students[$index];
- }
- } else {
- # Sort by user name
- for(my $index=0; $indexaborted()) {
- untie(%cache);
- return 'aborted';
- }
+=cut
- my $classlist=&Apache::loncoursedata::DownloadStudentNamePIDSection(
- $courseID,
- $c);
- my ($checkForError)=keys(%$classlist);
- if($checkForError =~ /^(con_lost|error|no_such_host)/i ||
- defined($classlist->{'error'})) {
- untie(%cache);
- return "Error getting student data.";
+#######################################################
+#######################################################
+sub log_sequence {
+ my ($seq,$recursive,$padding) = @_;
+ $padding = '' if (! defined($padding));
+ if (ref($seq) ne 'HASH') {
+ &Apache::lonnet::logthis('log_sequence passed bad sequnce');
+ return;
+ }
+ &Apache::lonnet::logthis($padding.'sequence '.$seq->{'title'});
+ while (my($key,$value) = each(%$seq)) {
+ next if ($key eq 'contents');
+ if (ref($value) eq 'ARRAY') {
+ for (my $i=0;$i< scalar(@$value);$i++) {
+ &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
+ $value->[$i]);
+ }
+ } else {
+ &Apache::lonnet::logthis($padding.$key.'='.$value);
}
-
- if($c->aborted()) {
- untie(%cache);
- return 'aborted';
+ }
+ if (defined($recursive)) {
+ &Apache::lonnet::logthis($padding.'-'x20);
+ &Apache::lonnet::logthis($padding.'contains:');
+ foreach my $item (@{$seq->{'contents'}}) {
+ if ($item->{'type'} eq 'container') {
+ &log_sequence($item,$recursive,$padding.' ');
+ } else {
+ &Apache::lonnet::logthis($padding.'title = '.$item->{'title'});
+ while (my($key,$value) = each(%$item)) {
+ next if ($key eq 'title');
+ if (ref($value) eq 'ARRAY') {
+ for (my $i=0;$i< scalar(@$value);$i++) {
+ &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
+ $value->[$i]);
+ }
+ } else {
+ &Apache::lonnet::logthis($padding.$key.'='.$value);
+ }
+ }
+ }
}
+ &Apache::lonnet::logthis($padding.'end contents of '.$seq->{'title'});
+ &Apache::lonnet::logthis($padding.'-'x20);
+ }
+ return;
+}
- # Active is a temporary solution, remember to change
- @students=&Apache::loncoursedata::ProcessClassList(\%cache,
- $classlist,
- $courseID,
- 'Active', $c);
+##############################################
+##############################################
- if($c->aborted()) {
- untie(%cache);
- return 'aborted';
- }
+=pod
- untie(%cache);
- } else {
- if(!$c->aborted() && tie(%cache,'GDBM_File',$cacheDB,
- &GDBM_READER,0640)) {
- @students=split(/:::/,$cache{'NamesOfStudents'});
- } else {
- return 'aborted';
- }
- }
+=item &StudentDataSelect($elementname,$status,$numvisible,$selected)
- return ('OK', $isCached, \@students);
-}
+Returns html for a selection box allowing the user to choose one (or more)
+of the fields of student data available (fullname, username, id, section, etc)
-# Create progress
-sub Create_PrgWin {
- $r->print(<
- popwin=open('','popwin','width=400,height=100');
- popwin.document.writeln(''+
- 'LON-CAPA Statistics '+
- 'Computation Progress '+
- ''+
- '');
- popwin.document.close();
-
-ENDPOP
+=over 4
- $r->rflush();
-}
+=item $elementname The name of the HTML form element
-# update progress
-sub Update_PrgWin {
- my ($totalStudents,$index,$name)=@_;
- $r->print('');
- $r->rflush();
-}
+=item $status 'multiple' or 'single' selection box
-# close Progress Line
-sub Close_PrgWin {
- $r->print('');
- $r->rflush();
-}
-
-# For loading the colored table for display or un-colored for print
-sub setbgcolor {
- my $PrintTable=shift;
- undef %color;
- if ($PrintTable){
- $color{"gb"}="#FFFFFF";
- $color{"red"}="#FFFFFF";
- $color{"yellow"}="#FFFFFF";
- $color{"green"}="#FFFFFF";
- $color{"purple"}="#FFFFFF";
- } else {
- $color{"gb"}="#DDFFFF";
- $color{"red"}="#FFDDDD";
- $color{"yellow"}="#EEFFCC";
- $color{"green"}="#DDFFDD";
- $color{"purple"}="#FFDDFF";
- }
+=item $numvisible The number of options to be visible
- return;
-}
+=back
+
+=cut
-sub initial {
- undef %hash;
- undef %CachData;
- undef %GraphDat;
- undef %ConceptData;
- undef $Pos;
- undef $GData;
-}
-
-#---- END HELPER FUNCTIONS ---------------------------------------------------
-
-sub BuildProblemStatisticsPage {
- my ($cacheDB, $students)=@_;
-
- my %cache;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- $r->print('Unable to tie database.');
+##############################################
+##############################################
+sub StudentDataSelect {
+ my ($elementname,$status,$numvisible)=@_;
+ if ($numvisible < 1) {
return;
}
+ #
+ # Build the form element
+ my $Str = "\n";
+ $Str .= ''."\n";
+ #
+ # Deal with 'all'
+ $Str .= ' \n";
+ }
+ $Str .= " \n";
+ return $Str;
+}
- my $Ptr = '';
- $Ptr .= '
');
-
- $r->print(&ProblemStatisticsLegend());
-
-# my $discriminantFactor;
-# my $list;
-# foreach (@$students) {
-# ($discriminantFactor, $list) = &ExtractStudentData($_);
-# }
-
-# my ($upper, $lower) = &Discriminant($discriminantFactor);
-# my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
-# 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
-# 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
-# &BuildStatisticsTable(\%cache, $discriminantFactor, $list, \%Header);
+##############################################
+##############################################
- $r->print('');
+=pod
- untie(%cache);
+=item &MapSelect($elementname,$status,$numvisible,$restriction)
- return;
-}
+Returns html for a selection box allowing the user to choose one (or more)
+of the sequences in the course. The values of the sequences are the symbs.
+If the top sequence is selected, the value 'top' will result.
-sub BuildDiffGraph {
- my ($courseID)=@_;
+=over 4
- my $graphData = &GetGraphData('DiffGraph', $courseID);
- $r->print(' ');
+=item $elementname The name of the HTML form element
- return;
-}
+=item $status 'multiple' or 'single' selection box
-sub BuildWrongGraph {
- my ($courseID)=@_;
+=item $numvisible The number of options to be visible
- my $graphData = &GetGraphData('WrongGraph', $courseID);
- $r->print(' ');
+=item $restriction Code reference to subroutine which returns true or
+false. The code must expect a reference to a sequence data structure.
- return;
-}
+=back
-sub BuildAnalyzePage {
- my ($cacheDB, $students, $courseID)=@_;
+=cut
- my %cache;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- $r->print('Unable to tie database.');
+##############################################
+##############################################
+sub MapSelect {
+ my ($elementname,$status,$numvisible,$restriction)=@_;
+ if ($numvisible < 1) {
return;
}
+ #
+ # Set up array of selected items
+ &SetSelectedMaps($elementname);
+ #
+ # Set up the restriction call
+ if (! defined($restriction)) {
+ $restriction = sub { 1; };
+ }
+ #
+ # Build the form element
+ my $Str = "\n";
+ $Str .= ''."\n";
+ #
+ # Deal with 'all'
+ foreach (@SelectedMaps) {
+ if ($_ eq 'all') {
+ @SelectedMaps = ('all');
+ last;
+ }
+ }
+ #
+ # Put in option for 'all'
+ $Str .= ' ($seq));
+ $Str .= ' {'symb'} eq $_) {
+ $Str .= 'selected ';
+ last;
+ }
+ }
+ $Str .= '>'.$seq->{'title'}." \n";
+ }
+ $Str .= " \n";
+ return $Str;
+}
- &ShowOpGraph(\%cache, $students, $courseID);
-
- untie(%cache);
+##############################################
+##############################################
- return;
-}
+=pod
-sub BuildProblemAnalysisPage {
- my ($cacheDB)=@_;
+=item &SectionSelect($elementname,$status,$numvisible)
- my %cache;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
- $r->print('Unable to tie database.');
- return;
- }
+Returns html for a selection box allowing the user to choose one (or more)
+of the sections in the course.
- $r->print(''."\n");
+Uses the package variables @Sections and @SelectedSections
+=over 4
- untie(%cache);
+=item $elementname The name of the HTML form element
- return;
-}
+=item $status 'multiple' or 'single' selection box
-sub BuildStudentAssessmentPage {
- my ($cacheDB, $students, $courseID)=@_;
+=item $numvisible The number of options to be visible
- my %cache;
+=back
- my $Ptr = '';
- $Ptr .= '