2007-12-07 23:23:25 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-12-07 23:23:25 +00:00
|
|
|
|
2008-06-24 22:20:40 +00:00
|
|
|
////// 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 "<select name=select_name>
|
|
|
|
<option selected> ---
|
|
|
|
";
|
|
|
|
$names = units_of_type($top_unit, "BoltSelect");
|
|
|
|
foreach ($names as $n) {
|
|
|
|
echo "<option> $n";
|
|
|
|
}
|
|
|
|
echo "</select>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// show a menu of exercise sets
|
|
|
|
//
|
|
|
|
function choose_xset($top_unit) {
|
|
|
|
echo "<select name=xset_name>
|
|
|
|
<option selected> ---
|
|
|
|
";
|
|
|
|
$names = units_of_type($top_unit, "BoltExerciseSet");
|
|
|
|
foreach ($names as $n) {
|
|
|
|
echo "<option> $n";
|
|
|
|
}
|
|
|
|
echo "</select>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-06-20 21:33:02 +00:00
|
|
|
////// bits of HTML for getting user info
|
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
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 = "<select name=birth_year>\n";
|
|
|
|
for ($i=$this_year-100; $i<$this_year; $i++) {
|
|
|
|
$s = ($i == $user->bolt->birth_year)?"selected":"";
|
|
|
|
$x .= "<option value=$i $s>$i</option>\n";
|
|
|
|
}
|
|
|
|
$s = (!$user->bolt->birth_year)?"selected":"";
|
|
|
|
$x .= "<option value=$0 $s>Unspecified</option>\n";
|
|
|
|
$x .= "</select>\n";
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sex_select($user) {
|
|
|
|
$x = "<select name=sex>\n";
|
|
|
|
$s = ($user->bolt->sex == 0)?"selected":"";
|
|
|
|
$x .= "<option value=0 $s>Unspecified</option>\n";
|
|
|
|
$s = ($user->bolt->sex == 1)?"selected":"";
|
|
|
|
$x .= "<option value=1 $s>Male</option>\n";
|
|
|
|
$s = ($user->bolt->sex == 2)?"selected":"";
|
|
|
|
$x .= "<option value=2 $s>Female</option>\n";
|
|
|
|
$x .= "</select>\n";
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function request_info($user, $course) {
|
2008-02-13 19:54:54 +00:00
|
|
|
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.
|
|
|
|
<p>
|
|
|
|
<form action=bolt_sched.php>
|
2007-12-07 23:23:25 +00:00
|
|
|
<input type=hidden name=action value=update_info>
|
|
|
|
<input type=hidden name=course_id value=$course->id>
|
|
|
|
";
|
|
|
|
start_table();
|
|
|
|
row2("Birth year", birth_year_select($user));
|
|
|
|
row2("Sex", sex_select($user));
|
|
|
|
row2("", "<input type=submit value=OK>");
|
|
|
|
end_table();
|
|
|
|
echo "</form>\n";
|
|
|
|
page_tail();
|
|
|
|
}
|
|
|
|
|
2008-06-20 21:33:02 +00:00
|
|
|
////// 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";
|
|
|
|
}
|
|
|
|
|
2008-06-26 03:50:03 +00:00
|
|
|
//////////// graph drawing
|
|
|
|
|
2008-06-29 20:57:21 +00:00
|
|
|
function compare_bar($title, $n, $width, $lo, $hi) {
|
2008-06-26 03:50:03 +00:00
|
|
|
$x1 = $width*$lo;
|
|
|
|
$x2 = $width*($hi-$lo);
|
|
|
|
$a1 = number_format($lo*100);
|
|
|
|
$a2 = number_format($hi*100);
|
|
|
|
return "
|
|
|
|
<tr>
|
|
|
|
<td>$title<br><span class=note>($n students)</span></td>
|
|
|
|
<td>
|
|
|
|
<table class=bolt_bar width=$width><tr class=bolt_bar>
|
|
|
|
<td class=bolt_bar1 width=$x1 bgcolor=lightgray align=right>$a1</td>
|
|
|
|
<td class=bolt_bar2 width=$x2 bgcolor=black></td>
|
|
|
|
<td class=bolt_bar1 bgcolor=lightgray>$a2</td>
|
|
|
|
</tr></table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2008-06-29 20:57:21 +00:00
|
|
|
function compare_bar_insuff($title, $width) {
|
2008-06-26 03:50:03 +00:00
|
|
|
return "
|
|
|
|
<tr>
|
|
|
|
<td>$title</td>
|
|
|
|
<td>
|
|
|
|
<table class=bolt_bar width=$width><tr class=bolt_bar>
|
|
|
|
<td class=bolt_bar1 bgcolor=lightgray>Insufficient data</td>
|
|
|
|
</tr></table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:46:05 +00:00
|
|
|
function outcome_graph($x, $width) {
|
|
|
|
$n = $x[0]+$x[1]+$x[2];
|
|
|
|
if (!$n) return empty_cell();
|
2008-07-01 20:33:39 +00:00
|
|
|
$x0 = $width*$x[1]/$n;
|
|
|
|
$x1 = $width*$x[0]/$n;
|
2008-06-30 16:46:05 +00:00
|
|
|
$x2 = $width*$x[2]/$n;
|
2008-07-01 20:33:39 +00:00
|
|
|
if ($x[1]/$n>0.05) {
|
|
|
|
$t0 = number_format(100*$x[1]/$n)."%";
|
|
|
|
} else {
|
|
|
|
$t0 = "";
|
|
|
|
}
|
2008-08-15 22:07:24 +00:00
|
|
|
$s = "<td>
|
2008-06-30 16:46:05 +00:00
|
|
|
<table class=bolt_bar><tr>
|
2008-08-15 22:07:24 +00:00
|
|
|
";
|
|
|
|
if ($x0) {
|
|
|
|
$s .= "<td class=bolt_bar height=10 width=$x0 bgcolor=#88ff88><span class=note>$t0</span></td>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
if ($x1) {
|
|
|
|
$s .= "<td class=bolt_bar height=10 width=$x1 bgcolor=#ff8888><br></td>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
if ($x2) {
|
|
|
|
$s .= "<td class=bolt_bar height=10 width=$x2 bgcolor=#ffff88><br></td>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
$s .= "</tr></table>
|
2008-06-30 16:46:05 +00:00
|
|
|
</td>
|
|
|
|
";
|
2008-08-15 22:07:24 +00:00
|
|
|
return $s;
|
2008-06-27 23:15:57 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:46:05 +00:00
|
|
|
function time_graph($t, $w) {
|
2008-07-01 20:33:39 +00:00
|
|
|
if ($t == 0) return "<td>---</td>";
|
2008-06-30 16:46:05 +00:00
|
|
|
$x = (log10($t)+2)*$w/4;
|
2008-07-01 20:33:39 +00:00
|
|
|
$t = number_format($t, 1);
|
2008-06-30 16:46:05 +00:00
|
|
|
return "<td>
|
|
|
|
<table class=bolt_bar><tr>
|
2008-08-15 22:07:24 +00:00
|
|
|
<td class=bolt_bar height=10 width=$x bgcolor=#ffffcc><span class=note>$t sec</span></td>
|
2008-06-30 16:46:05 +00:00
|
|
|
</tr></table>
|
|
|
|
</td>";
|
2008-06-27 23:15:57 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:46:05 +00:00
|
|
|
function score_graph($t, $w) {
|
2008-07-01 20:33:39 +00:00
|
|
|
if ($t == 0) return "<td>---</td>";
|
2008-06-30 16:46:05 +00:00
|
|
|
$x = $t*$w;
|
|
|
|
$y = (1-$t)*$w;
|
2008-07-01 20:33:39 +00:00
|
|
|
$t = number_format($t*100);
|
2008-08-15 22:07:24 +00:00
|
|
|
$s = "<td>
|
2008-06-30 16:46:05 +00:00
|
|
|
<table class=bolt_bar><tr>
|
2008-08-15 22:07:24 +00:00
|
|
|
";
|
|
|
|
if ($x) {
|
|
|
|
$s .= "<td class=bolt_bar height=10 width=$x bgcolor=#ffffcc><span class=note>$t%</span></td>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
if ($y) {
|
|
|
|
$s .= "<td class=bolt_bar width=$y bgcolor=gray></td>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
$s .= "</tr></table></td>
|
|
|
|
";
|
|
|
|
return $s;
|
2008-06-27 23:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function empty_cell() {
|
|
|
|
return "<td><br></td>";
|
|
|
|
}
|
|
|
|
|
2008-08-15 22:07:24 +00:00
|
|
|
function empty_row() {
|
|
|
|
return "<tr><td><br></td></tr>";
|
|
|
|
}
|
|
|
|
|
2008-08-14 21:05:02 +00:00
|
|
|
//////////// show refresh schedule //////////////
|
|
|
|
|
|
|
|
function show_refresh($r) {
|
|
|
|
echo "<tr>
|
2008-08-21 23:24:11 +00:00
|
|
|
<td>$r->name</td>
|
|
|
|
<td>".time_str($r->due_time)."</td>
|
|
|
|
<td>
|
2008-10-20 21:19:13 +00:00
|
|
|
";
|
|
|
|
if ($r->last_view_id) {
|
|
|
|
echo "
|
|
|
|
<a href=bolt_sched.php?course_id=$r->course_id&refresh_id=$r->id&action=start>Restart</a>
|
2008-08-21 23:24:11 +00:00
|
|
|
| <a href=bolt_sched.php?course_id=$r->course_id&refresh_id=$r->id&action=resume>Resume</a>
|
2008-10-20 21:19:13 +00:00
|
|
|
";
|
|
|
|
} else {
|
|
|
|
echo "
|
|
|
|
<a href=bolt_sched.php?course_id=$r->course_id&refresh_id=$r->id&action=start>Start</a>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
echo "
|
2008-08-14 21:05:02 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2008-08-21 23:24:11 +00:00
|
|
|
echo "<tr><th colspan=3>Refresh schedule</th></tr>\n";
|
2008-08-14 21:05:02 +00:00
|
|
|
foreach ($refreshes as $r) {
|
|
|
|
show_refresh($r);
|
|
|
|
}
|
|
|
|
end_table();
|
|
|
|
}
|
|
|
|
|
2008-08-15 22:07:24 +00:00
|
|
|
function bolt_style() {
|
|
|
|
echo "
|
|
|
|
<link rel=\"stylesheet\" type=\"text/css\" href=\"".URL_BASE."bolt.css\">
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2007-12-07 23:23:25 +00:00
|
|
|
?>
|