cloudfactory 0.6 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +0 -3
- data/lib/cf/badge.rb +22 -109
- data/lib/cf/cli.rb +5 -11
- data/lib/cf/cli/line.rb +42 -23
- data/lib/cf/cli/templates/sample-line/line.yml.erb +0 -2
- data/lib/cf/help.txt +0 -13
- data/lib/cf/human_worker.rb +65 -13
- data/lib/cf/station.rb +58 -12
- data/lib/cf/version.rb +1 -1
- data/spec/badges_spec.rb +337 -237
- data/spec/custom_task_form_spec.rb +2 -2
- data/spec/human_worker_spec.rb +5 -131
- data/spec/line_spec.rb +5 -7
- data/spec/task_form_spec.rb +18 -1
- data/spec/text_appending_robot_spec.rb +5 -4
- metadata +51 -54
- data/lib/cf/cli/badge.rb +0 -234
- data/lib/cf/cli/badge_yaml_validator.rb +0 -25
- data/lib/cf/cli/templates/sample-line/badge.yml +0 -21
data/lib/cf/station.rb
CHANGED
@@ -179,26 +179,32 @@ module CF
|
|
179
179
|
number = worker_instance.number
|
180
180
|
reward = worker_instance.reward
|
181
181
|
stat_badge = worker_instance.stat_badge
|
182
|
-
|
183
|
-
|
184
|
-
request =
|
185
|
-
{
|
186
|
-
:body =>
|
182
|
+
if stat_badge.nil?
|
183
|
+
request =
|
187
184
|
{
|
188
|
-
:
|
189
|
-
|
190
|
-
|
191
|
-
|
185
|
+
:body =>
|
186
|
+
{
|
187
|
+
:api_key => CF.api_key,
|
188
|
+
:worker => {:number => number, :reward => reward, :type => "HumanWorker"}
|
189
|
+
}
|
192
190
|
}
|
193
|
-
|
194
|
-
|
191
|
+
else
|
192
|
+
request =
|
193
|
+
{
|
194
|
+
:body =>
|
195
|
+
{
|
196
|
+
:api_key => CF.api_key,
|
197
|
+
:worker => {:number => number, :reward => reward, :type => "HumanWorker"},
|
198
|
+
:stat_badge => stat_badge
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
195
202
|
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}/workers.json",request)
|
196
203
|
worker = CF::HumanWorker.new({})
|
197
204
|
worker.id = resp.parsed_response['id']
|
198
205
|
worker.number = resp.parsed_response['number']
|
199
206
|
worker.reward = resp.parsed_response['reward']
|
200
207
|
worker.stat_badge = resp.parsed_response['stat_badge']
|
201
|
-
worker.badges = resp.parsed_response['badges']
|
202
208
|
if resp.code != 200
|
203
209
|
worker.errors = resp.parsed_response['error']['message']
|
204
210
|
end
|
@@ -367,5 +373,45 @@ module CF
|
|
367
373
|
def gold_standards=(gold_standard) # :nodoc:
|
368
374
|
@gold_standards << gold_standard
|
369
375
|
end
|
376
|
+
|
377
|
+
#specify the badges for the station
|
378
|
+
# ===Usage Example:
|
379
|
+
# CF::Badge.new({:line => line, :station => s,:name => "Tomb Digitizer", :description => "This badge qualifies you to work on tomb digitization tasks.",:max_badges => 100,:gold_standards => ["#{@gold_standard.settings[:name]}"],:test_attributes =>{:type => "default",:retries => 10,:pass_percentage => 100,:check_manually => true}})
|
380
|
+
def badges badge = nil
|
381
|
+
line_title = line["title"] || line.title
|
382
|
+
if badge
|
383
|
+
if badge.settings[:test_attributes] && badge.settings[:test_attributes][:form_attributes].present?
|
384
|
+
form = badge.settings[:test_attributes][:form_attributes]
|
385
|
+
if( form[:type] == "CustomTaskForm" && form[:file])
|
386
|
+
raw_html = ""
|
387
|
+
File.open("#{form[:file]}").each_line do |line|
|
388
|
+
raw_html += line
|
389
|
+
end
|
390
|
+
badge.settings[:test_attributes][:form_attributes].merge!({:raw_html => raw_html,:_type =>"CustomTaskForm"})
|
391
|
+
end
|
392
|
+
badge.settings[:test_attributes][:form_attributes].merge!({:_type =>"TaskForm"}) if form[:type] == "TaskForm"
|
393
|
+
end
|
394
|
+
request =
|
395
|
+
{
|
396
|
+
:body =>
|
397
|
+
{
|
398
|
+
:api_key => CF.api_key,
|
399
|
+
:badge => badge.settings
|
400
|
+
}
|
401
|
+
}
|
402
|
+
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{line_title.downcase}/stations/#{self.index}/badges.json",request)
|
403
|
+
badge = CF::Badge.new()
|
404
|
+
badge.settings.merge!(resp.to_hash)
|
405
|
+
self.errors = resp.parsed_response['error']['message'] if resp.code != 200
|
406
|
+
@badges << badge
|
407
|
+
else
|
408
|
+
@badges
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
def badges=(badge)
|
413
|
+
@badges << badge
|
414
|
+
end
|
415
|
+
|
370
416
|
end
|
371
417
|
end
|
data/lib/cf/version.rb
CHANGED
data/spec/badges_spec.rb
CHANGED
@@ -1,242 +1,342 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CF::Badge do
|
4
|
-
context "
|
5
|
-
it " in
|
4
|
+
context "add a badge" do
|
5
|
+
it "should add a badge to the station in DSL way" do
|
6
6
|
WebMock.allow_net_connect!
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
|
26
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
27
|
-
}
|
28
|
-
]
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "in plain ruby way" do
|
33
|
-
WebMock.allow_net_connect!
|
34
|
-
@badge = CF::Badge.new(
|
35
|
-
:name => "Bizcard Digitizer_plain",
|
36
|
-
:description => "this badge qualifies the worker for bizcard digitization",
|
37
|
-
:max_badge_assignments => 100,
|
38
|
-
:retries_allowed => 5,
|
39
|
-
:pass_percentage => 80,
|
40
|
-
:assignment_duration => 3600,
|
41
|
-
:allow_retake_after => 5,
|
42
|
-
:check_manually =>false,
|
43
|
-
:form => "./lib/cf/cli/templates/sample-line/form.html",
|
44
|
-
:known_answers=>
|
45
|
-
[
|
46
|
-
{ "name" => "chandra",
|
47
|
-
"input"=> {"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
48
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"1"}}
|
49
|
-
},
|
50
|
-
{
|
51
|
-
"name" => "mohan",
|
52
|
-
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
53
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
54
|
-
}
|
55
|
-
]
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
it " with standard task form" do
|
60
|
-
WebMock.allow_net_connect!
|
61
|
-
@badge = CF::Badge.create(
|
62
|
-
:name => "Bizcard Digitizer_standard_form",
|
63
|
-
:description => "this badge qualifies the worker for bizcard digitization",
|
64
|
-
:max_badge_assignments => 100,
|
65
|
-
:retries_allowed => 5,
|
66
|
-
:pass_percentage => 80,
|
67
|
-
:assignment_duration => 3600,
|
68
|
-
:allow_retake_after => 5,
|
69
|
-
:check_manually =>false,
|
70
|
-
:form => {:title => "standard task form", :instruction => "Describe me"},
|
71
|
-
:known_answers=>
|
72
|
-
[
|
73
|
-
{ "name" => "chandra",
|
74
|
-
"input"=> {"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
75
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"1"}}
|
76
|
-
},
|
77
|
-
{
|
78
|
-
"name" => "mohan",
|
79
|
-
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
80
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
81
|
-
}
|
82
|
-
]
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
context "create a badge without" do
|
89
|
-
before(:each) do
|
90
|
-
WebMock.allow_net_connect!
|
91
|
-
@badge_hash = {
|
92
|
-
:name => "Bizcard Digitizer#{Time.new.strftime('%Y%b%d-%H%M%S')}",
|
93
|
-
:description => "this badge qualifies the worker for bizcard digitization",
|
94
|
-
:max_badge_assignments => 100,
|
95
|
-
:retries_allowed => 5,
|
96
|
-
:pass_percentage => 80,
|
97
|
-
:assignment_duration => 3600,
|
98
|
-
:allow_retake_after => 5,
|
99
|
-
:check_manually =>false,
|
100
|
-
:form => "./lib/cf/cli/templates/sample-line/form.html",
|
101
|
-
:known_answers=>
|
102
|
-
[
|
103
|
-
{ "name" => "chandra",
|
104
|
-
"input"=> {"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
105
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"1"}}
|
106
|
-
},
|
107
|
-
{
|
108
|
-
"name" => "mohan",
|
109
|
-
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
110
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
111
|
-
}
|
112
|
-
]
|
113
|
-
}
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
it "name should give error 'Name can't be blank'" do
|
118
|
-
@badge_hash.delete(:name)
|
119
|
-
badge = CF::Badge.new(@badge_hash)
|
120
|
-
badge.errors.should eql(["Name can't be blank"])
|
121
|
-
end
|
122
|
-
|
123
|
-
it "form should raise error 'Test is invalid'" do
|
124
|
-
@badge_hash.delete(:form)
|
125
|
-
badge = CF::Badge.new(@badge_hash)
|
126
|
-
badge.errors.should eql(["Test is invalid"])
|
127
|
-
end
|
128
|
-
|
129
|
-
it "known_answers should raise error 'You have not provided known answers for the badge'" do
|
130
|
-
@badge_hash.delete(:known_answers)
|
131
|
-
badge = CF::Badge.new(@badge_hash)
|
132
|
-
badge.errors.should eql("You have not provided known answers for the badge.")
|
133
|
-
end
|
134
|
-
|
135
|
-
it "form with different file type" do
|
136
|
-
@badge_hash[:form] = "./lib/cf/cli/templates/sample-line/badge.yml"
|
137
|
-
badge = CF::Badge.new(@badge_hash)
|
138
|
-
badge.errors.should eql(["Wrong type of file for the form."])
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
context "#update" do
|
144
|
-
before(:each) do
|
145
|
-
WebMock.allow_net_connect!
|
146
|
-
@badge = CF::Badge.create(
|
147
|
-
:name => "Bizcard Digitizer",
|
148
|
-
:description => "this badge qualifies the worker for bizcard digitization",
|
149
|
-
:max_badge_assignments => 100,
|
150
|
-
:retries_allowed => 5,
|
151
|
-
:pass_percentage => 80,
|
152
|
-
:assignment_duration => 3600,
|
153
|
-
:allow_retake_after => 5,
|
154
|
-
:check_manually =>false,
|
155
|
-
:form => "./lib/cf/cli/templates/sample-line/form.html",
|
156
|
-
:known_answers=>
|
157
|
-
[
|
158
|
-
{ "name" => "chandra",
|
159
|
-
"input"=> {"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
160
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"1"}}
|
161
|
-
},
|
162
|
-
{
|
163
|
-
"name" => "mohan",
|
164
|
-
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
165
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
166
|
-
}
|
167
|
-
]
|
168
|
-
)
|
169
|
-
|
170
|
-
@badge_hash = {
|
171
|
-
:name => "Bizcard Digitizer_updated",
|
172
|
-
:description => "this badge qualifies the worker for bizcard digitization for next level",
|
173
|
-
:max_badge_assignments => 80,
|
174
|
-
:retries_allowed => 0,
|
175
|
-
:pass_percentage => 10,
|
176
|
-
:assignment_duration => 300,
|
177
|
-
:allow_retake_after => 2,
|
178
|
-
:check_manually => true,
|
179
|
-
:form => "./lib/cf/cli/templates/sample-line/form.html",
|
180
|
-
:known_answers=>
|
181
|
-
[
|
182
|
-
{
|
183
|
-
"name" => "updated",
|
184
|
-
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
185
|
-
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"2"}}
|
186
|
-
}
|
187
|
-
]
|
188
|
-
}
|
189
|
-
end
|
190
|
-
|
191
|
-
it "in block DSl Way" do
|
192
|
-
badge = CF::Badge.update("Bizcard Digitizer", @badge_hash)
|
193
|
-
badge["name"].should eql("bizcard-digitizer_updated")
|
194
|
-
badge["description"].should eql("this badge qualifies the worker for bizcard digitization for next level")
|
195
|
-
badge["max_badge_assignments"].should eql(80)
|
196
|
-
badge["test"]["retries"].should eql(0)
|
197
|
-
badge["test"]["check_manually"].should eql(true)
|
198
|
-
badge["test"]["pass_percentage"].should eql(10)
|
199
|
-
badge["test"]["known_answers"].should eql(1)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "in absence of form should raise error" do
|
203
|
-
@badge_hash.delete(:form)
|
204
|
-
badge = CF::Badge.update(@badge.name, @badge_hash)
|
205
|
-
badge["error"]["message"].should eql("Badge #{@badge.name.parameterize} can not be updated beacuse {:test=>[\"is invalid\"]}")
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
|
210
|
-
context "#list" do
|
211
|
-
it "should list all badges" do
|
212
|
-
WebMock.allow_net_connect!
|
213
|
-
badge = CF::Badge.list
|
214
|
-
badge["code"].should eql(200)
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should list specific badge" do
|
218
|
-
WebMock.allow_net_connect!
|
219
|
-
badge_list = CF::Badge.list("bizcard-digitizer_updated")
|
220
|
-
badge_list["badges"].first["name"].should eql("bizcard-digitizer_updated")
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "#delete" do
|
225
|
-
it "a specific badge" do
|
226
|
-
WebMock.allow_net_connect!
|
227
|
-
badge = CF::Badge.destroy("bizcard-digitizer_updated")
|
228
|
-
badge["code"].should eql(200)
|
229
|
-
CF::Badge.list("bizcard-digitizer_updated")["error"]["message"].should eql("No badge to list")
|
230
|
-
end
|
7
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
8
|
+
sleep 1
|
9
|
+
line = CF::Line.create(title,"Digitization") do |l|
|
10
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
11
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
12
|
+
end
|
13
|
+
station = CF::Station.create({:line => line, :type => "work"}) do |s|
|
14
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
15
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
16
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
17
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
18
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
19
|
+
end
|
20
|
+
@gold_standard = CF::GoldStandard.new({ :line => line,
|
21
|
+
:station => s,
|
22
|
+
:name => "easy_#{Time.now}",
|
23
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
24
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
25
|
+
})
|
231
26
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
27
|
+
@badge = CF::Badge.create({
|
28
|
+
:line => line,
|
29
|
+
:station => s,
|
30
|
+
:name => "Tomb Digitizer#{Time.now.day}",
|
31
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
32
|
+
:max_badges => 100,
|
33
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
34
|
+
:test_attributes =>
|
35
|
+
{
|
36
|
+
:type => "default",
|
37
|
+
:retries => 10,
|
38
|
+
:pass_percentage => 100,
|
39
|
+
:check_manually => true
|
40
|
+
}
|
41
|
+
})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should reuse the badge with in the account and badge to the station in DSL way" do
|
46
|
+
WebMock.allow_net_connect!
|
47
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
48
|
+
sleep 1
|
49
|
+
line = CF::Line.create(title,"Digitization") do |l|
|
50
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
51
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
52
|
+
end
|
53
|
+
station = CF::Station.create({:line => line, :type => "work"}) do |s|
|
54
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
55
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
56
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
57
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
58
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
59
|
+
end
|
60
|
+
@gold_standard = CF::GoldStandard.new({ :line => line,
|
61
|
+
:station => s,
|
62
|
+
:name => "easy_#{Time.now}",
|
63
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
64
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
65
|
+
})
|
66
|
+
|
67
|
+
@badge = CF::Badge.create({
|
68
|
+
:line => line,
|
69
|
+
:station => s,
|
70
|
+
:name => "timromero#{Time.now.day}",
|
71
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
72
|
+
:max_badges => 100,
|
73
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
74
|
+
:test_attributes =>
|
75
|
+
{
|
76
|
+
:type => "default",
|
77
|
+
:retries => 10,
|
78
|
+
:pass_percentage => 100,
|
79
|
+
:check_manually => true
|
80
|
+
}
|
81
|
+
})
|
82
|
+
|
83
|
+
@badge = CF::Badge.create({
|
84
|
+
:line => line,
|
85
|
+
:station => s,
|
86
|
+
:name => "Tomb Digitizer#{Time.now.day}"
|
87
|
+
})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it "should add a badge to the station in plain ruby way" do
|
93
|
+
WebMock.allow_net_connect!
|
94
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
95
|
+
sleep 1
|
96
|
+
@line = CF::Line.create(title,"Digitization") do |l|
|
97
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
98
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
99
|
+
end
|
100
|
+
station = CF::Station.create({:line => @line, :type => "work"}) do |s|
|
101
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
102
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
103
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
104
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
105
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
106
|
+
end
|
107
|
+
@gold_standard = CF::GoldStandard.new({ :line => @line,
|
108
|
+
:station => s,
|
109
|
+
:name => "easy",
|
110
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
111
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
112
|
+
})
|
113
|
+
end
|
114
|
+
badge = CF::Badge.new({
|
115
|
+
:name => "Tomb Digitizereee#{Time.now}",
|
116
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
117
|
+
:max_badges => 100,
|
118
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
119
|
+
:test_attributes =>
|
120
|
+
{
|
121
|
+
:type => "default",
|
122
|
+
:retries => 10,
|
123
|
+
:pass_percentage => 100,
|
124
|
+
:check_manually => false
|
125
|
+
}
|
126
|
+
})
|
127
|
+
|
128
|
+
@line.stations.first.badges badge
|
129
|
+
badge1 = CF::Badge.new({
|
130
|
+
:name => "timromero#{Time.now.day}"
|
131
|
+
})
|
132
|
+
@line.stations.first.badges badge1
|
133
|
+
@line.stations.first.badges.count.should eql(2)
|
134
|
+
@line.stations.first.badges.last.settings["name"].should eql("timromero#{Time.now.day}")
|
135
|
+
@line.stations.first.badges.first.settings["name"].should eq(badge.settings[:name])
|
136
|
+
@line.stations.first.badges.first.settings['test']["form"].should eql({"_type"=>"TaskForm", "form_fields"=>[{"label"=>"First Name", "field_type"=>"short_answer", "required"=>true, "position"=>1}, {"label"=>"Middle Name", "field_type"=>"short_answer", "position"=>2}, {"label"=>"Last Name", "field_type"=>"short_answer", "required"=>true, "position"=>3}], "instruction"=>"Describe", "title"=>"Enter text from a business card image"})
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
it "should add a badge to the station with test form defined in DSL way" do
|
142
|
+
WebMock.allow_net_connect!
|
143
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
144
|
+
sleep 1
|
145
|
+
line = CF::Line.create(title,"Digitization") do |l|
|
146
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
147
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
148
|
+
end
|
149
|
+
station = CF::Station.create({:line => line, :type => "work"}) do |s|
|
150
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
151
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
152
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
153
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
154
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
155
|
+
end
|
156
|
+
@gold_standard = CF::GoldStandard.new({ :line => line,
|
157
|
+
:station => s,
|
158
|
+
:name => "easy_#{Time.now}",
|
159
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
160
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
161
|
+
})
|
162
|
+
|
163
|
+
@badge = CF::Badge.new({
|
164
|
+
:line => line,
|
165
|
+
:station => s,
|
166
|
+
:name => "Tomb Digitizer#{Time.now}",
|
167
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
168
|
+
:max_badges => 100,
|
169
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
170
|
+
:test_attributes =>
|
171
|
+
{
|
172
|
+
:type => "default",
|
173
|
+
:retries => 10,
|
174
|
+
:pass_percentage => 100,
|
175
|
+
:check_manually => true,
|
176
|
+
:form_attributes => {
|
177
|
+
:title => "Tombfinder Test",
|
178
|
+
:instruction => "Look at the image of the tomb in the url given and answer the asked questions.",
|
179
|
+
:type => "TaskForm",
|
180
|
+
:form_fields_attributes =>
|
181
|
+
[
|
182
|
+
{ "label" => "Last Name", "field_type" => "radio_button", 'option_values' => ["LEIGH", "IRVING", "GERTRUDE"] },
|
183
|
+
{ "label" => "Lizzie Year of Birth", "field_type" => "radio_button", 'option_values' => ["1873", "1933", "1896"] }
|
184
|
+
]
|
185
|
+
}
|
186
|
+
}
|
187
|
+
})
|
188
|
+
end
|
189
|
+
line.stations.first.badges.first.settings[:test_attributes][:form_attributes][:type].should eql("TaskForm")
|
190
|
+
line.stations.first.badges.first.settings[:test_attributes][:form_attributes][:form_fields_attributes].should eql([{"label"=>"Last Name", "field_type"=>"radio_button", "option_values"=>["LEIGH", "IRVING", "GERTRUDE"]}, {"label"=>"Lizzie Year of Birth", "field_type"=>"radio_button", "option_values"=>["1873", "1933", "1896"]}])
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
it "should add a badge to the station with customtaskform as a badge testform form defined in DSL way" do
|
196
|
+
WebMock.allow_net_connect!
|
197
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
198
|
+
sleep 1
|
199
|
+
line = CF::Line.create(title,"Digitization") do |l|
|
200
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
201
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
202
|
+
end
|
203
|
+
station = CF::Station.create({:line => line, :type => "work"}) do |s|
|
204
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
205
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
206
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
207
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
208
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
209
|
+
end
|
210
|
+
@gold_standard = CF::GoldStandard.new({ :line => line,
|
211
|
+
:station => s,
|
212
|
+
:name => "easy_#{Time.now}",
|
213
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
214
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
215
|
+
})
|
216
|
+
|
217
|
+
@badge = CF::Badge.new({
|
218
|
+
:line => line,
|
219
|
+
:station => s,
|
220
|
+
:name => "Tomb Digitizer#{Time.now}",
|
221
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
222
|
+
:max_badges => 100,
|
223
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
224
|
+
:test_attributes =>
|
225
|
+
{
|
226
|
+
:type => "default",
|
227
|
+
:retries => 10,
|
228
|
+
:pass_percentage => 100,
|
229
|
+
:check_manually => true,
|
230
|
+
:form_attributes => {
|
231
|
+
:title => "Custom TestForm",
|
232
|
+
:instruction => "Look at the image of the tomb in the url given and answer the asked questions.",
|
233
|
+
:type => "CustomTaskForm",
|
234
|
+
:file =>"./spec/badges/station_1.html"
|
235
|
+
}
|
236
|
+
}
|
237
|
+
})
|
238
|
+
end
|
239
|
+
line.stations.first.badges.first.settings[:test_attributes][:form_attributes][:type].should eql("CustomTaskForm")
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
it "should add a badge with defined custom_task_form as a badge test form in plain ruby way " do
|
244
|
+
WebMock.allow_net_connect!
|
245
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
246
|
+
sleep 1
|
247
|
+
@line = CF::Line.create(title,"Digitization") do |l|
|
248
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
249
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
250
|
+
end
|
251
|
+
station = CF::Station.create({:line => @line, :type => "work"}) do |s|
|
252
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
253
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
254
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
255
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
256
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
257
|
+
end
|
258
|
+
@gold_standard = CF::GoldStandard.new({ :line => @line,
|
259
|
+
:station => s,
|
260
|
+
:name => "easy",
|
261
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
262
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
263
|
+
})
|
264
|
+
end
|
265
|
+
badge = CF::Badge.new({
|
266
|
+
:name => "Tomb Digitizer#{Time.now}",
|
267
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
268
|
+
:max_badges => 100,
|
269
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
270
|
+
:test_attributes =>
|
271
|
+
{
|
272
|
+
:type => "default",
|
273
|
+
:retries => 10,
|
274
|
+
:pass_percentage => 100,
|
275
|
+
:check_manually => false,
|
276
|
+
:form_attributes => {
|
277
|
+
:title => "Custom TestForm in plain ruby way",
|
278
|
+
:instruction => "Look at the image of the tomb in the url given and answer the asked questions.",
|
279
|
+
:type => "CustomTaskForm",
|
280
|
+
:file =>"./spec/badges/station_1.html"
|
281
|
+
}
|
282
|
+
}
|
283
|
+
})
|
284
|
+
@line.stations.first.badges badge
|
285
|
+
@line.stations.first.badges.first.settings["test"]["form"]["_type"].should eql("CustomTaskForm")
|
286
|
+
@line.stations.first.badges.first.settings["test"]["form"]["raw_html"].present?.should eql(true)
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
it "should add a badge with defined task_form as a badge test form in plain ruby way " do
|
291
|
+
WebMock.allow_net_connect!
|
292
|
+
title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
|
293
|
+
sleep 1
|
294
|
+
@line = CF::Line.create(title,"Digitization") do |l|
|
295
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
296
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
297
|
+
end
|
298
|
+
station = CF::Station.create({:line => @line, :type => "work"}) do |s|
|
299
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
|
300
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
301
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
|
302
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
|
303
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
|
304
|
+
end
|
305
|
+
@gold_standard = CF::GoldStandard.new({ :line => @line,
|
306
|
+
:station => s,
|
307
|
+
:name => "easy",
|
308
|
+
:input => {'image_url' => "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
309
|
+
:expected_output => {"first_name" => {"value" => "John"}, "last_name" => {"value" => "Lennon"}, "company" => {"value" => "Sprout"}}
|
310
|
+
})
|
311
|
+
end
|
312
|
+
badge = CF::Badge.new({
|
313
|
+
:name => "Tomb Digitizer#{Time.now}",
|
314
|
+
:description => "This badge qualifies you to work on tomb digitization tasks.",
|
315
|
+
:max_badges => 100,
|
316
|
+
:gold_standards => ["#{@gold_standard.settings[:name]}"],
|
317
|
+
:test_attributes =>
|
318
|
+
{
|
319
|
+
:type => "default",
|
320
|
+
:retries => 10,
|
321
|
+
:pass_percentage => 100,
|
322
|
+
:check_manually => false,
|
323
|
+
:form_attributes => {
|
324
|
+
:title => "Tombfinder Test plain ruby way",
|
325
|
+
:instruction => "Look at the image of the tomb in the url given and answer the asked questions.",
|
326
|
+
:type => "TaskForm",
|
327
|
+
:form_fields_attributes =>
|
328
|
+
[
|
329
|
+
{ "label" => "Last Name", "field_type" => "radio_button", 'option_values' => ["LEIGH", "IRVING", "GERTRUDE"] },
|
330
|
+
{ "label" => "Lizzie Year of Birth", "field_type" => "radio_button", 'option_values' => ["1873", "1933", "1896"] }
|
331
|
+
]
|
332
|
+
}
|
333
|
+
}
|
334
|
+
})
|
335
|
+
@line.stations.first.badges badge
|
336
|
+
@line.stations.first.badges.first.settings["test"]["form"]["_type"].should eql("TaskForm")
|
337
|
+
@line.stations.first.badges.first.settings["test"]["form"]["form_fields"].should eql([{"label"=>"Last Name", "field_type"=>"radio_button", "option_values"=>["LEIGH", "IRVING", "GERTRUDE"]}, {"label"=>"Lizzie Year of Birth", "field_type"=>"radio_button", "option_values"=>["1873", "1933", "1896"]}])
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
end
|