mirror of https://github.com/BOINC/boinc.git
svn path=/trunk/boinc/; revision=15501
This commit is contained in:
parent
4e803d5e24
commit
37f0d8b6ef
|
@ -139,3 +139,10 @@ David Feb 22 2008
|
|||
bolt.inc
|
||||
ops/
|
||||
bolt_map.php
|
||||
|
||||
David June 26 2008
|
||||
- (a bunch of checkins recently)
|
||||
Added basic Unit Comparison feature, including
|
||||
- snapshots (makes it fast)
|
||||
- filtering and breakdown
|
||||
Also revisited Maps, and started redoing them along the same lines
|
||||
|
|
|
@ -181,7 +181,7 @@ class BoltResult {
|
|||
}
|
||||
static function enum($clause) {
|
||||
$db = BoltDb::get();
|
||||
return $db->enum('bolt_view', 'BoltResult', $clause);
|
||||
return $db->enum('bolt_result', 'BoltResult', $clause);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ function request_info($user, $course) {
|
|||
////// stuff related to snapshots
|
||||
|
||||
function compare_snapshot_filename($course_id, $select_name, $xset_name) {
|
||||
return "../bolt_snap/compare_snapshot_".$course_id."_".$select_name."_".$xset_name.".json";
|
||||
return "../bolt_snap/compare_snapshot_".$course_id."_".$select_name."_".$xset_name;
|
||||
}
|
||||
|
||||
// a "snapshot" is a condensed representation of the results
|
||||
|
@ -186,7 +186,7 @@ function write_compare_snapshot($course_id, $select_name, $xset_name, $dur) {
|
|||
$s->recs = $a;
|
||||
$s->dur = $dur;
|
||||
$s->time = $now;
|
||||
fwrite($f, json_encode($s));
|
||||
fwrite($f, serialize($s));
|
||||
fclose($f);
|
||||
return $s;
|
||||
}
|
||||
|
@ -197,12 +197,12 @@ function read_compare_snapshot($course_id, $select_name, $xset_name) {
|
|||
if (!$f) return null;
|
||||
$x = fread($f, filesize($filename));
|
||||
fclose($f);
|
||||
return json_decode($x);
|
||||
return unserialize($x);
|
||||
}
|
||||
|
||||
|
||||
function map_snapshot_filename($course_id) {
|
||||
return "../bolt_snap/map_snapshot_".$course_id.".json";
|
||||
return "../bolt_snap/map_snapshot_".$course_id;
|
||||
}
|
||||
|
||||
// a "map snapshot" is:
|
||||
|
@ -216,12 +216,13 @@ function write_map_snapshot($course_id, $dur) {
|
|||
$start = $now - $dur*86400;
|
||||
|
||||
$views = array();
|
||||
$results = array();
|
||||
$xset_results = array();
|
||||
$users = array();
|
||||
|
||||
$vs = BoltView::enum("course_id=$course_id and create_time>$start");
|
||||
$vs = BoltView::enum("course_id=$course_id and start_time>$start");
|
||||
foreach ($vs as $v) {
|
||||
if (array_key_exists($v->item_name), $views) {
|
||||
if (array_key_exists($v->item_name, $views)) {
|
||||
$x = $views[$v->item_name];
|
||||
$x[] = $v;
|
||||
$views[$v->item_name] = $x;
|
||||
|
@ -237,7 +238,7 @@ function write_map_snapshot($course_id, $dur) {
|
|||
|
||||
$rs = BoltResult::enum("course_id=$course_id and create_time>$start");
|
||||
foreach ($rs as $r) {
|
||||
if (array_key_exists($r->item_name), $results) {
|
||||
if (array_key_exists($r->item_name, $results)) {
|
||||
$x = $results[$r->item_name];
|
||||
$x[] = $r;
|
||||
$results[$r->item_name] = $x;
|
||||
|
@ -253,15 +254,15 @@ function write_map_snapshot($course_id, $dur) {
|
|||
|
||||
$xrs = BoltXsetResult::enum("course_id=$course_id and create_time>$start");
|
||||
foreach ($xrs as $xr) {
|
||||
if (array_key_exists($xr->item_name), $xset_results) {
|
||||
$x = $xset_results[$xr->item_name];
|
||||
if (array_key_exists($xr->name, $xset_results)) {
|
||||
$x = $xset_results[$xr->name];
|
||||
$x[] = $xr;
|
||||
$xset_results[$xr->item_name] = $x;
|
||||
$xset_results[$xr->name] = $x;
|
||||
} else {
|
||||
$xset_results[$xr->item_name] = array($xr);
|
||||
$xset_results[$xr->name] = array($xr);
|
||||
}
|
||||
if (!array_key_exists($xr->user_id, $users)) {
|
||||
$user = BoincUser::lookup_id($r->user_id);
|
||||
$user = BoincUser::lookup_id($xr->user_id);
|
||||
BoltUser::lookup($user);
|
||||
$users[$v->user_id] = $user;
|
||||
}
|
||||
|
@ -277,18 +278,19 @@ function write_map_snapshot($course_id, $dur) {
|
|||
|
||||
$filename = map_snapshot_filename($course_id);
|
||||
$f = fopen($filename, "w");
|
||||
fwrite($f, json_encode($y));
|
||||
fwrite($f, serialize($y));
|
||||
fclose($f);
|
||||
|
||||
return $y;
|
||||
}
|
||||
|
||||
function read_map_snapshot() {
|
||||
$filename = map_snapshot_filename($course_id, $select_name, $xset_name);
|
||||
function read_map_snapshot($course_id) {
|
||||
$filename = map_snapshot_filename($course_id);
|
||||
$f = @fopen($filename, "r");
|
||||
if (!$f) return null;
|
||||
$x = fread($f, filesize($filename));
|
||||
fclose($f);
|
||||
return json_decode($x);
|
||||
return unserialize($x);
|
||||
}
|
||||
|
||||
////// Statistics
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
// show a map;
|
||||
// show form to set or change filter or breakdown
|
||||
|
||||
require_once("../util.inc");
|
||||
require_once("../inc/util.inc");
|
||||
require_once("../inc/bolt_db.inc");
|
||||
require_once("../inc/bolt_cat.inc");
|
||||
require_once("../inc/bolt_util.inc");
|
||||
require_once("../inc/bolt.inc");
|
||||
|
||||
function show_snap_form() {
|
||||
|
@ -46,25 +47,72 @@ function show_snap_form() {
|
|||
}
|
||||
|
||||
function snap_action() {
|
||||
global $course_id;
|
||||
$dur = get_int('dur');
|
||||
$s = write_map_snapshot($course_id, $dur);
|
||||
map_aux($select_name, $xset_name, $s);
|
||||
global $course_id;
|
||||
global $top_unit;
|
||||
|
||||
$dur = get_int('dur');
|
||||
$s = write_map_snapshot($course_id, $dur);
|
||||
show_map();
|
||||
}
|
||||
|
||||
function map_aux($snap) {
|
||||
function show_unit($snap, $unit) {
|
||||
$class = get_class($unit);
|
||||
echo "<li> $unit->name ($class); ";
|
||||
if ($unit->is_item) {
|
||||
if (array_key_exists($unit->name, $snap->views)) {
|
||||
$n = count($snap->views[$unit->name]);
|
||||
} else {
|
||||
$n = 0;
|
||||
}
|
||||
echo "$n views";
|
||||
}
|
||||
if ($class == "BoltExercise") {
|
||||
if (array_key_exists($unit->name, $snap->results)) {
|
||||
$rs = $snap->results[$unit->name];
|
||||
$sum = 0;
|
||||
$n = count($rs);
|
||||
foreach ($rs as $r) {
|
||||
$sum += $r->score;
|
||||
}
|
||||
$avg = $sum/$n;
|
||||
echo " avg score: $avg ($n)";
|
||||
}
|
||||
}
|
||||
if ($class == "BoltExerciseSet") {
|
||||
if (array_key_exists($unit->name, $snap->xset_results)) {
|
||||
$xrs = $snap->xset_results[$unit->name];
|
||||
$sum = 0;
|
||||
$n = count($xrs);
|
||||
foreach ($xrs as $xr) {
|
||||
$sum += $xr->score;
|
||||
}
|
||||
$avg = $sum/$n;
|
||||
echo " avg score: $avg ($n)";
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
function show_map($unit, $level) {
|
||||
for ($i=0; $i<$level; $i++) echo ' ';
|
||||
echo "$unit->name: $unit->nviews\n";
|
||||
function show_unit_recurse($snap, $unit) {
|
||||
show_unit($snap, $unit);
|
||||
if ($unit->is_item) return;
|
||||
foreach ($unit->units as $u) {
|
||||
show_map($u, $level+1);
|
||||
echo "<ul>\n";
|
||||
show_unit_recurse($snap, $u);
|
||||
echo "</ul>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function show_map() {
|
||||
global $course_id;
|
||||
global $top_unit;
|
||||
|
||||
page_head("Course map");
|
||||
$snap = read_map_snapshot($course_id);
|
||||
show_unit_recurse($snap, $top_unit);
|
||||
page_tail();
|
||||
}
|
||||
|
||||
$course_id = get_int('course_id');
|
||||
$course = BoltCourse::lookup_id($course_id);
|
||||
if (!$course) error_page("no course");
|
||||
|
@ -79,7 +127,7 @@ case "snap_action":
|
|||
snap_action();
|
||||
break;
|
||||
case "map":
|
||||
show_map($top_unit, 0);
|
||||
show_map();
|
||||
break;
|
||||
default:
|
||||
error_page("Unknown action $action");
|
||||
|
|
Loading…
Reference in New Issue