Changes between Version 5 and Version 6 of BossaExampleOne


Ignore:
Timestamp:
Feb 11, 2008, 12:58:30 PM (17 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaExampleOne

    v5 v6  
    3030
    3131Visit http://a.b.c/test_ops/bossa_ops.php,
    32 and create an application named "test",
    33 with application file "test.php" (we'll create this later).
     32and create an application named "example",
     33with display file "bossa_example.php"
     34and backend file "bossa_example_backend.inc".
    3435
    3536== A script to generate jobs ==
     
    119120'''http://a.b.c/test_ops/bossa_test.php?make_jobs'''.
    120121
    121 
    122 
    123 == Create jobs ==
     122== Displaying jobs ==
     123
     124Next we'll need a script that displays a job and handles user input.
     125{{{
     126function show_job($bj, $bji) {
     127    $info = json_decode($bj->info);
     128    $img_url = $info.url;
     129    echo "
     130        <form method=get action=bossa_example.php>
     131        Click on the center of the ellipse.
     132        If you don't see one, click here:
     133        <br><br><input type=submit name=submit value=None>
     134        <input type=hidden name=bji value=$bji->id>
     135        <input type=hidden name=completion value=1>
     136        <input type=image name=pic src=$img_url>
     137        </form>
     138    ";
     139}
     140
     141function handle_job_completion($bj, $bji) {
     142    $response = null;
     143    if (get_str('submit', true)) {
     144        $response->have_ellipse = 0;
     145    } else {
     146        $response->have_ellipse = 1;
     147        $response->cx = get_int('pic.x');
     148        $response->cy = get_int('pic.y');
     149    }
     150    $bji->info = json_encode($response);
     151    $bji->completed($bj);
     152    Bossa::show_next_job($bj);    // show another job immediately
     153}
     154
     155Bossa::script_init($user, $bj, $bji);
     156
     157if (isset($_GET['completion'])) {
     158    handle_job_completion($bj, $bji);
     159} else {
     160    show_job($bj, $bji);
     161}
     162}}}
    124163
    125164== What volunteers see ==
    126165
    127 == View results ==
     166== Handling completed results ==
     167
     168Finally, we need to specify how results are handled.
     169This is specified in "html/inc/bossa_example.inc".
     170
     171This defines two functions.
     172The first defines a comparison of two results:
     173{{{
     174function compare($r1, $r2) {
     175    if ($r1->have_ellipse) {
     176        if ($r2->have_ellipse) {
     177            $dx = ($r1->cx - $r2->cx);
     178            $dy = ($r1->cy - $r2->cy);
     179            $dsq = $dx*$dx + $dy*$dy;
     180            return ($dsq < 400);
     181        } else return false;
     182    } else {
     183        return !$r2->have_ellipse;
     184    }
     185}
     186}}}
     187
     188The second function specifies what happens when a
     189job has been completed, i.e. a consensus set has been found:
     190{{{
     191function handle_consensus($bj, $c) {
     192    $res = $c[0];
     193    if ($res->have_ellipse) {
     194        $res->cx = 0;
     195        $res->cy = 0;
     196        foreach ($c as $r) {
     197            $res->cx += $r->cx;
     198            $res->cy += $r->cy;
     199        }
     200        $res->cx /= count($c);
     201        $res->cy /= count($c);
     202    }
     203
     204    $info = json_decode[$bj->info);
     205    $info->result = $res;
     206    $i = json_encode($info);
     207    $bj->update("info='$i'");
     208}
     209}}}
     210