= 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: [[Image(bossa_test.png, nolink)]] (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/: * [source:/trunk/boinc/html/ops/bossa_example_make_files.php ops/bossa_example_make_files.php]: a script that creates image files. * [source:/trunk/boinc/html/ops/bossa_example_make_jobs.php ops/bossa_example_make_jobs.php]: a script that creates jobs. * [source:/trunk/boinc/html/inc/bossa_example.inc inc/bossa_example.inc]: the application's callback functions. 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
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 "path>View image"; 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 } }}}