cloudfactory 0.5.6 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/cf/badge.rb +109 -22
- data/lib/cf/cli.rb +11 -5
- data/lib/cf/cli/badge.rb +234 -0
- data/lib/cf/cli/badge_yaml_validator.rb +25 -0
- data/lib/cf/cli/line.rb +23 -42
- data/lib/cf/cli/templates/sample-line/badge.yml +21 -0
- data/lib/cf/cli/templates/sample-line/line.yml.erb +2 -0
- data/lib/cf/help.txt +13 -0
- data/lib/cf/human_worker.rb +13 -65
- data/lib/cf/station.rb +12 -58
- data/lib/cf/version.rb +1 -1
- data/spec/badges_spec.rb +237 -337
- data/spec/custom_task_form_spec.rb +2 -2
- data/spec/human_worker_spec.rb +131 -5
- data/spec/line_spec.rb +7 -5
- data/spec/task_form_spec.rb +1 -18
- data/spec/text_appending_robot_spec.rb +4 -5
- metadata +55 -52
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pry'
|
2
|
+
module Cf
|
3
|
+
module BadgeYamlValidator
|
4
|
+
|
5
|
+
def validate(yaml_path)
|
6
|
+
errors = []
|
7
|
+
badge_dump = YAML::load(File.read(yaml_path).strip)
|
8
|
+
if badge_dump.class == Hash
|
9
|
+
if badge_dump["badge"].class == Array
|
10
|
+
badge_dump["badge"].each do |badge|
|
11
|
+
errors << "form for the badge is missing" unless badge["form"]
|
12
|
+
errors << "name of the badge is missing" unless badge["name"]
|
13
|
+
errors << "description for the badge is missing" unless badge["description"]
|
14
|
+
errors << "known answers for the badge must be array of hashes" unless badge["known_answers"].class == Array
|
15
|
+
end
|
16
|
+
else
|
17
|
+
errors << "badge mut be array of hash"
|
18
|
+
end
|
19
|
+
else
|
20
|
+
errors << "badges must be hash"
|
21
|
+
end
|
22
|
+
errors
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/cf/cli/line.rb
CHANGED
@@ -239,20 +239,14 @@ module Cf # :nodoc: all
|
|
239
239
|
number = worker['num_workers']
|
240
240
|
reward = worker['reward']
|
241
241
|
worker_type = worker['worker_type']
|
242
|
+
|
243
|
+
##### Add badge to the station ########
|
244
|
+
|
242
245
|
if worker_type == "human"
|
243
|
-
|
246
|
+
badges = station_file['station']['badges']
|
244
247
|
stat_badge = worker['stat_badge']
|
245
|
-
if stat_badge.nil?
|
246
|
-
human_worker = CF::HumanWorker.new({:station => s, :number => number, :reward => reward})
|
247
|
-
else
|
248
|
-
human_worker = CF::HumanWorker.new({:station => s, :number => number, :reward => reward, :stat_badge => stat_badge})
|
249
|
-
end
|
250
248
|
|
251
|
-
|
252
|
-
skill_badges.each do |badge|
|
253
|
-
human_worker.badge = badge
|
254
|
-
end
|
255
|
-
end
|
249
|
+
human_worker = CF::HumanWorker.new({:station => s, :number => number, :reward => reward, :badge => badges, :stat_badge => stat_badge})
|
256
250
|
|
257
251
|
say_status "worker", "#{number} Cloud #{pluralize(number, "Worker")} with reward of #{reward} #{pluralize(reward, "cent")}"
|
258
252
|
display_error(line_title, "#{human_worker.errors}") if human_worker.errors.present?
|
@@ -266,6 +260,7 @@ module Cf # :nodoc: all
|
|
266
260
|
display_error(line_title, "Invalid worker type: #{worker_type}")
|
267
261
|
end
|
268
262
|
|
263
|
+
|
269
264
|
# Creation of Form
|
270
265
|
# Creation of TaskForm
|
271
266
|
if station_file['station']['task_form'].present?
|
@@ -298,6 +293,15 @@ module Cf # :nodoc: all
|
|
298
293
|
display_error(line_title, "#{form.errors}") if form.errors.present?
|
299
294
|
end
|
300
295
|
|
296
|
+
# print if the badge for the station exist NOTE: addition of the badge is done above.
|
297
|
+
# it is printed here for better UI
|
298
|
+
if badges
|
299
|
+
say "Adding Badges For Station#{index}", :green
|
300
|
+
badges.each do |name|
|
301
|
+
say_status "-", "#{name}"
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
301
305
|
#check the presence of gold standard and create goldstandards for the station
|
302
306
|
gold_standards = station_file['station']['gold_standards']
|
303
307
|
if gold_standards
|
@@ -323,29 +327,6 @@ module Cf # :nodoc: all
|
|
323
327
|
end
|
324
328
|
end
|
325
329
|
end
|
326
|
-
|
327
|
-
#######create badge #########
|
328
|
-
badges = station_file['station']['badges']
|
329
|
-
if badges
|
330
|
-
say "Adding Badges to station", :green
|
331
|
-
badges.each do |s_badge|
|
332
|
-
if s_badge.length == 1 && s_badge.keys.include?("name")
|
333
|
-
else
|
334
|
-
form = s_badge["test_attributes"]["form_attributes"]
|
335
|
-
unless form.blank?
|
336
|
-
if form["type"] == "CustomTaskForm"
|
337
|
-
file = File.read("#{line_source}/#{form["file"]}") || File.read("#{line_source}/badges/station#{station_file['station']['station_index']}.html")
|
338
|
-
s_badge["test_attributes"]["form_attributes"].merge!({:raw_html => file, :_type =>"CustomTaskForm" })
|
339
|
-
else
|
340
|
-
s_badge["test_attributes"]["form_attributes"].merge!({:_type =>"TaskForm" })
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
badge = CF::Badge.new(s_badge.merge({:line => line,:station => s }))
|
345
|
-
say_status "Badge","'#{s_badge["name"] }'"
|
346
|
-
display_error(line_title, "#{badge.errors}") if badge.errors.present?
|
347
|
-
end
|
348
|
-
end
|
349
330
|
end
|
350
331
|
end
|
351
332
|
|
@@ -370,17 +351,17 @@ module Cf # :nodoc: all
|
|
370
351
|
end
|
371
352
|
end
|
372
353
|
if gold_standards.class == Hash#gold_standards["file"]
|
373
|
-
|
374
|
-
|
375
|
-
display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
|
376
|
-
else
|
377
|
-
gold_standards.each do |gold_options|
|
378
|
-
gold_standard = CF::GoldStandard.new(gold_options.merge(:line => line))
|
379
|
-
say_status "GoldStandard", "'#{gold_options["name"]}'"
|
354
|
+
gold_standard = CF::GoldStandard.new(gold_standards.merge!({:line => line}))
|
355
|
+
say_status "GoldStandard from file", "'#{gold_standards[:file]}'"
|
380
356
|
display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
|
357
|
+
else
|
358
|
+
gold_standards.each do |gold_options|
|
359
|
+
gold_standard = CF::GoldStandard.new(gold_options.merge(:line => line))
|
360
|
+
say_status "GoldStandard", "'#{gold_options["name"]}'"
|
361
|
+
display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
|
362
|
+
end
|
381
363
|
end
|
382
364
|
end
|
383
|
-
end
|
384
365
|
|
385
366
|
say " ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁", :white
|
386
367
|
say "Line was successfully created.", :green
|
@@ -0,0 +1,21 @@
|
|
1
|
+
badge:
|
2
|
+
- name: Designer #name of the badge that you want to create
|
3
|
+
description: This badge allow to do the designing tasks #description of the badge
|
4
|
+
max_badge_assignments: 5 #numbers of worker who can take the badge
|
5
|
+
retries_allowed: 5 #number of retries that worker get at the time of taking the badge
|
6
|
+
pass_percentage: 80 #the value in percentage that the worker must score to pass the test
|
7
|
+
assignment_duration: 3600 #time assigned for badge test
|
8
|
+
check_manually: false #checking badge answers that worker has ssubmitted
|
9
|
+
allow_retake_after: 30 #number of day after which the worker can again take the badge exam
|
10
|
+
form: badge_form.html #form for the badge. It should be html format if it is a custom form
|
11
|
+
known_answers: #the hash of question and answers for the badge
|
12
|
+
- input:
|
13
|
+
image_url: http://www.crystalinks.com/newton.jpg
|
14
|
+
expected_output:
|
15
|
+
gender: male
|
16
|
+
age: 60
|
17
|
+
- input:
|
18
|
+
image_url: http://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Salmanrampwalk.png/220px-Salmanrampwalk.png
|
19
|
+
expected_output:
|
20
|
+
gender: male
|
21
|
+
age: 50
|
@@ -30,6 +30,8 @@ stations:
|
|
30
30
|
worker_type: human # "human" or name of robot (google_translate_robot, etc)
|
31
31
|
num_workers: 2
|
32
32
|
reward: 2
|
33
|
+
badge:
|
34
|
+
- bizcard-digitizer
|
33
35
|
custom_task_form:
|
34
36
|
form_title: Clink a link and paste in url
|
35
37
|
instruction: Look through search results and find the best date
|
data/lib/cf/help.txt
CHANGED
@@ -65,3 +65,16 @@ Output:
|
|
65
65
|
Get the output of run. For more info, cf output help
|
66
66
|
More:
|
67
67
|
cf output help [sub-command] #list all help related to output subcommands
|
68
|
+
|
69
|
+
|
70
|
+
Badge:
|
71
|
+
Usage:
|
72
|
+
cf badge create # Create badges that are in badge.yml
|
73
|
+
cf badge delete <badge name> # Delete the given badge within your account
|
74
|
+
cf badge generate # Generate a new badge template at badges/badge.yml
|
75
|
+
cf badge list # List all badges asscociated with your account. Use 'cf badge list <badge_name>' for single badge
|
76
|
+
cf badge update <badge_name> # Update the given badge within with your account. Use 'cf badge update' to update all badges in badge.yml
|
77
|
+
Description:
|
78
|
+
Commands to manage the badges.
|
79
|
+
More:
|
80
|
+
cf help [COMMAND] # Describe subcommands or one specific subcommand
|
data/lib/cf/human_worker.rb
CHANGED
@@ -45,7 +45,7 @@ module CF
|
|
45
45
|
attr_accessor :errors
|
46
46
|
|
47
47
|
# Badge setting for "worker" object
|
48
|
-
attr_accessor :
|
48
|
+
attr_accessor :badges
|
49
49
|
|
50
50
|
# ==Initializes a new "worker" object
|
51
51
|
# ==Usage of HumanWorker.new(hash):
|
@@ -72,34 +72,26 @@ module CF
|
|
72
72
|
@station = options[:station]
|
73
73
|
@number = options[:number].nil? ? 1 : options[:number]
|
74
74
|
@reward = options[:reward]
|
75
|
-
@stat_badge = options[:stat_badge]
|
75
|
+
@stat_badge = options[:stat_badge]
|
76
|
+
@badges = options[:badge]
|
76
77
|
if @station
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
:body =>
|
81
|
-
{
|
82
|
-
:api_key => CF.api_key,
|
83
|
-
:worker => {:number => @number, :reward => @reward, :type => "HumanWorker"}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
else
|
87
|
-
request =
|
78
|
+
request =
|
79
|
+
{
|
80
|
+
:body =>
|
88
81
|
{
|
89
|
-
:
|
90
|
-
{
|
91
|
-
|
92
|
-
|
93
|
-
:stat_badge => options[:stat_badge]
|
94
|
-
}
|
82
|
+
:api_key => CF.api_key,
|
83
|
+
:worker => {:number => @number, :reward => @reward, :type => "HumanWorker"},
|
84
|
+
:badge => options[:badge],
|
85
|
+
:stat_badge => options[:stat_badge]
|
95
86
|
}
|
96
|
-
|
87
|
+
}
|
97
88
|
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers.json",request)
|
98
89
|
|
99
90
|
self.id = resp.parsed_response['id']
|
100
91
|
self.number = resp.parsed_response['number']
|
101
92
|
self.reward = resp.parsed_response['reward']
|
102
93
|
self.stat_badge = resp.parsed_response['stat_badge']
|
94
|
+
self.badges = resp.parsed_response['badges']
|
103
95
|
|
104
96
|
if resp.code != 200
|
105
97
|
self.errors = resp.parsed_response['error']['message']
|
@@ -109,52 +101,8 @@ module CF
|
|
109
101
|
end
|
110
102
|
end
|
111
103
|
|
112
|
-
# ==Creation a new "worker" object with Badge
|
113
|
-
# ==Usage Example:
|
114
|
-
# ==In Plain Ruby way
|
115
|
-
# badge_settings =
|
116
|
-
# {
|
117
|
-
# :title => 'Football Fanatic',
|
118
|
-
# :description => "This qualification allows you to perform work at stations which have this badge.",
|
119
|
-
# :max_badges => 3,
|
120
|
-
# :test =>
|
121
|
-
# {
|
122
|
-
# :input => {:name => "Lionel Andres Messi", :country => "Argentina"},
|
123
|
-
# :expected_output =>
|
124
|
-
# [
|
125
|
-
# {:birthplace => "Rosario, Santa Fe, Argentina",:match_options => {:tolerance => 10, :ignore_case => true }},
|
126
|
-
# {:position => "CF",:match_options => {:tolerance => 1 }},
|
127
|
-
# {:"current-club" => "Barcelona",:match_options => {:tolerance => 1, :ignore_case => false }}
|
128
|
-
# ]
|
129
|
-
# }
|
130
|
-
# }
|
131
|
-
# line = CF::Line.new("human_worker", "Digitization")
|
132
|
-
# input_format = CF::InputFormat.new({:name => "image_url", :required => true, :valid_type => "url"})
|
133
|
-
# line.input_formats input_format
|
134
|
-
#
|
135
|
-
# station = CF::Station.new({:type => "work"})
|
136
|
-
# line.stations station
|
137
|
-
#
|
138
|
-
# worker = CF::HumanWorker.new({:number => 2, :reward => 20, :skill_badge => skill_badge})
|
139
|
-
# line.stations.first.worker = worker
|
140
|
-
#
|
141
|
-
# line.stations.first.worker.badge = badge_settings
|
142
|
-
def badge=(badge)
|
143
|
-
request =
|
144
|
-
{
|
145
|
-
:body =>
|
146
|
-
{
|
147
|
-
:api_key => CF.api_key,
|
148
|
-
:skill_badge => badge
|
149
|
-
}
|
150
|
-
}
|
151
|
-
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers/#{self.id}/badge.json",request)
|
152
|
-
self.errors = resp['error']['message'] if resp.code != 200
|
153
|
-
self.skill_badges << resp.parsed_response['skill_badges']
|
154
|
-
end
|
155
|
-
|
156
104
|
def to_s # :nodoc:
|
157
|
-
"{:id => => #{self.id}, :number => #{self.number}, :reward => #{self.reward}, :stat_badge => #{self.stat_badge}, :errors => #{self.errors}}"
|
105
|
+
"{:id => => #{self.id}, :number => #{self.number}, :reward => #{self.reward}, :stat_badge => #{self.stat_badge}, :errors => #{self.errors},:badges =>#{self.badges}}"
|
158
106
|
end
|
159
107
|
end
|
160
108
|
end
|
data/lib/cf/station.rb
CHANGED
@@ -179,32 +179,26 @@ 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
|
-
|
185
|
-
|
186
|
-
|
187
|
-
:api_key => CF.api_key,
|
188
|
-
:worker => {:number => number, :reward => reward, :type => "HumanWorker"}
|
189
|
-
}
|
190
|
-
}
|
191
|
-
else
|
192
|
-
request =
|
182
|
+
badges = worker_instance.badges
|
183
|
+
|
184
|
+
request =
|
185
|
+
{
|
186
|
+
:body =>
|
193
187
|
{
|
194
|
-
:
|
195
|
-
{
|
196
|
-
|
197
|
-
|
198
|
-
:stat_badge => stat_badge
|
199
|
-
}
|
188
|
+
:api_key => CF.api_key,
|
189
|
+
:worker => {:number => number, :reward => reward, :type => "HumanWorker"},
|
190
|
+
:stat_badge => stat_badge,
|
191
|
+
:badge => badges
|
200
192
|
}
|
201
|
-
|
193
|
+
}
|
194
|
+
|
202
195
|
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}/workers.json",request)
|
203
196
|
worker = CF::HumanWorker.new({})
|
204
197
|
worker.id = resp.parsed_response['id']
|
205
198
|
worker.number = resp.parsed_response['number']
|
206
199
|
worker.reward = resp.parsed_response['reward']
|
207
200
|
worker.stat_badge = resp.parsed_response['stat_badge']
|
201
|
+
worker.badges = resp.parsed_response['badges']
|
208
202
|
if resp.code != 200
|
209
203
|
worker.errors = resp.parsed_response['error']['message']
|
210
204
|
end
|
@@ -373,45 +367,5 @@ module CF
|
|
373
367
|
def gold_standards=(gold_standard) # :nodoc:
|
374
368
|
@gold_standards << gold_standard
|
375
369
|
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
|
-
|
416
370
|
end
|
417
371
|
end
|
data/lib/cf/version.rb
CHANGED
data/spec/badges_spec.rb
CHANGED
@@ -1,342 +1,242 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CF::Badge do
|
4
|
-
context "
|
5
|
-
it "
|
4
|
+
context "#create" do
|
5
|
+
it " in block 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
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
7
|
+
@badge = CF::Badge.create(
|
8
|
+
:name => "Bizcard Digitizer_dsl",
|
9
|
+
:description => "this badge qualifies the worker for bizcard digitization",
|
10
|
+
:max_badge_assignments => 100,
|
11
|
+
:retries_allowed => 5,
|
12
|
+
:pass_percentage => 80,
|
13
|
+
:assignment_duration => 3600,
|
14
|
+
:allow_retake_after => 5,
|
15
|
+
:check_manually =>false,
|
16
|
+
:form => "./lib/cf/cli/templates/sample-line/form.html",
|
17
|
+
:known_answers=>
|
18
|
+
[
|
19
|
+
{ "name" => "chandra",
|
20
|
+
"input"=> {"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg"},
|
21
|
+
"expected_output"=>{"gender"=>{"value"=>"Male"}, "rich"=>{"value"=>"1"}}
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name" => "mohan",
|
25
|
+
"input"=>{"image_url"=> "http://onwired.com/images/portfolio/linda-stanley-business-card.jpg2"},
|
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
|
340
231
|
|
341
|
-
|
342
|
-
|
232
|
+
it "delete all badges" do
|
233
|
+
WebMock.allow_net_connect!
|
234
|
+
badge2 = CF::Badge.destroy("bizcard-digitizer")
|
235
|
+
badge2 = CF::Badge.destroy("bizcard-digitizer_updated")
|
236
|
+
badge2 = CF::Badge.destroy("bizcard-digitizer_dsl")
|
237
|
+
badge3 = CF::Badge.destroy("bizcard-digitizer_plain")
|
238
|
+
badge4 = CF::Badge.destroy("Bizcard Digitizer_standard_form")
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|