.
////// functions that traverse a unit tree
// get names of units of a given type
function units_of_type($unit, $type) {
$names = array();
if (get_class($unit) == $type) {
$names[] = $unit->name;
}
if (is_subclass_of($unit, "BoltSet")) {
foreach ($unit->units as $u) {
$n = units_of_type($u, $type);
$names = array_merge($names, $n);
}
}
return array_unique($names);
}
// show a menu of select units
//
function choose_select($top_unit) {
echo "";
}
// show a menu of exercise sets
//
function choose_xset($top_unit) {
echo "";
}
// Find a unit of given name
//
function lookup_unit($top_unit, $name) {
if ($top_unit->name == $name) return $top_unit;
if (is_subclass_of($top_unit, "BoltSet")) {
foreach ($top_unit->units as $child) {
$u = lookup_unit($child, $name);
if ($u) return $u;
}
}
return null;
}
////// bits of HTML for getting user info
function info_incomplete($user) {
if (!$user->bolt->birth_year) return true;
if (!$user->bolt->sex) return true;
return false;
}
function birth_year_select($user) {
$this_year = date("Y");
$x = "\n";
return $x;
}
function sex_select($user) {
$x = "\n";
return $x;
}
function request_info($user, $course) {
page_head("About you");
echo "
You may optionally tell us some facts about yourself.
This information will help us improve this course,
and will be kept private.
\n";
page_tail();
}
////// Statistics
// compute the mean and stdev of an array
//
function mean_stdev($array, &$mean, &$stdev) {
$n = 0;
$m = 0;
$m2 = 0;
foreach ($array as $x) {
$n++;
$delta = $x - $m;
$m += $delta/$n;
$m2 += $delta*($x-$m);
}
$mean = $m;
$stdev = sqrt($m2/($n-1));
}
// approximate the 90% confidence interval for the mean of an array
//
function conf_int_90($array, &$lo, &$hi) {
$n = count($array);
mean_stdev($array, $mean, $stdev);
// I'm too lazy to compute the t distribution
$t_90 = 1.7;
$d = $t_90 * $stdev / sqrt($n);
$lo = $mean - $d;
$hi = $mean + $d;
}
function test_stats() {
$a = array(1,1,1,1,0,1,1,1,3, 1, 1, 1, 1);
mean_stdev($a, $mean, $stdev);
echo "mean: $mean stdev: $stdev\n";
conf_int_90($a, $lo, $hi);
echo "lo $lo hi $hi\n";
}
//////////// graph drawing
function compare_bar($title, $n, $width, $lo, $hi) {
$x1 = $width*$lo;
$x2 = $width*($hi-$lo);
$a1 = number_format($lo*100);
$a2 = number_format($hi*100);
return "
$title ($n students)
$a1
$a2
";
}
function compare_bar_insuff($title, $width) {
return "
";
}
function show_refreshes() {
global $user;
global $course;
$refreshes = BoltRefreshRec::enum("user_id=$user->id and course_id=$course->id");
if (!count($refreshes)) return;
start_table();
echo "
Refresh schedule
\n";
foreach ($refreshes as $r) {
show_refresh($r);
}
end_table();
}
function bolt_style() {
echo "
";
}
?>