version 1.127, 2004/03/23 16:35:15
|
version 1.134, 2004/06/04 17:46:10
|
Line 547 store student data.
|
Line 547 store student data.
|
################################################ |
################################################ |
################################################ |
################################################ |
sub init_dbs { |
sub init_dbs { |
my $courseid = shift; |
my ($courseid,$drop) = @_; |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
# |
# |
# Drop any of the existing tables |
# Drop any of the existing tables |
foreach my $table (@Tables) { |
if ($drop) { |
&Apache::lonmysql::drop_table($table); |
foreach my $table (@Tables) { |
|
&Apache::lonmysql::drop_table($table); |
|
} |
} |
} |
# |
# |
# Note - changes to this table must be reflected in the code that |
# Note - changes to this table must be reflected in the code that |
Line 580 sub init_dbs {
|
Line 582 sub init_dbs {
|
restrictions => 'NOT NULL', |
restrictions => 'NOT NULL', |
auto_inc => 'yes', }, |
auto_inc => 'yes', }, |
{ name => 'part', |
{ name => 'part', |
type => 'VARCHAR(100)', |
type => 'VARCHAR(100) BINARY', |
restrictions => 'NOT NULL'}, |
restrictions => 'NOT NULL'}, |
], |
], |
'PRIMARY KEY' => ['part (100)'], |
'PRIMARY KEY' => ['part (100)'], |
Line 595 sub init_dbs {
|
Line 597 sub init_dbs {
|
restrictions => 'NOT NULL', |
restrictions => 'NOT NULL', |
auto_inc => 'yes', }, |
auto_inc => 'yes', }, |
{ name => 'student', |
{ name => 'student', |
type => 'VARCHAR(100)', |
type => 'VARCHAR(100) BINARY', |
restrictions => 'NOT NULL UNIQUE'}, |
restrictions => 'NOT NULL UNIQUE'}, |
{ name => 'section', |
{ name => 'section', |
type => 'VARCHAR(100)', |
type => 'VARCHAR(100) BINARY', |
restrictions => 'NOT NULL'}, |
restrictions => 'NOT NULL'}, |
{ name => 'status', |
{ name => 'status', |
type => 'VARCHAR(15)', |
type => 'VARCHAR(15) BINARY', |
restrictions => 'NOT NULL'}, |
restrictions => 'NOT NULL'}, |
{ name => 'classification', |
{ name => 'classification', |
type => 'varchar(100)', }, |
type => 'VARCHAR(100) BINARY', }, |
{ name => 'updatetime', |
{ name => 'updatetime', |
type => 'INT UNSIGNED'}, |
type => 'INT UNSIGNED'}, |
{ name => 'fullupdatetime', |
{ name => 'fullupdatetime', |
Line 629 sub init_dbs {
|
Line 631 sub init_dbs {
|
type => 'MEDIUMINT UNSIGNED', |
type => 'MEDIUMINT UNSIGNED', |
restrictions => 'NOT NULL' }, |
restrictions => 'NOT NULL' }, |
{ name => 'part', |
{ name => 'part', |
type => 'VARCHAR(100)', |
type => 'VARCHAR(100) BINARY', |
restrictions => 'NOT NULL'}, |
restrictions => 'NOT NULL'}, |
{ name => 'solved', |
{ name => 'solved', |
type => 'TINYTEXT' }, |
type => 'TINYTEXT' }, |
Line 709 sub init_dbs {
|
Line 711 sub init_dbs {
|
{ name => 'awarddetail', |
{ name => 'awarddetail', |
type => 'TINYTEXT' }, |
type => 'TINYTEXT' }, |
# { name => 'message', |
# { name => 'message', |
# type => 'CHAR' }, |
# type => 'CHAR BINARY'}, |
{ name => 'response_specific', |
{ name => 'response_specific', |
type => 'TINYTEXT' }, |
type => 'TINYTEXT' }, |
{ name => 'response_specific_value', |
{ name => 'response_specific_value', |
Line 1081 sub populate_student_table {
|
Line 1083 sub populate_student_table {
|
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
|
&init_dbs($courseid,0); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $request = 'INSERT IGNORE INTO '.$student_table. |
my $request = 'INSERT IGNORE INTO '.$student_table. |
"(student,section,status) VALUES "; |
"(student,section,status) VALUES "; |
Line 1594 sub ensure_tables_are_set_up {
|
Line 1597 sub ensure_tables_are_set_up {
|
!$found_performance || !$found_parameters || |
!$found_performance || !$found_parameters || |
!$found_fulldump_part || !$found_fulldump_response || |
!$found_fulldump_part || !$found_fulldump_response || |
!$found_fulldump_timestamp || !$found_weight ) { |
!$found_fulldump_timestamp || !$found_weight ) { |
if (&init_dbs($courseid)) { |
if (&init_dbs($courseid,1)) { |
return 'error'; |
return 'error'; |
} |
} |
} |
} |
Line 2004 sub get_problem_statistics {
|
Line 2007 sub get_problem_statistics {
|
$dbh->do($request); |
$dbh->do($request); |
# |
# |
# Collect the first suite of statistics |
# Collect the first suite of statistics |
$request = 'SELECT COUNT(*),SUM(tries),MAX(tries),AVG(tries),STD(tries) '. |
$request = 'SELECT COUNT(*),SUM(tries),'. |
|
'AVG(tries),STD(tries) '. |
'FROM '.$stats_table; |
'FROM '.$stats_table; |
my ($num,$tries,$mod,$mean,$STD) = &execute_SQL_request |
my ($num,$tries,$mean,$STD) = &execute_SQL_request |
($dbh,$request); |
($dbh,$request); |
|
# |
|
$request = 'SELECT MAX(tries),MIN(tries) FROM '.$stats_table. |
|
' WHERE awarded>0'; |
|
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
|
my ($max,$min) = &execute_SQL_request($dbh,$request); |
|
# |
$request = 'SELECT SUM(awarded) FROM '.$stats_table; |
$request = 'SELECT SUM(awarded) FROM '.$stats_table; |
|
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
my ($Solved) = &execute_SQL_request($dbh,$request); |
my ($Solved) = &execute_SQL_request($dbh,$request); |
|
# |
$request = 'SELECT SUM(awarded) FROM '.$stats_table. |
$request = 'SELECT SUM(awarded) FROM '.$stats_table. |
" WHERE solved='correct_by_override'"; |
" WHERE solved='correct_by_override'"; |
|
if (defined($time_requirements)) { |
|
$request .= ' AND '.$time_requirements; |
|
} |
my ($solved) = &execute_SQL_request($dbh,$request); |
my ($solved) = &execute_SQL_request($dbh,$request); |
# |
# |
|
$Solved -= $solved; |
|
# |
$num = 0 if (! defined($num)); |
$num = 0 if (! defined($num)); |
$tries = 0 if (! defined($tries)); |
$tries = 0 if (! defined($tries)); |
$mod = 0 if (! defined($mod)); |
$max = 0 if (! defined($max)); |
|
$min = 0 if (! defined($min)); |
$STD = 0 if (! defined($STD)); |
$STD = 0 if (! defined($STD)); |
$Solved = 0 if (! defined($Solved)); |
$Solved = 0 if (! defined($Solved) || $Solved < 0); |
$solved = 0 if (! defined($solved)); |
$solved = 0 if (! defined($solved)); |
# |
# |
# Compute the more complicated statistics |
# Compute the more complicated statistics |
Line 2027 sub get_problem_statistics {
|
Line 2049 sub get_problem_statistics {
|
# |
# |
my $SKEW = 'nan'; |
my $SKEW = 'nan'; |
my $wrongpercent = 0; |
my $wrongpercent = 0; |
|
my $numwrong = 'nan'; |
if ($num > 0) { |
if ($num > 0) { |
($SKEW) = &execute_SQL_request($dbh,'SELECT SQRT(SUM('. |
($SKEW) = &execute_SQL_request($dbh,'SELECT SQRT(SUM('. |
'POWER(tries - '.$STD.',3)'. |
'POWER(tries - '.$STD.',3)'. |
'))/'.$num.' FROM '.$stats_table); |
'))/'.$num.' FROM '.$stats_table); |
$wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10; |
$numwrong = $num-$Solved; |
|
$wrongpercent=int(10*100*$numwrong/$num)/10; |
} |
} |
# |
# |
# Drop the temporary table |
# Drop the temporary table |
$dbh->do('DROP TABLE '.$stats_table); # May return an error |
$dbh->do('DROP TABLE '.$stats_table); # May return an error |
# |
# |
# Store in metadata |
|
if ($num) { |
|
my %storestats=(); |
|
# |
|
my $urlres=(&Apache::lonnet::decode_symb($symb))[2]; |
|
# |
|
$storestats{$courseid.'___'.$urlres.'___timestamp'}=time; |
|
$storestats{$courseid.'___'.$urlres.'___stdno'}=$num; |
|
$storestats{$courseid.'___'.$urlres.'___avetries'}=$mean; |
|
$storestats{$courseid.'___'.$urlres.'___difficulty'}=$DegOfDiff; |
|
# |
|
$urlres=~/^(\w+)\/(\w+)/; |
|
&Apache::lonnet::put('nohist_resevaldata',\%storestats,$1,$2); |
|
} |
|
# |
|
# Return result |
# Return result |
return { num_students => $num, |
return { num_students => $num, |
tries => $tries, |
tries => $tries, |
max_tries => $mod, |
max_tries => $max, |
|
min_tries => $min, |
mean_tries => $mean, |
mean_tries => $mean, |
std_tries => $STD, |
std_tries => $STD, |
skew_tries => $SKEW, |
skew_tries => $SKEW, |
num_solved => $Solved, |
num_solved => $Solved, |
num_override => $solved, |
num_override => $solved, |
|
num_wrong => $numwrong, |
per_wrong => $wrongpercent, |
per_wrong => $wrongpercent, |
deg_of_diff => $DegOfDiff }; |
deg_of_diff => $DegOfDiff }; |
} |
} |
Line 2139 sub populate_weight_table {
|
Line 2150 sub populate_weight_table {
|
|
|
=pod |
=pod |
|
|
|
=item &limit_by_start_end_times |
|
|
|
Build SQL WHERE condition which limits the data collected by the start |
|
and end times provided |
|
|
|
Inputs: $starttime, $endtime, $table |
|
|
|
Returns: $time_limits |
|
|
|
=cut |
|
|
|
########################################################## |
|
########################################################## |
|
sub limit_by_start_end_time { |
|
my ($starttime,$endtime,$table) = @_; |
|
my $time_requirements = undef; |
|
if (defined($starttime)) { |
|
$time_requirements .= $table.".timestamp>='".$starttime."'"; |
|
if (defined($endtime)) { |
|
$time_requirements .= " AND ".$table.".timestamp<='".$endtime."'"; |
|
} |
|
} elsif (defined($endtime)) { |
|
$time_requirements .= $table.".timestamp<='".$endtime."'"; |
|
} |
|
return $time_requirements; |
|
} |
|
|
|
########################################################## |
|
########################################################## |
|
|
|
=pod |
|
|
=item &limit_by_section_and_status |
=item &limit_by_section_and_status |
|
|
Build SQL WHERE condition which limits the data collected by section and |
Build SQL WHERE condition which limits the data collected by section and |
Line 2194 sub RNK_student { return 0; };
|
Line 2237 sub RNK_student { return 0; };
|
sub RNK_score { return 1; }; |
sub RNK_score { return 1; }; |
|
|
sub rank_students_by_scores_on_resources { |
sub rank_students_by_scores_on_resources { |
my ($resources,$Sections,$enrollment,$courseid) = @_; |
my ($resources,$Sections,$enrollment,$courseid,$starttime,$endtime) = @_; |
return if (! defined($resources) || ! ref($resources) eq 'ARRAY'); |
return if (! defined($resources) || ! ref($resources) eq 'ARRAY'); |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $ENV{'request.course.id'}; |
Line 2207 sub rank_students_by_scores_on_resources
|
Line 2250 sub rank_students_by_scores_on_resources
|
my $symb_limits = '('.join(' OR ',map {'a.symb_id='.&get_symb_id($_); |
my $symb_limits = '('.join(' OR ',map {'a.symb_id='.&get_symb_id($_); |
} @$resources |
} @$resources |
).')'; |
).')'; |
|
my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); |
my $request = 'SELECT b.student,SUM(a.awarded*w.weight) AS score FROM '. |
my $request = 'SELECT b.student,SUM(a.awarded*w.weight) AS score FROM '. |
$performance_table.' AS a '. |
$performance_table.' AS a '. |
'NATURAL LEFT JOIN '.$weight_table.' AS w '. |
'NATURAL LEFT JOIN '.$weight_table.' AS w '. |
Line 2218 sub rank_students_by_scores_on_resources
|
Line 2262 sub rank_students_by_scores_on_resources
|
if (defined($enrollment_limits)) { |
if (defined($enrollment_limits)) { |
$request .= $enrollment_limits.' AND '; |
$request .= $enrollment_limits.' AND '; |
} |
} |
|
if (defined($time_limits)) { |
|
$request .= $time_limits.' AND '; |
|
} |
if ($symb_limits ne '()') { |
if ($symb_limits ne '()') { |
$request .= $symb_limits.' AND '; |
$request .= $symb_limits.' AND '; |
} |
} |
Line 2251 Returns: the sum of the score on the pro
|
Line 2298 Returns: the sum of the score on the pro
|
######################################################## |
######################################################## |
######################################################## |
######################################################## |
sub get_sum_of_scores { |
sub get_sum_of_scores { |
my ($resource,$part,$students,$courseid) = @_; |
my ($resource,$part,$students,$courseid,$starttime,$endtime) = @_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $ENV{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $dbh = &Apache::lonmysql::get_dbh(); |
|
my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); |
my $request = 'SELECT SUM(a.awarded*w.weight),SUM(w.weight) FROM '. |
my $request = 'SELECT SUM(a.awarded*w.weight),SUM(w.weight) FROM '. |
$performance_table.' AS a '. |
$performance_table.' AS a '. |
'NATURAL LEFT JOIN '.$weight_table.' AS w '; |
'NATURAL LEFT JOIN '.$weight_table.' AS w '; |
$request .= 'WHERE a.symb_id='.&get_symb_id($resource->{'symb'}). |
$request .= 'WHERE a.symb_id='.&get_symb_id($resource->{'symb'}). |
' AND a.part_id='.&get_part_id($part); |
' AND a.part_id='.&get_part_id($part); |
|
if (defined($time_limits)) { |
|
$request .= ' AND '.$time_limits; |
|
} |
if (defined($students)) { |
if (defined($students)) { |
$request .= ' AND ('. |
$request .= ' AND ('. |
join(' OR ',map {'a.student_id='.&get_student_id(split(':',$_)); |
join(' OR ',map {'a.student_id='.&get_student_id(split(':',$_)); |
Line 2279 sub get_sum_of_scores {
|
Line 2330 sub get_sum_of_scores {
|
return ($rows->[0],$rows->[1]); |
return ($rows->[0],$rows->[1]); |
} |
} |
|
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
|
|
|
=item &score_stats |
|
|
|
Inputs: $Sections, $enrollment, $symbs, $starttime, |
|
$endtime, $courseid |
|
|
|
$Sections, $enrollment, $starttime, $endtime, and $courseid are the same as |
|
elsewhere in this module. |
|
$symbs is an array ref of symbs |
|
|
|
Returns: minimum, maximum, mean, s.d., number of students, and maximum |
|
possible of student scores on the given resources |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
sub score_stats { |
|
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
|
if (! defined($courseid)) { |
|
$courseid = $ENV{'request.course.id'}; |
|
} |
|
# |
|
&setup_table_names($courseid); |
|
my $dbh = &Apache::lonmysql::get_dbh(); |
|
# |
|
my ($section_limits,$enrollment_limits)= |
|
&limit_by_section_and_status($Sections,$enrollment,'b'); |
|
my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); |
|
my @Symbids = map { &get_symb_id($_); } @{$symbs}; |
|
# |
|
my $stats_table = $courseid.'_problem_stats'; |
|
my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids); |
|
my $request = 'DROP TABLE '.$stats_table; |
|
$dbh->do($request); |
|
$request = |
|
'CREATE TEMPORARY TABLE '.$stats_table.' '. |
|
'SELECT a.student_id,'. |
|
'SUM(a.awarded*w.weight) AS score FROM '. |
|
$performance_table.' AS a '. |
|
'NATURAL LEFT JOIN '.$weight_table.' AS w '. |
|
'LEFT JOIN '.$student_table.' AS b ON a.student_id=b.student_id '. |
|
'WHERE ('.$symb_restriction.')'; |
|
if ($time_limits) { |
|
$request .= ' AND '.$time_limits; |
|
} |
|
if ($section_limits) { |
|
$request .= ' AND '.$section_limits; |
|
} |
|
if ($enrollment_limits) { |
|
$request .= ' AND '.$enrollment_limits; |
|
} |
|
$request .= ' GROUP BY a.student_id'; |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
my $sth = $dbh->prepare($request); |
|
$sth->execute(); |
|
$request = |
|
'SELECT AVG(score),STD(score),MAX(score),MIN(score),COUNT(score) '. |
|
'FROM '.$stats_table; |
|
my ($ave,$std,$max,$min,$count) = &execute_SQL_request($dbh,$request); |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
|
|
$request = 'SELECT SUM(weight) FROM '.$weight_table. |
|
' WHERE ('.$symb_restriction.')'; |
|
my ($max_possible) = &execute_SQL_request($dbh,$request); |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
return($min,$max,$ave,$std,$count,$max_possible); |
|
} |
|
|
|
|
|
######################################################## |
|
######################################################## |
|
|
|
=pod |
|
|
|
=item &count_stats |
|
|
|
Inputs: $Sections, $enrollment, $symbs, $starttime, |
|
$endtime, $courseid |
|
|
|
$Sections, $enrollment, $starttime, $endtime, and $courseid are the same as |
|
elsewhere in this module. |
|
$symbs is an array ref of symbs |
|
|
|
Returns: minimum, maximum, mean, s.d., and number of students |
|
of the number of items correct on the given resources |
|
|
|
=cut |
|
|
|
######################################################## |
|
######################################################## |
|
sub count_stats { |
|
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
|
if (! defined($courseid)) { |
|
$courseid = $ENV{'request.course.id'}; |
|
} |
|
# |
|
&setup_table_names($courseid); |
|
my $dbh = &Apache::lonmysql::get_dbh(); |
|
# |
|
my ($section_limits,$enrollment_limits)= |
|
&limit_by_section_and_status($Sections,$enrollment,'b'); |
|
my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); |
|
my @Symbids = map { &get_symb_id($_); } @{$symbs}; |
|
# |
|
my $stats_table = $courseid.'_problem_stats'; |
|
my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids); |
|
my $request = 'DROP TABLE '.$stats_table; |
|
$dbh->do($request); |
|
$request = |
|
'CREATE TEMPORARY TABLE '.$stats_table.' '. |
|
'SELECT a.student_id,'. |
|
'COUNT(a.award) AS count FROM '. |
|
$performance_table.' AS a '. |
|
'LEFT JOIN '.$student_table.' AS b ON a.student_id=b.student_id '. |
|
'WHERE ('.$symb_restriction.')'. |
|
" AND a.award!='INCORRECT_ATTEMPTED'"; |
|
if ($time_limits) { |
|
$request .= ' AND '.$time_limits; |
|
} |
|
if ($section_limits) { |
|
$request .= ' AND '.$section_limits; |
|
} |
|
if ($enrollment_limits) { |
|
$request .= ' AND '.$enrollment_limits; |
|
} |
|
$request .= ' GROUP BY a.student_id'; |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
my $sth = $dbh->prepare($request); |
|
$sth->execute(); |
|
$request = |
|
'SELECT AVG(count),STD(count),MAX(count),MIN(count),COUNT(count) '. |
|
'FROM '.$stats_table; |
|
my ($ave,$std,$max,$min,$count) = &execute_SQL_request($dbh,$request); |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
return($min,$max,$ave,$std,$count); |
|
} |
|
|
###################################################### |
###################################################### |
###################################################### |
###################################################### |