cloudfactory 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cf/run.rb CHANGED
@@ -31,14 +31,23 @@ module CF
31
31
  @line = line
32
32
  @line_title = line.title
33
33
  elsif line.class == String
34
- @line_title = line
34
+ if line.split("/").count == 2
35
+ @account = line.split("/").first
36
+ @line_title = line.split("/").last
37
+ elsif line.split("/").count == 1
38
+ @line_title = line
39
+ end
35
40
  end
36
41
  @title = title
37
42
  if File.exist?(input.to_s)
38
43
  @file = input
39
44
  @param_data = File.new(input, 'rb')
40
45
  @param_for_input = :file
41
- resp = self.class.post("/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data})
46
+ if line.class == String && line.split("/").count == 2
47
+ resp = self.class.post("/lines/#{@account}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data})
48
+ else
49
+ resp = self.class.post("/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data})
50
+ end
42
51
  if resp.code != 200
43
52
  self.errors = resp.error.message
44
53
  end
@@ -54,7 +63,11 @@ module CF
54
63
  :data =>{:run => { :title => @title }, :inputs => @param_data}
55
64
  }
56
65
  }
57
- run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json",options)
66
+ if line.class == String && line.split("/").count == 2
67
+ run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{@account}/#{@line_title.downcase}/runs.json",options)
68
+ else
69
+ run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json",options)
70
+ end
58
71
  if run.code != 200
59
72
  self.errors = run.parsed_response['error']['message']
60
73
  end
@@ -78,18 +91,13 @@ module CF
78
91
  # run_object.final_output
79
92
  def final_output
80
93
  resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output.json")
81
- @final_output =[]
82
- resp['output'].each do |r|
83
- result = FinalOutput.new()
84
- r.to_hash.each_pair do |k,v|
85
- result.send("#{k}=",v) if result.respond_to?(k)
94
+ output = []
95
+ if resp['output'].class == Array
96
+ resp['output'].each do |o|
97
+ output << o.to_hash
86
98
  end
87
- if result.final_output == nil
88
- result.final_output = resp.output
89
- end
90
- @final_output << result
91
99
  end
92
- return @final_output
100
+ return output
93
101
  end
94
102
 
95
103
  # ==Returns Final Output of production Run
@@ -97,7 +105,13 @@ module CF
97
105
  # CF::Run.final_output("run_title")
98
106
  def self.final_output(title)
99
107
  resp = get("/runs/#{CF.account_name}/#{title.downcase}/output.json")
100
- return resp['output']
108
+ output = []
109
+ if resp['output'].class == Array
110
+ resp['output'].each do |o|
111
+ output << o.to_hash
112
+ end
113
+ end
114
+ return output
101
115
  end
102
116
 
103
117
  # ==Returns Output of production Run for any specific Station and for given Run Title
@@ -108,7 +122,13 @@ module CF
108
122
  station_no = options[:station]
109
123
  title = options[:title]
110
124
  resp = get("/runs/#{CF.account_name}/#{title.downcase}/output/#{station_no}.json")
111
- return resp['output']
125
+ output = []
126
+ if resp['output'].class == Array
127
+ resp['output'].each do |o|
128
+ output << o.to_hash
129
+ end
130
+ end
131
+ return output
112
132
  end
113
133
 
114
134
  # ==Returns Output of Run object for any specific Station
@@ -118,7 +138,13 @@ module CF
118
138
  def output(options={})
119
139
  station_no = options[:station]
120
140
  resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output/#{station_no}.json")
121
- return resp['output'].first.to_hash
141
+ output = []
142
+ if resp['output'].class == Array
143
+ resp['output'].each do |o|
144
+ output << o.to_hash
145
+ end
146
+ end
147
+ return output
122
148
  end
123
149
 
124
150
  # ==Searches Run for the given "run_title"
data/lib/cf/station.rb CHANGED
@@ -25,7 +25,7 @@ module CF
25
25
  attr_accessor :auto_judge
26
26
 
27
27
  # Contains Error Message if any
28
- attr_accessor :errors
28
+ attr_accessor :errors, :batch_size
29
29
 
30
30
  # ==Initializes a new station
31
31
  # ===Usage Example:
@@ -40,22 +40,42 @@ module CF
40
40
  @auto_judge = options[:auto_judge]
41
41
  @station_input_formats = options[:input_formats]
42
42
  @line_instance = options[:line]
43
- request_general =
44
- {
45
- :body =>
43
+ @batch_size = options[:batch_size]
44
+ if @batch_size.nil?
45
+ request_general =
46
46
  {
47
- :api_key => CF.api_key,
48
- :station => {:type => @type, :input_formats => @station_input_formats}
47
+ :body =>
48
+ {
49
+ :api_key => CF.api_key,
50
+ :station => {:type => @type, :input_formats => @station_input_formats}
51
+ }
49
52
  }
50
- }
51
- request_tournament =
52
- {
53
- :body =>
53
+ request_tournament =
54
54
  {
55
- :api_key => CF.api_key,
56
- :station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats}
55
+ :body =>
56
+ {
57
+ :api_key => CF.api_key,
58
+ :station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats}
59
+ }
57
60
  }
58
- }
61
+ else
62
+ request_general =
63
+ {
64
+ :body =>
65
+ {
66
+ :api_key => CF.api_key,
67
+ :station => {:type => @type, :input_formats => @station_input_formats, :batch_size => @batch_size}
68
+ }
69
+ }
70
+ request_tournament =
71
+ {
72
+ :body =>
73
+ {
74
+ :api_key => CF.api_key,
75
+ :station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats, :batch_size => @batch_size}
76
+ }
77
+ }
78
+ end
59
79
  if @line_title
60
80
  if @type == "Improve"
61
81
  line = options[:line]
data/lib/cf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CF # :nodoc: all
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -15,8 +15,8 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "concept_tagging_robot_run", [{"url"=>"www.mosexindex.com"}])
17
17
  output = run.final_output
18
- output.first.final_output.first.concept_tagging_of_url.should eql(["Canada", "English language"])
19
- output.first.final_output.first.concept_tagging_relevance_of_url.should eql([89.5153, 79.0912])
18
+ output.first['concept_tagging_of_url'].should eql(["Canada", "English language"])
19
+ output.first['concept_tagging_relevance_of_url'].should eql([89.5153, 79.0912])
20
20
  line.stations.first.worker.class.should eql(CF::RobotWorker)
21
21
  line.stations.first.worker.reward.should eql(0.5)
22
22
  line.stations.first.worker.number.should eql(1)
@@ -40,8 +40,8 @@ module CF
40
40
 
41
41
  run = CF::Run.create(line, "concept_tagging_robot_run_1", [{"url"=>"www.mosexindex.com"}])
42
42
  output = run.final_output
43
- output.first.final_output.first.concept_tagging_of_url.should eql(["Canada", "English language"])
44
- output.first.final_output.first.concept_tagging_relevance_of_url.should eql([89.5153, 79.0912])
43
+ output.first['concept_tagging_of_url'].should eql(["Canada", "English language"])
44
+ output.first['concept_tagging_relevance_of_url'].should eql([89.5153, 79.0912])
45
45
  line.stations.first.worker.class.should eql(CF::RobotWorker)
46
46
  line.stations.first.worker.reward.should eql(0.5)
47
47
  line.stations.first.worker.number.should eql(1)
@@ -16,7 +16,7 @@ module CF
16
16
  run = CF::Run.create(line, "content_scraping_robot_run", [{"url"=> "http://www.sprout-technology.com"}])
17
17
 
18
18
  output = run.final_output
19
- output.first.final_output.first.scraped_link_from_document.should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
19
+ output.first['scraped_link_from_document'].should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
20
20
 
21
21
  line.stations.first.worker.class.should eql(CF::RobotWorker)
22
22
  line.stations.first.worker.reward.should eql(0.5)
@@ -42,7 +42,7 @@ module CF
42
42
  run = CF::Run.create(line, "content_scraping_robot_run_1", [{"url"=> "http://www.sprout-technology.com"}])
43
43
 
44
44
  output = run.final_output
45
- output.first.final_output.first.scraped_link_from_document.should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
45
+ output.first['scraped_link_from_document'].should eql([["http://www.cloudfactory.com", "http://www.bizcardarmy.com"]])
46
46
 
47
47
  line.stations.first.worker.class.should eql(CF::RobotWorker)
48
48
  line.stations.first.worker.reward.should eql(0.5)
@@ -15,10 +15,10 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "entity_extraction_robot_run", [{"text"=> "Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"}])
17
17
  output = run.final_output
18
- output.first.final_output.first.entity_counts_of_document.should eql([["2", "2", "1", "1", "2", "1"]])
19
- output.first.final_output.first.entity_names_of_document.should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
20
- output.first.final_output.first.entity_relevances_of_document.should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
21
- output.first.final_output.first.entity_types_of_document.should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
18
+ output.first['entity_counts_of_document'].should eql([["2", "2", "1", "1", "2", "1"]])
19
+ output.first['entity_names_of_document'].should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
20
+ output.first['entity_relevances_of_document'].should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
21
+ output.first['entity_types_of_document'].should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
22
22
  line.stations.first.worker.class.should eql(CF::RobotWorker)
23
23
  line.stations.first.worker.reward.should eql(0.5)
24
24
  line.stations.first.worker.number.should eql(1)
@@ -41,10 +41,10 @@ module CF
41
41
 
42
42
  run = CF::Run.create(line, "entity_extraction_robot_run_1", [{"text"=> "Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"}])
43
43
  output = run.final_output
44
- output.first.final_output.first.entity_counts_of_document.should eql([["2", "2", "1", "1", "2", "1"]])
45
- output.first.final_output.first.entity_names_of_document.should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
46
- output.first.final_output.first.entity_relevances_of_document.should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
47
- output.first.final_output.first.entity_types_of_document.should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
44
+ output.first['entity_counts_of_document'].should eql([["2", "2", "1", "1", "2", "1"]])
45
+ output.first['entity_names_of_document'].should eql([["Ludwig Von Beethoven", "Franz Kafka", "George Orwell", "Mozart", "China", "Japan"]])
46
+ output.first['entity_relevances_of_document'].should eql([[92.12089999999999, 73.8997, 48.079100000000004, 28.9416, 27.1982, 21.1997]])
47
+ output.first['entity_types_of_document'].should eql([["Person", "Person", "Person", "Person", "Country", "Country"]])
48
48
  line.stations.first.worker.class.should eql(CF::RobotWorker)
49
49
  line.stations.first.worker.reward.should eql(0.5)
50
50
  line.stations.first.worker.number.should eql(1)
@@ -28,7 +28,7 @@ module CF
28
28
  run = CF::Run.create(line, "google_translate_robot_run", [{"text"=> "I started loving Monsoon"}])
29
29
  @final_output = run.final_output
30
30
  line.stations.first.worker.number.should eq(1)
31
- @final_output.first.final_output.first.translation_of_text.should eql('Empecé a amar a Monzón')
31
+ @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
32
32
  end
33
33
  end
34
34
 
@@ -50,7 +50,7 @@ module CF
50
50
 
51
51
  @final_output = run.final_output
52
52
  line.stations.first.worker.number.should eq(1)
53
- @final_output.first.final_output.first.translation_of_text.should eql('Empecé a amar a Monzón')
53
+ @final_output.first['translation_of_text'].should eql('Empecé a amar a Monzón')
54
54
  end
55
55
  end
56
56
  end
@@ -15,7 +15,7 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "image_processing_robot_run", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
17
17
  output = run.final_output
18
- converted_url = output.first.final_output.first.processed_image_of_url
18
+ converted_url = output.first['processed_image_of_url']
19
19
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
20
20
  line.stations.first.worker.class.should eql(CF::RobotWorker)
21
21
  line.stations.first.worker.reward.should eql(0.01)
@@ -40,7 +40,7 @@ module CF
40
40
 
41
41
  run = CF::Run.create(line, "image_processing_robot_run_1", [{"url"=> "http://wwwdelivery.superstock.com/WI/223/1527/PreviewComp/SuperStock_1527R-020214.jpg"}])
42
42
  output = run.final_output
43
- converted_url = output.first.final_output.first.processed_image_of_url
43
+ converted_url = output.first['processed_image_of_url']
44
44
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
45
45
  line.stations.first.worker.class.should eql(CF::RobotWorker)
46
46
  line.stations.first.worker.reward.should eql(0.01)
@@ -18,8 +18,8 @@ module CF
18
18
  end
19
19
  run = CF::Run.create(line, "keyword_matching_robot_run", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
20
20
  output = run.final_output
21
- output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
22
- output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
21
+ output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
22
+ output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
23
23
  line.stations.first.worker.class.should eql(CF::RobotWorker)
24
24
  line.stations.first.worker.reward.should eql(0.5)
25
25
  line.stations.first.worker.number.should eql(1)
@@ -54,8 +54,8 @@ module CF
54
54
 
55
55
  run = CF::Run.create(line, "keyword_matching_robot_run_1", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
56
56
  output = run.final_output
57
- output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
58
- output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
57
+ output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
58
+ output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
59
59
  line.stations.first.worker.class.should eql(CF::RobotWorker)
60
60
  line.stations.first.worker.reward.should eql(0.5)
61
61
  line.stations.first.worker.number.should eql(1)
data/spec/line_spec.rb CHANGED
@@ -346,8 +346,8 @@ describe CF::Line do
346
346
  forced_delete = CF::Line.destroy("delete_line_of_run", :forced => true)
347
347
 
348
348
  search_line = CF::Line.find("delete_line_of_run")
349
- search_line.code.should eql(404)
350
- search_line.error.message.should eql("Line document not found using selector: {:public=>true, :title=>\"delete_line_of_run\"}")
349
+ search_line['code'].should eql(404)
350
+ search_line['error']['message'].should eql("Line document not found using selector: {:public=>true, :title=>\"delete_line_of_run\"}")
351
351
  end
352
352
  end
353
353
  end
@@ -365,7 +365,7 @@ describe CF::Line do
365
365
  end
366
366
  end
367
367
  end
368
- line_details = CF::Line.details("line_details")
368
+ line_details = CF::Line.inspect("line_details")
369
369
  line_input_format_id = line_details['input_formats'].first['id']
370
370
  from_field_id = line_details['stations'].first['form_fields'].first['id']
371
371
  station_input_format_id = line_details['stations'].first['input_formats'].first['id']
@@ -373,4 +373,28 @@ describe CF::Line do
373
373
  end
374
374
  end
375
375
  end
376
+
377
+ context "get a line of other account" do
378
+ it "as public line" do
379
+ VCR.use_cassette "lines/plain-ruby/public-line", :record => :new_episodes do
380
+ # WebMock.allow_net_connect!
381
+ got_line = CF::Line.find("hero/dummy")
382
+ got_line['title'].should eql("dummy")
383
+ got_line['public'].should eql(true)
384
+
385
+ run = CF::Run.create("hero/dummy", "dummy_run", [{"text" => "run for public line of another account"}])
386
+ run.title.should eql("dummy_run")
387
+ run.input.should eql([{"text" => "run for public line of another account"}])
388
+ end
389
+ end
390
+
391
+ it "as private line" do
392
+ VCR.use_cassette "lines/plain-ruby/private-line", :record => :new_episodes do
393
+ # WebMock.allow_net_connect!
394
+ got_line = CF::Line.find("hero/dummy_false")
395
+ got_line['code'].should eql(404)
396
+ got_line['error']['message'].should eql("Line with title: dummy_false under account hero is not public")
397
+ end
398
+ end
399
+ end
376
400
  end
@@ -16,8 +16,8 @@ module CF
16
16
  end
17
17
  run = CF::Run.create(line, "mailer_robot_run", [{"to"=> "manish.das@sprout-technology.com"}])
18
18
  output = run.final_output
19
- output.first.final_output.first.recipients_of_to.should eql([["manish.das@sprout-technology.com"]])
20
- output.first.final_output.first.sent_message_for_to.should eql(["<html><body><h1>Hello manish.das@sprout-technology.com Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
19
+ output.first['recipients_of_to'].should eql([["manish.das@sprout-technology.com"]])
20
+ output.first['sent_message_for_to'].should eql(["<html><body><h1>Hello manish.das@sprout-technology.com Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
21
21
  line.stations.first.worker.class.should eql(CF::RobotWorker)
22
22
  line.stations.first.worker.reward.should eql(0.01)
23
23
  line.stations.first.worker.number.should eql(1)
@@ -42,8 +42,8 @@ module CF
42
42
 
43
43
  run = CF::Run.create(line, "mailer_robot_run_1", [{"to"=> "manish.das@sprout-technology.com"}])
44
44
  output = run.final_output
45
- output.first.final_output.first.recipients_of_to.should eql([["manish.das@sprout-technology.com"]])
46
- output.first.final_output.first.sent_message_for_to.should eql(["<html><body><h1>Hello manish.das@sprout-technology.com Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
45
+ output.first['recipients_of_to'].should eql([["manish.das@sprout-technology.com"]])
46
+ output.first['sent_message_for_to'].should eql(["<html><body><h1>Hello manish.das@sprout-technology.com Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
47
47
  line.stations.first.worker.class.should eql(CF::RobotWorker)
48
48
  line.stations.first.worker.reward.should eql(0.01)
49
49
  line.stations.first.worker.number.should eql(1)
@@ -35,7 +35,7 @@ module CF
35
35
  run = CF::Run.create(line, "media_converter_robot_run", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov", "to" => "mpg", "audio_quality" => "320", "video_quality" => "3"}])
36
36
  @final_output = run.final_output
37
37
  line.stations.first.worker.number.should eq(1)
38
- converted_url = @final_output.first.final_output.first.converted_file_from_url
38
+ converted_url = @final_output.first['converted_file_from_url']
39
39
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
40
40
  end
41
41
  end
@@ -57,7 +57,7 @@ module CF
57
57
 
58
58
  @final_output = run.final_output
59
59
  line.stations.first.worker.number.should eq(1)
60
- converted_url = @final_output.first.final_output.first.converted_file_from_url
60
+ converted_url = @final_output.first['converted_file_from_url']
61
61
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
62
62
  end
63
63
  end
@@ -15,8 +15,8 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "media_splitting_robot_run", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
17
17
  output = run.final_output
18
- converted_url_1= output.first.final_output.first.splits_of_url.first
19
- converted_url_2= output.first.final_output.first.splits_of_url.last
18
+ converted_url_1= output.first['splits_of_url'].first
19
+ converted_url_2= output.first['splits_of_url'].last
20
20
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_1}").should eql(true)
21
21
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_2}").should eql(true)
22
22
  line.stations.first.worker.class.should eql(CF::RobotWorker)
@@ -42,8 +42,8 @@ module CF
42
42
 
43
43
  run = CF::Run.create(line, "media_splitting_robot_run_1", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
44
44
  output = run.final_output
45
- converted_url_1= output.first.final_output.first.splits_of_url.first
46
- converted_url_2= output.first.final_output.first.splits_of_url.last
45
+ converted_url_1= output.first['splits_of_url'].first
46
+ converted_url_2= output.first['splits_of_url'].last
47
47
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_1}").should eql(true)
48
48
  File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_2}").should eql(true)
49
49
  line.stations.first.worker.class.should eql(CF::RobotWorker)
data/spec/run_spec.rb CHANGED
@@ -170,10 +170,10 @@ module CF
170
170
  end
171
171
  end
172
172
  run = CF::Run.create(line, "run-name-result-0111111111", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
173
- @final_output = run.final_output
174
173
  # debugger
175
- @final_output.first.final_output.first['first-name'].should eql("Bob")
176
- @final_output.first.final_output.first['last-name'].should eql("Marley")
174
+ @final_output = run.final_output
175
+ @final_output.first['first-name'].should eql("Bob")
176
+ @final_output.first['last-name'].should eql("Marley")
177
177
  end
178
178
  end
179
179
 
@@ -186,13 +186,15 @@ module CF
186
186
  CF::RobotWorker.create({:station => s, :type => "text_extraction_robot", :settings => {:url => ["{{url}}"]}})
187
187
  end
188
188
  CF::Station.create({:line => l, :type => "work"}) do |s1|
189
- CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
189
+ CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj", "iPhone"]}})
190
190
  end
191
191
  end
192
- run = CF::Run.create(line, "keyword_matching_robot_run_result", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
192
+ run = CF::Run.create(line, "keyword_matching_robot_run_result", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}, {"url"=> "http://techcrunch.com/2011/07/26/buddytv-iphone/"}])
193
193
  output = run.final_output
194
- output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
195
- output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
194
+ output.first['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
195
+ output.first['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
196
+ output.last['included_keywords_count_in_contents_of_url'].should eql(["4"])
197
+ output.last['keyword_included_in_contents_of_url'].should eql(["iPhone"])
196
198
  line.stations.first.worker.class.should eql(CF::RobotWorker)
197
199
  line.stations.first.worker.reward.should eql(0.5)
198
200
  line.stations.first.worker.number.should eql(1)
@@ -201,7 +203,7 @@ module CF
201
203
  line.stations.last.worker.class.should eql(CF::RobotWorker)
202
204
  line.stations.last.worker.reward.should eql(0.5)
203
205
  line.stations.last.worker.number.should eql(1)
204
- line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
206
+ line.stations.last.worker.settings.should eql({:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj", "iPhone"]})
205
207
  line.stations.last.worker.type.should eql("KeywordMatchingRobot")
206
208
  output_of_station_1 = CF::Run.output({:title => "keyword_matching_robot_run_result", :station => 1})
207
209
  output_of_station_2 = CF::Run.output({:title => "keyword_matching_robot_run_result", :station => 2})
@@ -249,7 +251,7 @@ module CF
249
251
  end
250
252
  run = CF::Run.create(line, "media_splitting_robot_run_5", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
251
253
  run_1 = CF::Run.create(line, "media_splitting_robot_run_5", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
252
- run_1.errors.should eql("[\"Title is already taken for this account\"]")
254
+ run_1.errors.should eql(["Title is already taken for this account"])
253
255
  end
254
256
  end
255
257
 
@@ -284,7 +286,7 @@ module CF
284
286
  run = CF::Run.create(line, "media_splitting_robot_run_7", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
285
287
  found_run = CF::Run.find("unused_title")
286
288
  found_run.code.should eql(404)
287
- found_run.errors.should eql("Run document not found using selector: {:tenant_id=>BSON::ObjectId('4def16fa5511274d98000014'), \"account_id\"=>BSON::ObjectId('4def122255112748d7000003'), :title=>\"unused_title\"}")
289
+ found_run.errors.should eql("Run document not found using selector: {:tenant_id=>BSON::ObjectId('4def16fa5511274d98000014'), :title=>\"unused_title\"}")
288
290
  end
289
291
  end
290
292
  end
@@ -376,10 +378,10 @@ module CF
376
378
  run_2 = CF::Run.create(line_2, "progress_run_32", [{"url"=> "http://www.sprout-technology.com"}])
377
379
 
378
380
  got_run = CF::Run.all
379
- got_run.first.line.title.should eql("digitizard--11111000")
380
- got_run.first.title.should eql("run-name--11111000")
381
- got_run.last.line.title.should eql("progress_run_line_31")
382
- got_run.last.title.should eql("progress_run_31")
381
+ got_run.first.line.title.should eql("keyword_matching_robot_result")
382
+ got_run.first.title.should eql("keyword_matching_robot_run_result")
383
+ got_run.last.line.title.should eql("digarde-007")
384
+ got_run.last.title.should eql("runnamee1")
383
385
  end
384
386
  end
385
387
 
@@ -15,8 +15,8 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "sentiment_robot_run", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
17
17
  output = run.final_output
18
- output.first.final_output.first.sentiment_of_url.should eql("positive")
19
- output.first.final_output.first.sentiment_relevance_of_url.should eql(24.0408)
18
+ output.first['sentiment_of_url'].should eql("positive")
19
+ output.first['sentiment_relevance_of_url'].should eql(24.0408)
20
20
  line.stations.first.worker.class.should eql(CF::RobotWorker)
21
21
  line.stations.first.worker.reward.should eql(0.5)
22
22
  line.stations.first.worker.number.should eql(1)
@@ -40,8 +40,8 @@ module CF
40
40
 
41
41
  run = CF::Run.create(line, "sentiment_robot_run_1", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
42
42
  output = run.final_output
43
- output.first.final_output.first.sentiment_of_url.should eql("positive")
44
- output.first.final_output.first.sentiment_relevance_of_url.should eql(24.0408)
43
+ output.first['sentiment_of_url'].should eql("positive")
44
+ output.first['sentiment_relevance_of_url'].should eql(24.0408)
45
45
  line.stations.first.worker.class.should eql(CF::RobotWorker)
46
46
  line.stations.first.worker.reward.should eql(0.5)
47
47
  line.stations.first.worker.number.should eql(1)
data/spec/station_spec.rb CHANGED
@@ -53,8 +53,8 @@ describe CF::Station do
53
53
  end
54
54
  end
55
55
  line.stations.first.type.should eq("WorkStation")
56
- line.stations.first.worker.number.should == 2
57
- line.stations.first.worker.reward.should == 20
56
+ line.stations.first.worker.number.should eql(2)
57
+ line.stations.first.worker.reward.should eql(20)
58
58
  line.stations.first.form.title.should eq("Enter text from a business card image")
59
59
  line.stations.first.form.instruction.should eq("Describe")
60
60
  line.stations.first.form.form_fields[0].label.should eq("First Name")
@@ -251,4 +251,39 @@ describe CF::Station do
251
251
  end
252
252
  end
253
253
  end
254
+
255
+ context "create station with batch size option" do
256
+ it "for work station in block DSL way" do
257
+ # WebMock.allow_net_connect!
258
+ VCR.use_cassette "stations/block/create-with-batch-size", :record => :new_episodes do
259
+ line = CF::Line.create("batch_size_line", "Digitization") do
260
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
261
+ CF::Station.create({:line => self, :type => "work", :batch_size => 3}) do |s|
262
+ CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
263
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
264
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
265
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
266
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
267
+ end
268
+ end
269
+ end
270
+ line.stations.first.type.should eql("WorkStation")
271
+ line.stations.first.batch_size.should eql(3)
272
+ line.stations.first.worker.number.should eql(2)
273
+ line.stations.first.worker.reward.should eql(20)
274
+ end
275
+ end
276
+
277
+ it "for work station in Plain Ruby way" do
278
+ # WebMock.allow_net_connect!
279
+ VCR.use_cassette "stations/plain-ruby/create-with-batch-size", :record => :new_episodes do
280
+ line = CF::Line.new("batch_size_line_1", "Digitization")
281
+ CF::InputFormat.new({:line => line, :name => "image_url", :required => true, :valid_type => "url"})
282
+ station = CF::Station.new({:type => "work", :batch_size => 3})
283
+ line.stations station
284
+ line.stations.first.type.should eql("WorkStation")
285
+ line.stations.first.batch_size.should eql(3)
286
+ end
287
+ end
288
+ end
254
289
  end
@@ -15,8 +15,8 @@ module CF
15
15
  end
16
16
  run = CF::Run.create(line, "term_extraction_run", [{"url"=> "http://www.sprout-technology.com"}])
17
17
  output = run.final_output
18
- output.first.final_output.first.keyword_relevance_of_url.should eql([99.7991, 95.6566, 83.2383, 79.39450000000001, 76.0281])
19
- output.first.final_output.first.keywords_of_url.should eql(["Web App", "web application", "Web App Development", "Web App Management", "world-class web development"])
18
+ output.first['keyword_relevance_of_url'].should eql([99.7991, 95.6566, 83.2383, 79.39450000000001, 76.0281])
19
+ output.first['keywords_of_url'].should eql(["Web App", "web application", "Web App Development", "Web App Management", "world-class web development"])
20
20
  line.stations.first.worker.class.should eql(CF::RobotWorker)
21
21
  line.stations.first.worker.reward.should eql(0.5)
22
22
  line.stations.first.worker.number.should eql(1)
@@ -40,8 +40,8 @@ module CF
40
40
 
41
41
  run = CF::Run.create(line, "term_extraction_run_1", [{"url"=> "http://www.sprout-technology.com"}])
42
42
  output = run.final_output
43
- output.first.final_output.first.keyword_relevance_of_url.should eql([99.7991, 95.6566, 83.2383, 79.39450000000001, 76.0281])
44
- output.first.final_output.first.keywords_of_url.should eql(["Web App", "web application", "Web App Development", "Web App Management", "world-class web development"])
43
+ output.first['keyword_relevance_of_url'].should eql([99.7991, 95.6566, 83.2383, 79.39450000000001, 76.0281])
44
+ output.first['keywords_of_url'].should eql(["Web App", "web application", "Web App Development", "Web App Management", "world-class web development"])
45
45
  line.stations.first.worker.class.should eql(CF::RobotWorker)
46
46
  line.stations.first.worker.reward.should eql(0.5)
47
47
  line.stations.first.worker.number.should eql(1)
@@ -28,8 +28,8 @@ module CF
28
28
  # debugger
29
29
  output = run.final_output
30
30
  station_1_output = run.output(:station => 1)
31
- station_1_output['description'].should eql(["this is description", "about company", "the company works on", "Ruby on Rails"])
32
- output.first.final_output.first.append_description.should eql("this is description||about company||the company works on||Ruby on Rails")
31
+ station_1_output.first['description'].should eql(["this is description", "about company", "the company works on", "Ruby on Rails"])
32
+ output.first['append_description'].should eql("this is description||about company||the company works on||Ruby on Rails")
33
33
  line.stations.last.worker.class.should eql(CF::RobotWorker)
34
34
  line.stations.first.worker.reward.should eql(20)
35
35
  line.stations.first.worker.number.should eql(1)
@@ -72,8 +72,8 @@ module CF
72
72
  # debugger
73
73
  output = run.final_output
74
74
  station_1_output = run.output(:station => 1)
75
- station_1_output['description'].should eql(["this is description", "about company", "the company works on", "Ruby on Rails"])
76
- output.first.final_output.first.append_description.should eql("this is description||about company||the company works on||Ruby on Rails")
75
+ station_1_output.first['description'].should eql(["this is description", "about company", "the company works on", "Ruby on Rails"])
76
+ output.first['append_description'].should eql("this is description||about company||the company works on||Ruby on Rails")
77
77
  line.stations.last.worker.class.should eql(CF::RobotWorker)
78
78
  line.stations.first.worker.reward.should eql(20)
79
79
  line.stations.first.worker.number.should eql(1)