Changes between Version 4 and Version 5 of BossaExampleOne


Ignore:
Timestamp:
Feb 11, 2008, 12:13:25 PM (16 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BossaExampleOne

    v4 v5  
    1717Visit http://a.b.c/test/create_account.php and create an account for yourself.
    1818
    19 == Create an application ==
     19== Example application ==
    2020
    21 We'll create an application where volunteers view images consisting of random rectangles,
     21We'll create an application in which volunteers view images consisting of random rectangles,
    2222possibly with an ellipse superimposed.
    2323Their task is to click on the center of the ellipse,
    2424or to indicate that there is no ellipse.
    25 
    26 Here's an example image:
     25Here's an example:
    2726
    2827[[Image(bossa_test.png, nolink)]]
     
    3433with application file "test.php" (we'll create this later).
    3534
     35== A script to generate jobs ==
     36
     37We'll need a program to generate jobs.
     38This is done with a PHP script:
     39[source:/trunk/html/ops/bossa_test.php html/ops/bossa_test.php].
     40
     41The first part of this script is code for generating an image;
     42the key functions are '''make_test_case()''',
     43which generates a structure saying if and where there's an ellipse,
     44and '''make_image()''', which generates an image given this info.
     45
     46Next we have
     47{{{
     48function make_job($app, $batch, $i, $config) {
     49    // create the image file;
     50    // store it in the download directory hierarchy
     51    //
     52    $jobname = "job_$batch_$i";
     53    $case = make_test_case();
     54    $filename = "$jobname.png";
     55    $path = dir_hier_path(
     56        $filename, $config->download_dir, $config->uldl_dir_fanout
     57    );
     58    $url = dir_hier_url(
     59        $filename, $config->download_url, $config->uldl_dir_fanout
     60    );
     61    imagepng(make_image($case), $path);
     62    $case->url = $url;
     63
     64    // make a job record in the Bossa database
     65    //
     66    $job = new BossaJob;
     67    $job->app_id = $app->id;
     68    $job->batch = $batch;
     69    $job->time_estimate = 30;
     70    $job->time_limit = 600;
     71    $job->name = $jobname;
     72    $job->info = json_encode($case);
     73
     74    if (!$job->insert()) {
     75        echo "BossaJob::insert failed: ", mysql_error(), "\n";
     76        exit(1);
     77    }
     78}
     79}}}
     80
     81This creates one job.
     82It does the following:
     83
     84 * Choose a name for the job, and a name for the corresponding image file.
     85 * Decide where the file will go in the project's download hierarchy.
     86 * Create the image file.
     87 * Create a job record in the Bossa database.
     88
     89Finally we have:
     90{{{
     91function make_jobs() {
     92    $c = get_config();
     93    $config = null;
     94    $config->download_dir = parse_config($c, "<download_dir>");
     95    $config->download_url = parse_config($c, "<download_url>");
     96    $config->uldl_dir_fanout = parse_config($c, "<uldl_dir_fanout>");
     97    $app = BossaApp::lookup_name("bossa_test");
     98    if (!$app) {
     99        echo "Application $appname not found\n";
     100        exit(1);
     101    }
     102    $batch = time();
     103    for ($i=0; $i<10; $i++) {
     104        make_job($app, $batch, $i, $config);
     105    }
     106}
     107
     108if ($_GET['make_jobs']) {
     109    make_jobs();
     110} else {
     111    header ("Content-type: image/png");
     112    imagepng(make_image(make_test_case()));
     113}
     114}}}
     115
     116'''make_jobs()''' parses the project configuration file,
     117looks up the application in the database, and creates 10 jobs.
     118You can invoke this by visiting
     119'''http://a.b.c/test_ops/bossa_test.php?make_jobs'''.
     120
     121
     122
    36123== Create jobs ==
    37124