2008-02-11 23:38:31 +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/>.
|
2008-02-11 23:38:31 +00:00
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
require_once("../inc/bossa.inc");
|
2008-02-11 23:38:31 +00:00
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
// Bossa example #2.
|
|
|
|
// Show the user an image and ask them to click on the ellipse
|
|
|
|
// This version does replication;
|
|
|
|
// a job is considered done if either
|
|
|
|
// - 2 instances are positive and match within +- 20 pixels
|
|
|
|
// - 2 instances are negative
|
|
|
|
// - there are 10 finished instances
|
|
|
|
// (in which case the job is marked as inconclusive)
|
2008-02-11 23:38:31 +00:00
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
function job_show($job, $inst, $user) {
|
2008-07-30 21:37:41 +00:00
|
|
|
$info = $job->get_opaque_data($job);
|
2008-07-15 21:43:45 +00:00
|
|
|
$path = $info->path;
|
|
|
|
echo "
|
|
|
|
<h2>Find the Ellipse!</h2>
|
|
|
|
<form method=get action=bossa_job_finished.php>
|
|
|
|
Click on the center of the ellipse.
|
|
|
|
If you don't see one, click here:
|
|
|
|
<input type=submit name=submit value=None>
|
|
|
|
<br><br>
|
|
|
|
<input type=hidden name=bji value=$inst->id>
|
|
|
|
<input type=image name=pic src=$path>
|
|
|
|
</form>
|
|
|
|
";
|
2008-02-11 23:38:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
function job_issued($job, $inst, $user) {
|
|
|
|
$insts = $job->get_instances();
|
2008-07-30 02:16:10 +00:00
|
|
|
if (count($insts) == 1) {
|
|
|
|
$job->set_priority(2);
|
|
|
|
} else {
|
2008-07-15 21:43:45 +00:00
|
|
|
$job->set_priority(0);
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
function job_finished($job, $inst) {
|
2008-07-30 02:16:10 +00:00
|
|
|
// record the user's response
|
|
|
|
//
|
2008-07-15 21:43:45 +00:00
|
|
|
$response = null;
|
|
|
|
if (get_str('submit', true)) {
|
|
|
|
$response->have_ellipse = 0;
|
|
|
|
} else {
|
|
|
|
$response->have_ellipse = 1;
|
|
|
|
$response->cx = get_int('pic_x');
|
|
|
|
$response->cy = get_int('pic_y');
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
2008-07-30 21:37:41 +00:00
|
|
|
$inst->set_opaque_data($response);
|
2008-07-14 19:13:19 +00:00
|
|
|
|
2008-07-30 02:16:10 +00:00
|
|
|
// see whether we have a consensus
|
2008-07-15 21:43:45 +00:00
|
|
|
//
|
|
|
|
$insts = $job->get_finished_instances();
|
|
|
|
$n = count($insts);
|
2008-07-14 19:13:19 +00:00
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
$results = null;
|
|
|
|
foreach ($insts as $inst) {
|
2008-07-30 21:37:41 +00:00
|
|
|
$results[] = $inst->get_opaque_data();
|
2008-07-15 21:43:45 +00:00
|
|
|
}
|
|
|
|
for ($i=0; $i<$n-1; $i++) {
|
|
|
|
$r1 = $results[$i];
|
|
|
|
for ($j=$i+1; $j<$n; $j++) {
|
|
|
|
$r2 = $results[$j];
|
|
|
|
if (compatible($r1, $r2)) {
|
2008-07-30 21:37:41 +00:00
|
|
|
$job->set_state(BOSSA_JOB_DONE);
|
2008-07-15 21:43:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-30 02:16:10 +00:00
|
|
|
|
|
|
|
// no consensus - see whether we've reached replication limit
|
|
|
|
//
|
2008-07-17 20:58:42 +00:00
|
|
|
if ($n >= 10) {
|
2008-07-30 21:37:41 +00:00
|
|
|
$job->set_state(BOSSA_JOB_INCONCLUSIVE);
|
2008-07-17 20:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-07-30 02:16:10 +00:00
|
|
|
|
2008-07-30 21:37:41 +00:00
|
|
|
// still looking for consensus - get another instance
|
2008-07-30 02:16:10 +00:00
|
|
|
//
|
|
|
|
$job->set_priority(2);
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
// two results are compatible if neither found an ellipse,
|
|
|
|
// or they both did and centers are within 20 pixels
|
2008-07-14 19:13:19 +00:00
|
|
|
//
|
2008-07-15 21:43:45 +00:00
|
|
|
function compatible($r1, $r2) {
|
|
|
|
if ($r1->have_ellipse) {
|
|
|
|
if ($r2->have_ellipse) {
|
|
|
|
$dx = ($r1->cx - $r2->cx);
|
|
|
|
$dy = ($r1->cy - $r2->cy);
|
|
|
|
$dsq = $dx*$dx + $dy*$dy;
|
|
|
|
return ($dsq < 400);
|
|
|
|
} else return false;
|
|
|
|
} else {
|
|
|
|
return !$r2->have_ellipse;
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-15 21:43:45 +00:00
|
|
|
function job_timed_out($job, $inst, $user) {
|
2008-07-30 02:16:10 +00:00
|
|
|
$job->set_priority(2);
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 02:24:05 +00:00
|
|
|
function job_summary($job) {
|
2008-07-30 21:37:41 +00:00
|
|
|
$info = $job->get_opaque_data();
|
2008-07-21 16:25:03 +00:00
|
|
|
return "<a href=".URL_BASE."$info->path>View image</a>";
|
2008-07-15 21:43:45 +00:00
|
|
|
}
|
2008-07-14 19:13:19 +00:00
|
|
|
|
2009-04-10 23:36:32 +00:00
|
|
|
function instance_summary($info) {
|
2008-07-15 21:43:45 +00:00
|
|
|
if ($info->have_ellipse) {
|
2008-07-21 16:25:03 +00:00
|
|
|
return "ellipse ($info->cx, $info->cy)";
|
2008-07-14 19:13:19 +00:00
|
|
|
} else {
|
2008-07-21 16:25:03 +00:00
|
|
|
return "no ellipse";
|
2008-07-14 19:13:19 +00:00
|
|
|
}
|
2008-07-15 21:43:45 +00:00
|
|
|
}
|
2009-04-10 23:15:43 +00:00
|
|
|
|
|
|
|
function user_summary($user) {
|
|
|
|
return "";
|
|
|
|
}
|