Changes between Version 8 and Version 9 of BossaExampleOne


Ignore:
Timestamp:
Feb 12, 2008, 10:35:45 AM (17 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaExampleOne

    v8 v9  
    1919== Example application ==
    2020
    21 We'll create an application in which volunteers view images consisting of random rectangles,
    22 possibly with an ellipse superimposed.
     21We'll create an application in which volunteers view images,
     22looking for ellipses on a noisy background.
    2323Their task is to click on the center of the ellipse,
    2424or to indicate that there is no ellipse.
     
    3030
    3131Visit http://a.b.c/test_ops/bossa_ops.php,
    32 and create an application named "example",
    33 with display file "bossa_example.php"
    34 and backend file "bossa_example_backend.inc".
     32and create an application with short name "ellipse".
    3533
    3634== A script to generate jobs ==
    3735
    38 We'll need a program to generate jobs.
    39 This is done with a PHP script:
     36First, let's generate some jobs.
     37We'll do this with a PHP script, html/ops/bossa_test.php: copy this from
    4038[source:/trunk/boinc/html/ops/bossa_test.php html/ops/bossa_test.php].
    4139
     
    8078}}}
    8179
    82 This creates one job.
     80This function creates one job.
    8381It does the following:
    8482
    8583 * Choose a name for the job, and a name for the corresponding image file.
    86  * Decide where the file will go in the project's download hierarchy.
     84 * Decide where the file goes in the project's download hierarchy.
     85 * Generate a random case (ellipse presence and position)
    8786 * Create the image file.
    88  * Create a job record in the Bossa database.
     87 * Create a job record in the Bossa database.  Assign a time estimate (in seconds) and a time limit.  Store a description of the job, encoded in JSON, in the job record.
    8988
    9089Finally we have:
    9190{{{
    92 function make_jobs() {
     91function make_jobs($njobs) {
    9392    $c = get_config();
    9493    $config = null;
     
    9695    $config->download_url = parse_config($c, "<download_url>");
    9796    $config->uldl_dir_fanout = parse_config($c, "<uldl_dir_fanout>");
    98     $app = BossaApp::lookup_name("bossa_test");
     97    $app = BossaApp::lookup_name("Find the ellipse");
    9998    if (!$app) {
    10099        echo "Application $appname not found\n";
     
    102101    }
    103102    $batch = time();
    104     for ($i=0; $i<10; $i++) {
     103    for ($i=0; $i<$njobs; $i++) {
    105104        make_job($app, $batch, $i, $config);
    106105    }
    107 }
    108 
    109 if ($_GET['make_jobs']) {
    110     make_jobs();
     106    echo "Created $njobs jobs";
     107}
     108
     109$njobs = get_int('make_jobs', true);
     110if ($njobs) {
     111    make_jobs($njobs);
    111112} else {
    112113    header ("Content-type: image/png");
     
    116117
    117118'''make_jobs()''' parses the project configuration file,
    118 looks up the application in the database, and creates 10 jobs.
     119looks up the application in the database, and creates some jobs.
    119120You can invoke this by visiting
    120 '''http://a.b.c/test_ops/bossa_test.php?make_jobs'''.
     121'''http://a.b.c/test_ops/bossa_test.php?make_jobs=10'''.
    121122
    122123== Displaying jobs ==
    123124
    124 Next we'll need a script that displays a job and handles user input.
     125Next we'll need a script that displays a job to a volunteer,
     126and handles their response.
     127This uses a PHP script, html/user/ellipse_display.php: copy this from
     128[source:/trunk/boinc/html/user/bossa_example.php html/user/bossa_example.php].
    125129{{{
    126130function show_job($bj, $bji) {
     
    128132    $img_url = $info.url;
    129133    echo "
    130         <form method=get action=bossa_example.php>
     134        <form method=get action=ellipse_display.php>
    131135        Click on the center of the ellipse.
    132136        If you don't see one, click here:
     
    162166}}}
    163167
    164 == What volunteers see ==
     168The script calls '''Bossa::script_init()''' to get objects describing
     169the user, the job, and the job instance.
     170
     171'''show_job()''' decodes the job description to get the image URL,
     172and displays the image in an HTML page that
     173lets the user click on the image or on a "No ellipse" button.
     174
     175'''handle_job_completion()''' gets the user's response (from form variables).
     176It calls the '''completed()''' method of the job,
     177passing it a JSON encoding of the response.
     178I then calls '''Bossa::show_next_job()''' to immediately display another job.
    165179
    166180== Handling completed results ==
    167181
    168182Finally, we need to specify how results are handled.
    169 This is specified in "html/inc/bossa_example.inc".
    170 
    171 This defines two functions.
    172 The first defines a comparison of two results:
    173 {{{
    174 function example_compare($r1, $r2) {
     183This is specified in "html/inc/ellipse_handler.inc".
     184
     185This defines two functions, which must have names '''X_compare''' and '''X_handle'''
     186where X is the application's short name.
     187
     188The first function compares two instances and decides if they are compatible:
     189{{{
     190function ellipse_compare($r1, $r2) {
    175191    if ($r1->have_ellipse) {
    176192        if ($r2->have_ellipse) {
     
    185201}
    186202}}}
    187 
    188 The second function specifies what happens when a
    189 job has been completed, i.e. a consensus set has been found:
    190 {{{
    191 function handle_consensus($bj, $c) {
     203In this case, two instances are considered compatible if either
     204 * neither of them found an ellipse, or
     205 * they both found an ellipse and the centers are within 20 pixels
     206
     207The second function specifies what happens when a job has been completed,
     208i.e. a consensus set has been found:
     209{{{
     210function ellipse_handle($bj, $c) {
    192211    $res = $c[0];
    193212    if ($res->have_ellipse) {
     
    209228}}}
    210229
     230This function is called with the BossaJob record ($bj) and an
     231array of job instances in the consensus set ($c).
     232In this case, we average the center positions (if an ellipse was found)
     233and store the JSON-encoded result in the '''info''' field of the job record.