--- loncom/metadata_database/LONCAPA/lonmetadata.pm 2004/04/14 20:35:29 1.7 +++ loncom/metadata_database/LONCAPA/lonmetadata.pm 2004/04/16 21:43:56 1.8 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonmetadata.pm,v 1.7 2004/04/14 20:35:29 matthew Exp $ +# $Id: lonmetadata.pm,v 1.8 2004/04/16 21:43:56 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -410,6 +410,48 @@ sub metadata_col_to_hash { =pod +=item nohist_resevaldata.db data structure + +The nohist_resevaldata.db file has the following possible keys: + + Statistics Data (values are integers, perl times, or real numbers) + ------------------------------------------ + $course___$resource___avetries + $course___$resource___count + $course___$resource___difficulty + $course___$resource___stdno + $course___$resource___timestamp + + Evaluation Data (values are on a 1 to 5 scale) + ------------------------------------------ + $username@$dom___$resource___clear + $username@$dom___$resource___comments + $username@$dom___$resource___depth + $username@$dom___$resource___technical + $username@$dom___$resource___helpful + + Course Context Data + ------------------------------------------ + $course___$resource___course course id + $course___$resource___comefrom resource preceeding this resource + $course___$resource___goto resource following this resource + $course___$resource___usage resource containing this resource + + New statistical data storage + ------------------------------------------ + $course&$sec&$numstud___$resource___stats + $sec is a string describing the sections: all, 1 2, 1 2 3,... + Value is a '&' deliminated list of key=value pairs. + Possible keys are (currently) disc,course,sections,difficulty, + stdno, timestamp + +=cut + +###################################################################### +###################################################################### + +=pod + =item &process_reseval_data Process a nohist_resevaldata hash into a more complex data structure. @@ -474,13 +516,15 @@ sub process_reseval_data { # $source is $cid\_$sec\_$stdno # $value is stat1=value&stat2=value&stat3=value,.... # - my ($cid,$sec,$stdno)=split('_',$source); - my $crssec = $cid.'_'.$sec; + my ($cid,$sec,$stdno)=split('&',$source); + my $crssec = $cid.'&'.$sec; my @Data = split('&',$value); my %Statistics; while (my ($key,$value) = split('=',pop(@Data))) { $Statistics{$key} = $value; } + $sec =~ s:("$|^")::g; + $Statistics{'sections'} = $sec; # # Only store the data if the number of students is greater # than the data already stored @@ -522,26 +566,71 @@ sub process_dynamic_metadata { my %data; my $resdata = $DynamicData->{$url}; # - # Get the statistical data - foreach my $type (qw/avetries difficulty stdno/) { - my $count; + # Get the statistical data - Use a weighted average + foreach my $type (qw/avetries difficulty disc/) { + my $studentcount; my $sum; my @Values; + my @Students; # + # Old data foreach my $coursedata (values(%{$resdata->{'statistics'}}), values(%{$resdata->{'stats'}})) { if (ref($coursedata) eq 'HASH' && exists($coursedata->{$type})) { - $count++; - $sum += $coursedata->{$type}; + $studentcount += $coursedata->{'stdno'}; + $sum += ($coursedata->{$type}*$coursedata->{'stdno'}); push(@Values,$coursedata->{$type}); + push(@Students,$coursedata->{'stdno'}); } } - if ($count) { - $data{$type} = $sum/$count; + if (exists($resdata->{'stats'})) { + foreach my $identifier (sort(keys(%{$resdata->{'stats'}}))) { + my $coursedata = $resdata->{'stats'}->{$identifier}; + $studentcount += $coursedata->{'stdno'}; + $sum += $coursedata->{$type}*$coursedata->{'stdno'}; + push(@Values,$coursedata->{$type}); + push(@Students,$coursedata->{'stdno'}); + } + } + # + # New data + if (defined($studentcount) && $studentcount>0) { + $data{$type} = $sum/$studentcount; $data{$type.'_list'} = join(',',@Values); } } # + # Find out the number of students who have completed the resource... + my $stdno; + foreach my $coursedata (values(%{$resdata->{'statistics'}}), + values(%{$resdata->{'stats'}})) { + if (ref($coursedata) eq 'HASH' && exists($coursedata->{'stdno'})) { + $stdno += $coursedata->{'stdno'}; + } + } + if (exists($resdata->{'stats'})) { + # + # For the number of students, take the maximum found for the class + my $current_course; + my $coursemax=0; + foreach my $identifier (sort(keys(%{$resdata->{'stats'}}))) { + my $coursedata = $resdata->{'stats'}->{$identifier}; + if (! defined($current_course)) { + $current_course = $coursedata->{'course'}; + } + if ($current_course ne $coursedata->{'course'}) { + $stdno += $coursemax; + $coursemax = 0; + $current_course = $coursedata->{'course'}; + } + if ($coursemax < $coursedata->{'stdno'}) { + $coursemax = $coursedata->{'stdno'}; + } + } + $stdno += $coursemax; # pick up the final course in the list + } + $data{'stdno'}=$stdno; + # # Get the context data foreach my $type (qw/course goto comefrom/) { if (defined($resdata->{$type}) && @@ -581,9 +670,33 @@ sub process_dynamic_metadata { $comments .= ''; $data{'comments'} = $comments; # + if (exists($resdata->{'stats'})) { + $data{'stats'} = $resdata->{'stats'}; + } + # return %data; } +sub dynamic_metadata_storage { + my ($data) = @_; + my %Store; + my $courseid = $data->{'course'}; + my $sections = $data->{'sections'}; + my $numstu = $data->{'num_students'}; + my $urlres = $data->{'urlres'}; + my $key = $courseid.'&'.$sections.'&'.$numstu.'___'.$urlres.'___stats'; + $Store{$key} = + 'course='.$courseid.'&'. + 'sections='.$sections.'&'. + 'timestamp='.time.'&'. + 'stdno='.$data->{'num_students'}.'&'. + 'avetries='.$data->{'mean_tries'}.'&'. + 'difficulty='.$data->{'deg_of_diff'}; + if (exists($data->{'deg_of_disc'})) { + $Store{$key} .= '&'.'disc='.$data->{'deg_of_disc'}; + } + return %Store; +} ###################################################################### ######################################################################