Changes between Version 14 and Version 15 of BossaExampleOne


Ignore:
Timestamp:
Jul 18, 2008, 8:42:20 PM (16 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaExampleOne

    v14 v15  
    3535The application is define by three scripts in ~/projects/test/html/:
    3636
    37  * '''ops/bossa_example_workgen.php''': this generates more jobs.
    38  * '''user/bossa_example.php''': show a job, and handle user response.
    39  * '''inc/bossa_example.inc''': compare and handle completed jobs.
     37 * '''ops/bossa_example_make_files.php''': this creates image files.
     38 * '''ops/bossa_example_make_jobs.php''': this creates jobs.
     39 * '''inc/bossa_example.inc''': display jobs and handle completed jobs.
    4040
    4141We'll go through these scripts and explain how they work.
    4242To develop your own Bossa applications you'll need to write corresponding scripts.
    4343
    44 == A script to generate jobs ==
     44== Creating jobs ==
    4545
    46 First, let's generate some jobs.
    47 We'll do this with a PHP script, [source:/trunk/boinc/html/ops/bossa_example_workgen.php html/ops/bossa_example_workgen.php].
     46To create some jobs, first we'll create some image files using the script
     47[source:/trunk/boinc/html/ops/bossa_example_make_files.php html/ops/bossa_example_make_files.php].
    4848
    49 The first part of this script is code for generating an image;
    50 the key functions are '''make_test_case()''',
    51 which generates a structure saying if and where there's an ellipse,
    52 and '''make_image()''', which generates an image given this info.
    53 
    54 Next we have
    5549{{{
    56 function make_job($app, $batch, $i, $config) {
    57     // create the image file;
    58     // store it in the download directory hierarchy
    59     //
    60     $jobname = "job_$batch_$i";
    61     $case = make_test_case();
    62     $filename = "$jobname.png";
    63     $path = dir_hier_path(
    64         $filename, $config->download_dir, $config->uldl_dir_fanout
    65     );
    66     $url = dir_hier_url(
    67         $filename, $config->download_url, $config->uldl_dir_fanout
    68     );
    69     imagepng(make_image($case), $path);
    70     $case->url = $url;
    71 
    72     // make a job record in the Bossa database
    73     //
    74     $job = new BossaJob;
    75     $job->app_id = $app->id;
    76     $job->batch = $batch;
    77     $job->time_estimate = 30;
    78     $job->time_limit = 600;
    79     $job->name = $jobname;
    80     $job->info = json_encode($case);
    81 
    82     if (!$job->insert()) {
    83         echo "BossaJob::insert failed: ", mysql_error(), "\n";
    84         exit(1);
    85     }
    86 }
     50cd ~/projects/test/html/ops
     51mkdir ../user/example
     52php bossa_example_make_files.php --nfiles 10 --dir example
    8753}}}
    8854
    89 This function creates one job, as follows:
     55This creates (in the '''examples/''' directory) 10 image files
     56'''0.png''' to '''9.png''',
     57and corresponding "answer" files '''0.ans''' to '''9.ans'''.
     58Roughly half the images will have ellipses
     59(you can specify this probability with '''--ellipse_frac x''').
    9060
    91  * Choose a name for the job, and a name for the corresponding image file.
    92  * Decide where the file goes in the project's download hierarchy.
    93  * Generate a random case (ellipse presence and position)
    94  * Create the image file.
    95  * 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.
    96 
    97 Finally we have:
     61Now, create jobs using
     62[source:/trunk/boinc/html/ops/bossa_example_make_jobs.php html/ops/bossa_example_make_jobs.php].
    9863{{{
    99 function make_jobs($njobs) {
    100     $c = get_config();
    101     $config = null;
    102     $config->download_dir = parse_config($c, "<download_dir>");
    103     $config->download_url = parse_config($c, "<download_url>");
    104     $config->uldl_dir_fanout = parse_config($c, "<uldl_dir_fanout>");
    105     $app = BossaApp::lookup_name("Find the ellipse");
    106     if (!$app) {
    107         echo "Application $appname not found\n";
    108         exit(1);
    109     }
    110     $batch = time();
    111     for ($i=0; $i<$njobs; $i++) {
    112         make_job($app, $batch, $i, $config);
    113     }
    114     echo "Created $njobs jobs";
    115 }
    116 
    117 $njobs = get_int('make_jobs', true);
    118 if ($njobs) {
    119     make_jobs($njobs);
    120 } else {
    121     header ("Content-type: image/png");
    122     imagepng(make_image(make_test_case()));
    123 }
     64php bossa_example_make_jobs --app_name bossa_example --dir example
    12465}}}
    12566
    126 '''make_jobs()''' parses the project configuration file,
    127 looks up the application in the database, and creates some jobs.
    128 You can invoke this by visiting
    129 '''http://a.b.c/test_ops/bossa_example_workgen.php?make_jobs=10'''
    130 (or use the link on the http://a.b.c/test_ops/bossa_ops.php).
     67This makes 10 jobs (one for each image in the directory)
     68and collects them into a "batch".
    13169
    13270== Displaying jobs ==