Greasy Fork

Shined up real nice.

MTurk Worst Case Scenario Calculator

Shows what your approval rate would be in worst case scenario

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// ==UserScript==
// @name        MTurk Worst Case Scenario Calculator
// @namespace   localhost
// @author      ThirdClassInternationalMasterTurker
// @description Shows what your approval rate would be in worst case scenario
// @include     https://www.mturk.com/mturk/dashboard
// @version     3.1
// @grant       none
// ==/UserScript==

//
// 2012-09-07 First public release by ThirdClassInternationalMasterTurker
//
// 2012-09-09 Added approximate number of rejects that drop you to the
//            edge of RATE_GOOD and RATE_OK
//
// 2012-10-06 Added GUI for setting RATE_GOOD and RATE_OK
//            (Click 'Pending (Worst Case Scenario)')
//
// 2012-12-02 3.1: Added @downloadURL and @updateURL
//

// --- SETTINGS ------------------------------------------------------- //
var RATE_GOOD = (localStorage['WCS_GOOD']) ? localStorage['WCS_GOOD'] : 99.0;
var RATE_OK   = (localStorage['WCS_OK']) ? localStorage['WCS_OK'] : 95.0;

var COLOUR_GOOD    = 'lightgreen';
var COLOUR_OK      = 'orange';
var COLOUR_BAD     = 'red';

// -------------------------------------------------------------------- //

var rows = document.evaluate('//tr[@class]',
           document,
           null,
           XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 

var submitted;
var returned;
var abandoned;
var approved;
var rejected;
var pending;

function config_func()
{
  return function()
  {
    var t = prompt('MTurk Worst Case Scenario\nSet your RATE_GOOD and RATE_OK.\nFor example: 99.0;95.0',
                    '' + RATE_GOOD + ';' + RATE_OK);
    if (!t)
      return;

    var rates = t.split(';', 2);
    rates[0] = parseFloat(rates[0]).toFixed(1);
    rates[1] = parseFloat(rates[1]).toFixed(1);
    
    if (rates[0] > 0 && rates[0] <= 100)
      localStorage['WCS_GOOD'] = rates[0];
    if (rates[1] > 0 && rates[1] <= 100)
      localStorage['WCS_OK'] = rates[1];
  };  
}


for (var i=0;i<rows.snapshotLength;i++) {
  var row = rows.snapshotItem(i);

  if (row.cells.length != 3)
    continue;
  if (row.className.match('odd|even') == null) {
    continue;
  }

  if (row.cells[0].textContent.match('HITs Submitted')) {
    submitted = parseInt(row.cells[1].textContent);
  }

  if (row.cells[0].textContent.match('\\.\\.\\. Approved')) {
    approved = parseInt(row.cells[1].textContent);
    approved_p = parseFloat(row.cells[2].textContent);

    if (approved_p >= RATE_GOOD) {
      row.cells[2].style.backgroundColor = COLOUR_GOOD;
    }
    else if (approved_p >= RATE_OK) {
      row.cells[2].style.backgroundColor = COLOUR_OK;
    }
    else {
      row.cells[2].style.backgroundColor = COLOUR_BAD;
    }
  }

  if (row.cells[0].textContent.match('\\.\\.\\. Rejected')) {
    rejected = parseInt(row.cells[1].textContent);
  }

  if (row.cells[0].textContent.match('\\.\\.\\. Pending')) {
    pending = parseInt(row.cells[1].textContent);

    row.cells[0].innerHTML += " <small>(Worst Case Scenario)</small>";

    if (RATE_GOOD < approved_p) {
      var p = 1.0 - RATE_GOOD/100;
      var x = (rejected-(p*submitted))/(p-1);
      row.cells[0].innerHTML += "<br>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:" + COLOUR_OK + "\">(~" + Math.round(x) + " rejects => " + RATE_GOOD + "%)</span>";
    }
    if (RATE_OK < approved_p) {
      var p = 1.0 - RATE_OK/100;
      var x = (rejected-(p*submitted))/(p-1);
      row.cells[0].innerHTML += "<br>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:" + COLOUR_BAD + "\">(~" + Math.round(x) + " rejects => " + RATE_OK + "%)</span>";
    }

    WCS = Math.round((approved/(approved+rejected+pending) * 1000))/10;
    row.cells[2].innerHTML = '(' + WCS + '%)';

    if (WCS >= RATE_GOOD) {
      row.cells[2].style.backgroundColor = COLOUR_GOOD;
    }
    else if (WCS >= RATE_OK) {
      row.cells[2].style.backgroundColor = COLOUR_OK;
    }
    else {
      row.cells[2].style.backgroundColor = COLOUR_BAD;
    }

    row.cells[0].addEventListener("click", config_func(), false);
    row.cells[2].addEventListener("click", config_func(), false);
  }
}