wiki:BossaExampleOne

Version 30 (modified by davea, 13 years ago) (diff)

--

Example 1: the basics

In this application volunteers view synthetic images, looking for ellipses on a noisy background. Their task is to click on the center of the ellipse, or to indicate that there is no ellipse. Here's an example image:

(there's an ellipse slightly below/left of center).

We'll assume you've created a Bossa project at http://a.b.c/test/. Visit http://a.b.c/test_ops/bossa_admin.php, and create an application with short name "bossa_example".

The application is implemented by three scripts in ~/projects/test/html/:

We'll go through these scripts and explain how they work. To develop your own Bossa applications you'll need to write corresponding scripts.

Creating jobs

First we'll create some image files using bossa_example_make_files.php.

cd ~/projects/test/html/ops
mkdir ../user/example
php bossa_example_make_files.php --nfiles 10 --dir example

This creates (in the examples/ directory) 10 image files 0.png to 9.png, and corresponding "answer" files 0.ans to 9.ans. Roughly half the images will have ellipses (you can specify this probability with --ellipse_frac x).

Now, create jobs using bossa_example_make_jobs.php:

php bossa_example_make_jobs.php --app_name bossa_example --dir example

This makes 10 jobs (one for each image in the directory) and collects them into a "batch".

Callback functions

The display function is:

     9  function job_show($job, $inst, $user) {
    10      $info = $job->get_opaque_data($job);
    11      $path = $info->path;
    12      page_head("Find the Ellipse");
    13      echo "
    14          <form method=get action=bossa_job_finished.php>
    15          Click on the center of the ellipse.
    16          If you don't see one, click here:
    17          <input type=submit name=submit value=None>
    18          <br><br>
    19          <input type=hidden name=bji value=$inst->id>
    20          <input type=image name=pic src=$path>
    21          </form>
    22      ";
    23      page_tail();
    24  }

This calls a Bossa API function to get the job's opaque data (line 10). Then it generates a web page containing the image within a form, so that clicking on the image (or on the None button) will invoke bossa_job_finished.php.

    26  function job_issued($job, $inst, $user) {
    27      $job->set_priority(0);
    28  }

This is called when a job is issued. It sets the job's priority to zero so that no other instances will be issued until further notice.

    30  function job_finished($job, $inst) {
    31      $response = null;
    32      if (get_str('submit', true)) {
    33          $response->have_ellipse = 0;
    34      } else {
    35          $response->have_ellipse = 1;
    36          $response->cx = get_int('pic_x');
    37          $response->cy = get_int('pic_y');
    38      }
    39      $inst->set_opaque_data($response);
    40  }

This is called when an instance is finished. It gets the user's response to the job, and stores it as the instance's opaque data.

    42  function job_timed_out($job, $inst, $user) {
    43      $job->set_priority(1);
    44  }

This is called when a job times out. It restores the priority to one so that the job will be issued to another volunteer.

The remaining functions return short strings that summarize the opaque data for jobs, instances, and users on the Admin page:

    46  function job_summary($job) {
    47      $info = $job->get_opaque_data();
    48      return "<a href=".URL_BASE."$info->path>View image</a>";
    49  }
    50
    51  function instance_summary($inst) {
    52      $info = $inst->get_opaque_data();
    53      if ($info->have_ellipse) {
    54          return "($info->cx, $info->cy)";
    55      } else {
    56          return "no ellipse";
    57      }
    58  }
    59
    60  function show_user_summary($user) {
    61  }

Attachments (1)

Download all attachments as: .zip