| 1 | {{{ |
| 2 | function job_finished($job, $inst, $user) { |
| 3 | $response = null; |
| 4 | if (get_str('submit', true)) { |
| 5 | $response->have_ellipse = 0; |
| 6 | } else { |
| 7 | $response->have_ellipse = 1; |
| 8 | $response->cx = get_int('pic_x'); |
| 9 | $response->cy = get_int('pic_y'); |
| 10 | } |
| 11 | $inst->update_info($response); |
| 12 | |
| 13 | if ($job->calibration) { |
| 14 | $b = $user->bossa; |
| 15 | $info = $job->get_info(); |
| 16 | $answer = $info->answer; |
| 17 | $u = $b->get_info(); |
| 18 | if (!$u) { |
| 19 | $u->npos = 0; |
| 20 | $u->npos_err = 0; |
| 21 | $u->nneg = 0; |
| 22 | $u->nneg_err = 0; |
| 23 | } |
| 24 | if (compatible($response, $answer)) { |
| 25 | if ($answer->have_ellipse) { |
| 26 | $u->npos++; |
| 27 | } else { |
| 28 | $u->nneg++; |
| 29 | } |
| 30 | } else { |
| 31 | if ($answer->have_ellipse) { |
| 32 | $u->npos++; |
| 33 | $u->npos_err++; |
| 34 | } else { |
| 35 | $u->nneg++; |
| 36 | $u->nneg_err++; |
| 37 | } |
| 38 | } |
| 39 | $b->update_info($u); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // see if job is done |
| 44 | // |
| 45 | $insts = $job->get_finished_instances(); |
| 46 | $n = count($insts); |
| 47 | |
| 48 | $results = null; |
| 49 | $users = null; |
| 50 | foreach ($insts as $inst) { |
| 51 | $results[] = $inst->get_info(); |
| 52 | $u = $inst->get_user(); |
| 53 | $users[] = $u->bossa->get_info(); |
| 54 | } |
| 55 | |
| 56 | // see if there's a negative consensus |
| 57 | // |
| 58 | $prob = 1; |
| 59 | for ($i=0; $i<$n; $i++) { |
| 60 | $r = $results[$i]; |
| 61 | if ($r1->have_ellipse) continue; |
| 62 | $u = $users[$i]; |
| 63 | $prob *= $u->neg_err_rate; |
| 64 | } |
| 65 | if ($prob < PROB_LIMIT) { |
| 66 | $job->update_state(BOSSA_JOB_DONE); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | // see if there's a positive consensus |
| 71 | // |
| 72 | for ($i=0; $i<$n; $i++) { |
| 73 | $r1 = $results[$i]; |
| 74 | $u = $users[$i]; |
| 75 | $prob = $u->pos_error_rate; |
| 76 | for ($j=0; $j<$n; $j++) { |
| 77 | if ($j == $i) continue; |
| 78 | $r2 = $results[$j]; |
| 79 | if (compatible($r1, $r2)) { |
| 80 | $u2 = $users[$j]; |
| 81 | $prob *= $u2->pos_err_rate; |
| 82 | } |
| 83 | } |
| 84 | if ($prob < PROB_LIMIT) { |
| 85 | $job->update_state(BOSSA_JOB_DONE); |
| 86 | return; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // see if there are too many instances without a consensus |
| 91 | // |
| 92 | if ($n >= 10) { |
| 93 | $job->update_state(BOSSA_JOB_INCONCLUSIVE); |
| 94 | return; |
| 95 | } |
| 96 | } |
| 97 | }}} |
| 98 | |
| 99 | {{{ |
| 100 | function user_summary($user) { |
| 101 | $b = $user->bossa; |
| 102 | $info = $b->get_info(); |
| 103 | if ($info) { |
| 104 | if ($info->npos) { |
| 105 | $pos_err = $info->npos_err/$info->npos; |
| 106 | } else { |
| 107 | $pos_err = "---"; |
| 108 | } |
| 109 | if ($info->nneg) { |
| 110 | $neg_err = $info->nneg_err/$info->nneg; |
| 111 | } else { |
| 112 | $neg_err = "---"; |
| 113 | } |
| 114 | return "error rate: positive $pos_err ($info->npos_err/$info->npos), |
| 115 | negative $neg_err ($info->nneg_err/$info->nneg) |
| 116 | "; |
| 117 | } else { |
| 118 | return "No data"; |
| 119 | } |
| 120 | } |
| 121 | }}} |