Changes between Version 8 and Version 9 of BossaExampleOne
- Timestamp:
- Feb 12, 2008, 10:35:45 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BossaExampleOne
v8 v9 19 19 == Example application == 20 20 21 We'll create an application in which volunteers view images consisting of random rectangles,22 possibly with an ellipse superimposed.21 We'll create an application in which volunteers view images, 22 looking for ellipses on a noisy background. 23 23 Their task is to click on the center of the ellipse, 24 24 or to indicate that there is no ellipse. … … 30 30 31 31 Visit 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". 32 and create an application with short name "ellipse". 35 33 36 34 == A script to generate jobs == 37 35 38 We'll need a program to generate jobs.39 This is done with a PHP script: 36 First, let's generate some jobs. 37 We'll do this with a PHP script, html/ops/bossa_test.php: copy this from 40 38 [source:/trunk/boinc/html/ops/bossa_test.php html/ops/bossa_test.php]. 41 39 … … 80 78 }}} 81 79 82 This creates one job.80 This function creates one job. 83 81 It does the following: 84 82 85 83 * 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) 87 86 * 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. 89 88 90 89 Finally we have: 91 90 {{{ 92 function make_jobs( ) {91 function make_jobs($njobs) { 93 92 $c = get_config(); 94 93 $config = null; … … 96 95 $config->download_url = parse_config($c, "<download_url>"); 97 96 $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"); 99 98 if (!$app) { 100 99 echo "Application $appname not found\n"; … … 102 101 } 103 102 $batch = time(); 104 for ($i=0; $i< 10; $i++) {103 for ($i=0; $i<$njobs; $i++) { 105 104 make_job($app, $batch, $i, $config); 106 105 } 107 } 108 109 if ($_GET['make_jobs']) { 110 make_jobs(); 106 echo "Created $njobs jobs"; 107 } 108 109 $njobs = get_int('make_jobs', true); 110 if ($njobs) { 111 make_jobs($njobs); 111 112 } else { 112 113 header ("Content-type: image/png"); … … 116 117 117 118 '''make_jobs()''' parses the project configuration file, 118 looks up the application in the database, and creates 10jobs.119 looks up the application in the database, and creates some jobs. 119 120 You 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'''. 121 122 122 123 == Displaying jobs == 123 124 124 Next we'll need a script that displays a job and handles user input. 125 Next we'll need a script that displays a job to a volunteer, 126 and handles their response. 127 This 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]. 125 129 {{{ 126 130 function show_job($bj, $bji) { … … 128 132 $img_url = $info.url; 129 133 echo " 130 <form method=get action= bossa_example.php>134 <form method=get action=ellipse_display.php> 131 135 Click on the center of the ellipse. 132 136 If you don't see one, click here: … … 162 166 }}} 163 167 164 == What volunteers see == 168 The script calls '''Bossa::script_init()''' to get objects describing 169 the user, the job, and the job instance. 170 171 '''show_job()''' decodes the job description to get the image URL, 172 and displays the image in an HTML page that 173 lets 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). 176 It calls the '''completed()''' method of the job, 177 passing it a JSON encoding of the response. 178 I then calls '''Bossa::show_next_job()''' to immediately display another job. 165 179 166 180 == Handling completed results == 167 181 168 182 Finally, 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) { 183 This is specified in "html/inc/ellipse_handler.inc". 184 185 This defines two functions, which must have names '''X_compare''' and '''X_handle''' 186 where X is the application's short name. 187 188 The first function compares two instances and decides if they are compatible: 189 {{{ 190 function ellipse_compare($r1, $r2) { 175 191 if ($r1->have_ellipse) { 176 192 if ($r2->have_ellipse) { … … 185 201 } 186 202 }}} 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) { 203 In 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 207 The second function specifies what happens when a job has been completed, 208 i.e. a consensus set has been found: 209 {{{ 210 function ellipse_handle($bj, $c) { 192 211 $res = $c[0]; 193 212 if ($res->have_ellipse) { … … 209 228 }}} 210 229 230 This function is called with the BossaJob record ($bj) and an 231 array of job instances in the consensus set ($c). 232 In this case, we average the center positions (if an ellipse was found) 233 and store the JSON-encoded result in the '''info''' field of the job record.