turkee 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +31 -17
- data/generators/turkee/turkee_generator.rb +1 -3
- metadata +4 -5
- data/generators/turkee/templates/turkee.js +0 -45
data/README.rdoc
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
== Description
|
1
|
+
== Turkee Description
|
2
2
|
|
3
|
-
|
3
|
+
Seamlessly convert your Rails forms for use on Mechanical Turk. Then, easily import the data posted by the Mechanical Turk workers back into your data models.
|
4
4
|
|
5
|
-
|
5
|
+
External forms are created using a simple form helper. HITs are created by issuing a rake command. Retrieving submitted response data and importing that data into your model(s) requires just one more rake command.
|
6
6
|
|
7
7
|
== Dependencies
|
8
8
|
|
9
|
-
Make sure that the rturk gem is installed
|
10
|
-
|
11
|
-
config.gem 'rturk'
|
12
|
-
|
13
|
-
...and configured with your Amazon Turk credentials. I created a config/initializers/turk_task_config.rb file with the following in it:
|
9
|
+
Make sure that the rturk gem is installed configured with your Amazon Turk credentials. I created a config/initializers/turk_task_config.rb file with the following in it:
|
14
10
|
|
15
11
|
TURKTASK_AWSACCESSKEYID = 'XXXXXXXXXXXXXXXXXX'
|
16
12
|
TURKTASK_AWSACCESSKEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|
@@ -31,25 +27,38 @@ And add it to your environment.rb configuration as a gem dependency:
|
|
31
27
|
To access the Turkee rake tasks, add the following to your application's Rakefile:
|
32
28
|
require 'tasks/turkee'
|
33
29
|
|
34
|
-
Run the turkee generator from your application directory to copy the needed
|
30
|
+
Run the turkee generator from your application directory to copy the needed migrations into your application:
|
35
31
|
|
36
32
|
./script/generate turkee # Rails 2
|
37
33
|
## Support for Rails 3 in the future.
|
38
34
|
|
39
35
|
== Use
|
40
36
|
|
41
|
-
1)
|
42
|
-
<%= javascript_include_tag :defaults, :turkee %>
|
43
|
-
* Turkee requires the default Rails javascript libraries, so be sure you are including those as well (as show above with :defaults).
|
44
|
-
2) Run your migrations :
|
37
|
+
1) Run your migrations :
|
45
38
|
|
46
39
|
rake db:migrate
|
47
40
|
|
41
|
+
2) You should disable form controls if the Turker hasn't accepted the HIT. You can determine this from your controller:
|
42
|
+
class SurveysController < ApplicationController
|
43
|
+
|
44
|
+
def new
|
45
|
+
@assignment_id = params[:assignmentId]
|
46
|
+
@disabled = Turkee::TurkeeFormHelper::disable_form_fields?(@assignment_id)
|
47
|
+
|
48
|
+
# If you wanted to find the associated turkee_task, you could do a find by hitId
|
49
|
+
# Not necessary in a simple example.
|
50
|
+
# @turkee_task = Turkee::TurkeeTask.find_by_hit_id(params[:hitId]).id rescue nil
|
51
|
+
|
52
|
+
...
|
53
|
+
@survey = Survey.new
|
54
|
+
end
|
55
|
+
|
48
56
|
3) Change your forms to use the form helper.
|
49
|
-
<% turkee_form_for @
|
50
|
-
|
51
|
-
|
57
|
+
<% turkee_form_for(@survey, @assignment_id) do |f| %>
|
58
|
+
<p><%= f.text_area :value, :disabled => @disabled %></p>
|
59
|
+
<p><%= f.submit 'Create', :disabled => @disabled %></p>
|
52
60
|
<% end %>
|
61
|
+
|
53
62
|
Using the turkee_form_for helper will post the form to the Mechanical Turk sandbox if you're in development/test mode, otherwise it will be posted to Mechanical Turk production/live site.
|
54
63
|
|
55
64
|
4) Run the following rake task to post to Mechanical Turk :
|
@@ -65,7 +74,9 @@ Using the turkee_form_for helper will post the form to the Mechanical Turk sandb
|
|
65
74
|
e.g. :
|
66
75
|
rake turkee:posthit ["Please complete our survey", "Tell us your favorite color.", "Survey", 100, 0.05, 2]
|
67
76
|
|
68
|
-
|
77
|
+
This will insert a row for the requested HIT into the turkee_tasks table. The turkee_tasks entry stores (among other things) the HIT URL and HIT ID (as returned from the Mechanical Turk API call).
|
78
|
+
|
79
|
+
5) Allow some time for the Mechanical Turk workers ("Turkers") to respond to your HIT.
|
69
80
|
|
70
81
|
6) Run the rake task that retrieves the values from Mechanical Turk and stores the user entered values into your model.
|
71
82
|
rake turkee::getresults
|
@@ -77,6 +88,9 @@ Rerun this task periodically to retrieve newly entered form values. You can set
|
|
77
88
|
# E.g. run every five minutes
|
78
89
|
*/5 * * * * cd /var/www/your/turk/application && rake turkee:getresults
|
79
90
|
|
91
|
+
Or you can directly call :
|
92
|
+
|
93
|
+
Turkee::TurkeeTask.process_hits
|
80
94
|
|
81
95
|
7) When a response is retrieved from Mechanical Turk, Turkee attempts to create a data row for the model specified using the corresponding retrieved data. If the row cannot be created (input failed model validations), the assignment is rejected.
|
82
96
|
As for Mechanical Turk approval, if the row is created and you haven't specified your own custom approve? method for the model, the assignment will automatically be approved. If you'd like to add your own custom approval method, add the approve? instance method to your model. E.g. :
|
@@ -2,8 +2,6 @@ class TurkeeGenerator < Rails::Generator::Base
|
|
2
2
|
|
3
3
|
def manifest
|
4
4
|
record do |m|
|
5
|
-
m.directory File.join('public', 'javascripts')
|
6
|
-
m.template 'turkee.js', File.join('public', 'javascripts', 'turkee.js')
|
7
5
|
m.migration_template "turkee_migration.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_tasks'
|
8
6
|
m.sleep 1 # Need this sleep so that we don't get the same migration timestamp for both migrations
|
9
7
|
m.migration_template "turkee_imported_assignments.rb.erb", File.join('db', 'migrate'), :migration_file_name => 'create_turkee_imported_assignments'
|
@@ -11,7 +9,7 @@ class TurkeeGenerator < Rails::Generator::Base
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def banner
|
14
|
-
%{Usage: #{$0} #{spec.name}\nCopies
|
12
|
+
%{Usage: #{$0} #{spec.name}\nCopies needed migrations to project.}
|
15
13
|
end
|
16
14
|
|
17
15
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turkee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Jones
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-19 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -77,7 +77,6 @@ extra_rdoc_files:
|
|
77
77
|
- README.rdoc
|
78
78
|
files:
|
79
79
|
- Rakefile
|
80
|
-
- generators/turkee/templates/turkee.js
|
81
80
|
- generators/turkee/templates/turkee_imported_assignments.rb.erb
|
82
81
|
- generators/turkee/templates/turkee_migration.rb.erb
|
83
82
|
- generators/turkee/turkee_generator.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
// Javascript referenced from the rturk example.
|
2
|
-
|
3
|
-
// Initializes a mechanical turk form and disables the form button
|
4
|
-
// until the user has accepted the turk task.
|
5
|
-
|
6
|
-
function gup( name )
|
7
|
-
{
|
8
|
-
var regexS = "[\\?&]"+name+"=([^&#]*)";
|
9
|
-
var regex = new RegExp( regexS );
|
10
|
-
var tmpURL = window.location.href;
|
11
|
-
var results = regex.exec( tmpURL );
|
12
|
-
if( results == null )
|
13
|
-
return "";
|
14
|
-
else
|
15
|
-
return results[1];
|
16
|
-
}
|
17
|
-
|
18
|
-
//
|
19
|
-
// This method decodes the query parameters that were URL-encoded
|
20
|
-
//
|
21
|
-
function decode(strToDecode)
|
22
|
-
{
|
23
|
-
var encoded = strToDecode;
|
24
|
-
return unescape(encoded.replace(/\+/g, " "));
|
25
|
-
}
|
26
|
-
|
27
|
-
function mturk_form_init(obj_name)
|
28
|
-
{
|
29
|
-
document.getElementById('assignmentId').value = gup('assignmentId');
|
30
|
-
|
31
|
-
//
|
32
|
-
// Check if the worker is PREVIEWING the HIT or if they've ACCEPTED the HIT
|
33
|
-
//
|
34
|
-
if (gup('assignmentId') == "ASSIGNMENT_ID_NOT_AVAILABLE")
|
35
|
-
{
|
36
|
-
// If we're previewing, disable the button and give it a helpful message
|
37
|
-
document.getElementById(obj_name + '_submit').disabled = true;
|
38
|
-
document.getElementById(obj_name + '_submit').value = "You must ACCEPT the HIT before you can submit the results.";
|
39
|
-
} else {
|
40
|
-
var form = document.getElementById('mturk_form');
|
41
|
-
if (document.referrer && ( document.referrer.indexOf('workersandbox') != -1) ) {
|
42
|
-
form.action = "https://workersandbox.mturk.com/mturk/externalSubmit";
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|