| 3 | | == Creating a Bossa project == |
| 4 | | |
| 5 | | First, [ServerIntro set up a BOINC server] and [MakeProject create a project]. |
| 6 | | You'll need PHP 5.2 or later (for JSON functions). |
| 7 | | Say your project is called '''test_project''', your BOINC source directory is '''~/boinc''', |
| 8 | | and your BOINC projects directory is '''~/projects'''. |
| 9 | | |
| 10 | | Create Bossa's database tables as follows: |
| 11 | | {{{ |
| 12 | | cd ~/boinc/db |
| 13 | | mysql test_project < bossa_schema.sql |
| 14 | | mysql test_project < bossa_constraints.sql |
| 15 | | }}} |
| 16 | | |
| 17 | | Create a Bossa application (see below) as follows: |
| 18 | | {{{ |
| 19 | | cd ~/projects/test_project/html/ops |
| 20 | | php bossa_setup_example.php |
| 21 | | }}} |
| 22 | | |
| 23 | | bossa_setup_example.php contains: |
| 24 | | {{{ |
| 25 | | $ba = new BossaApp(); |
| 26 | | $ba->name = 'bossa_test'; |
| 27 | | $ba->user_friendly_name = 'Simple pattern recognition'; |
| 28 | | $ba->start_url = 'bossa_example.php'; |
| 29 | | |
| 30 | | if ($ba->insert($ba)) { |
| 31 | | echo "Added application '$ba->name'\n"; |
| 32 | | } else { |
| 33 | | echo "Couldn't add '$ba->name': ", mysql_error(), "\n"; |
| 34 | | } |
| 35 | | }}} |
| 36 | | You can edit this to change the application name |
| 37 | | and front-end script name, if you like. |
| | 59 | |
| | 60 | == Creating a Bossa project == |
| | 61 | |
| | 62 | First, [ServerIntro set up a BOINC server] and [MakeProject create a project]. |
| | 63 | You'll need PHP 5.2 or later (for JSON functions). |
| | 64 | Say your project is called '''test_project''', your BOINC source directory is '''~/boinc''', |
| | 65 | and your BOINC projects directory is '''~/projects'''. |
| | 66 | |
| | 67 | Create Bossa's database tables as follows: |
| | 68 | {{{ |
| | 69 | cd ~/boinc/db |
| | 70 | mysql test_project < bossa_schema.sql |
| | 71 | mysql test_project < bossa_constraints.sql |
| | 72 | }}} |
| | 73 | |
| | 74 | Create a Bossa application (see below) as follows: |
| | 75 | {{{ |
| | 76 | cd ~/projects/test_project/html/ops |
| | 77 | php bossa_setup_example.php |
| | 78 | }}} |
| | 79 | |
| | 80 | bossa_setup_example.php contains: |
| | 81 | {{{ |
| | 82 | $ba = new BossaApp(); |
| | 83 | $ba->name = 'bossa_test'; |
| | 84 | $ba->user_friendly_name = 'Simple pattern recognition'; |
| | 85 | $ba->start_url = 'bossa_example.php'; |
| | 86 | |
| | 87 | if ($ba->insert($ba)) { |
| | 88 | echo "Added application '$ba->name'\n"; |
| | 89 | } else { |
| | 90 | echo "Couldn't add '$ba->name': ", mysql_error(), "\n"; |
| | 91 | } |
| | 92 | }}} |
| | 93 | You can edit this to change the application name |
| | 94 | and front-end script name, if you like. |
| | 95 | |
| | 96 | == Adding jobs == |
| 97 | | == Adding jobs == |
| | 100 | You develop a '''front-end script''' to show a job instance to a user, |
| | 101 | and to handle a completed instance. |
| | 102 | It's handy to put both of these functions in a single file. |
| | 103 | A front-end script is called with the URL parameter '''bji''' set |
| | 104 | to a job instance ID. |
| | 105 | Here's an example: |
| | 106 | |
| | 107 | {{{ |
| | 108 | 1 <?php |
| | 109 | 2 |
| | 110 | 3 require_once("../inc/bossa.inc"); |
| | 111 | 4 |
| | 112 | 5 echo "foo"; |
| | 113 | 6 |
| | 114 | 7 // Bossa example. |
| | 115 | 8 // Show the user an image and ask them whether it's a zero or one. |
| | 116 | 9 |
| | 117 | 10 function show_job($bj, $bji) { |
| | 118 | 11 if ($bji->finish_time) { |
| | 119 | 12 error_page("You already finished this job"); |
| | 120 | 13 } |
| | 121 | 14 $info = json_decode($bj->info); |
| | 122 | 15 $img_url = "http://boinc.berkeley.edu/images/number_".$info->number.".jpg"; |
| | 123 | 16 echo " |
| | 124 | 17 <form method=get action=bossa_example.php> |
| | 125 | 18 <input type=hidden name=bji value=$bji->id> |
| | 126 | 19 <img src=$img_url> |
| | 127 | 20 <br> |
| | 128 | 21 The picture shows a |
| | 129 | 22 <br><input type=radio name=response value=0> zero |
| | 130 | 23 <br><input type=radio name=response value=1> one |
| | 131 | 24 <br><input type=radio name=response value=2 checked> not sure |
| | 132 | 25 <br><br><input type=submit name=submit value=OK> |
| | 133 | 26 </form> |
| | 134 | 27 "; |
| | 135 | 28 } |
| | 136 | 29 |
| | 137 | 30 function handle_job_completion($bj, $bji) { |
| | 138 | 31 $response = null; |
| | 139 | 32 $response->number = get_int('response'); |
| | 140 | 33 $bji->info = json_encode($response); |
| | 141 | 34 $bji->completed($bj); |
| | 142 | 35 |
| | 143 | 36 // show another job immediately |
| | 144 | 37 // |
| | 145 | 38 Bossa::show_next_job($bj); |
| | 146 | 39 } |
| | 147 | 40 |
| | 148 | 41 Bossa::script_init($user, $bj, $bji); |
| | 149 | 42 |
| | 150 | 43 if ($_GET['submit']) { |
| | 151 | 44 handle_job_completion($bj, $bji); |
| | 152 | 45 } else { |
| | 153 | 46 show_job($bj, $bji); |
| | 154 | 47 } |
| | 155 | 48 |
| | 156 | 49 ?> |
| | 157 | }}} |
| | 158 | |
| | 159 | Line 41:: |
| | 160 | Call a Bossa utility function to look up the job instance and make sure that it was issued to the logged-in user. The job instance, job, and user are returned. |
| | 161 | Line 43:: |
| | 162 | Branch according to whether we are showing a job or handling the completion of a job. |
| | 163 | |