cloudfactory 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +11 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +10 -0
  4. data/README.md +44 -0
  5. data/Rakefile +40 -0
  6. data/bin/cf +8 -0
  7. data/cf.gemspec +76 -0
  8. data/example/google_translate_app/Gemfile +12 -0
  9. data/example/google_translate_app/config.ru +7 -0
  10. data/example/google_translate_app/google_translate_input.csv +4 -0
  11. data/example/google_translate_app/google_translator_app.rb +53 -0
  12. data/example/google_translate_app/views/index.haml +2 -0
  13. data/example/google_translate_app/views/layout.haml +7 -0
  14. data/example/google_translate_app/views/run.haml +4 -0
  15. data/example/google_translate_app/views/style.sass +2 -0
  16. data/example/human_worker_app/Gemfile +12 -0
  17. data/example/human_worker_app/config.ru +7 -0
  18. data/example/human_worker_app/human_worker_app.rb +55 -0
  19. data/example/human_worker_app/human_worker_input.csv +5 -0
  20. data/example/human_worker_app/public/app.js +12 -0
  21. data/example/human_worker_app/temp.csv +3 -0
  22. data/example/human_worker_app/views/index.haml +15 -0
  23. data/example/human_worker_app/views/layout.haml +10 -0
  24. data/example/human_worker_app/views/result.haml +18 -0
  25. data/example/human_worker_app/views/run.haml +12 -0
  26. data/example/human_worker_app/views/style.sass +25 -0
  27. data/example/sample_yaml_files/concept_tagging_robot.yaml +18 -0
  28. data/example/sample_yaml_files/content_scraping_robot.yaml +19 -0
  29. data/example/sample_yaml_files/entity_extraction_robot.yaml +18 -0
  30. data/example/sample_yaml_files/google_translate_robot.yaml +20 -0
  31. data/example/sample_yaml_files/image_processing_robot.yaml +20 -0
  32. data/example/sample_yaml_files/keyword_matching_and_text_extraction_robot.yaml +26 -0
  33. data/example/sample_yaml_files/mailer_robot.yaml +21 -0
  34. data/example/sample_yaml_files/media_converter_robot.yaml +21 -0
  35. data/example/sample_yaml_files/media_splitting_robot.yaml +20 -0
  36. data/example/sample_yaml_files/multiple_skill_badge.yaml +75 -0
  37. data/example/sample_yaml_files/sentiment_robot.yaml +19 -0
  38. data/example/sample_yaml_files/skill_badge.yaml +56 -0
  39. data/example/sample_yaml_files/stat_badge.yaml +40 -0
  40. data/example/sample_yaml_files/term_extraction_robot.yaml +20 -0
  41. data/example/sample_yaml_files/tournament_station_and_form_fields.yaml +40 -0
  42. data/features/form_generation.feature +46 -0
  43. data/features/form_preview.feature +98 -0
  44. data/features/line_creation.feature +99 -0
  45. data/features/line_deletion.feature +50 -0
  46. data/features/line_generation.feature +57 -0
  47. data/features/run.feature +141 -0
  48. data/features/support/cli_steps.rb +16 -0
  49. data/features/support/env.rb +23 -0
  50. data/features/target_url.feature +82 -0
  51. data/fixtures/api_credentials_example.yml +4 -0
  52. data/fixtures/input_data/media_converter_robot.csv +2 -0
  53. data/fixtures/input_data/test.csv +2 -0
  54. data/lib/cf.rb +94 -0
  55. data/lib/cf/account.rb +32 -0
  56. data/lib/cf/cli.rb +52 -0
  57. data/lib/cf/cli/config.rb +87 -0
  58. data/lib/cf/cli/form.rb +82 -0
  59. data/lib/cf/cli/line.rb +237 -0
  60. data/lib/cf/cli/production.rb +62 -0
  61. data/lib/cf/cli/templates/css_file.css.erb +22 -0
  62. data/lib/cf/cli/templates/form_preview.html.erb +17 -0
  63. data/lib/cf/cli/templates/html_file.html.erb +21 -0
  64. data/lib/cf/cli/templates/js_file.js.erb +18 -0
  65. data/lib/cf/cli/templates/line.tt +55 -0
  66. data/lib/cf/cli/templates/sample-line/form.css +27 -0
  67. data/lib/cf/cli/templates/sample-line/form.html +26 -0
  68. data/lib/cf/cli/templates/sample-line/form.js +7 -0
  69. data/lib/cf/cli/templates/sample-line/line.yml.erb +67 -0
  70. data/lib/cf/cli/templates/sample-line/sample-line.csv +3 -0
  71. data/lib/cf/client.rb +56 -0
  72. data/lib/cf/custom_task_form.rb +136 -0
  73. data/lib/cf/department.rb +24 -0
  74. data/lib/cf/final_output.rb +20 -0
  75. data/lib/cf/form_field.rb +62 -0
  76. data/lib/cf/human_worker.rb +67 -0
  77. data/lib/cf/input_format.rb +134 -0
  78. data/lib/cf/line.rb +231 -0
  79. data/lib/cf/robot_worker.rb +31 -0
  80. data/lib/cf/run.rb +158 -0
  81. data/lib/cf/station.rb +340 -0
  82. data/lib/cf/task_form.rb +147 -0
  83. data/lib/cf/version.rb +3 -0
  84. data/lib/generators/cf/form/form_generator.rb +55 -0
  85. data/lib/generators/cf/form/templates/cf_form.html.erb +11 -0
  86. data/lib/generators/cf/install/install_generator.rb +22 -0
  87. data/lib/generators/cf/install/templates/README +13 -0
  88. data/lib/generators/cf/install/templates/cloud_factory.rb +7 -0
  89. data/spec/account_spec.rb +11 -0
  90. data/spec/badge_spec.rb +88 -0
  91. data/spec/concept_tagging_robot_spec.rb +54 -0
  92. data/spec/config_spec.rb +20 -0
  93. data/spec/content_scraping_robot_spec.rb +58 -0
  94. data/spec/custom_task_form_spec.rb +190 -0
  95. data/spec/department_spec.rb +14 -0
  96. data/spec/entity_extraction_robot_spec.rb +56 -0
  97. data/spec/form_field_spec.rb +126 -0
  98. data/spec/generators/form_generator_spec.rb +60 -0
  99. data/spec/generators/install_generator_spec.rb +35 -0
  100. data/spec/google_translate_robot_spec.rb +64 -0
  101. data/spec/human_worker_spec.rb +118 -0
  102. data/spec/image_processing_robot_spec.rb +56 -0
  103. data/spec/input_format_spec.rb +113 -0
  104. data/spec/keyword_matching_and_text_extraction_robot_spec.rb +73 -0
  105. data/spec/line_spec.rb +338 -0
  106. data/spec/mailer_robot_spec.rb +62 -0
  107. data/spec/media_converter_robot_spec.rb +72 -0
  108. data/spec/media_splitting_robot_spec.rb +62 -0
  109. data/spec/run_spec.rb +298 -0
  110. data/spec/sentiment_robot_spec.rb +56 -0
  111. data/spec/spec_helper.rb +39 -0
  112. data/spec/station_spec.rb +256 -0
  113. data/spec/task_form_spec.rb +96 -0
  114. data/spec/term_extraction_robot_spec.rb +58 -0
  115. data/spec/text_appending_robot_spec.rb +86 -0
  116. metadata +472 -0
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module CF
5
+ describe CF::RobotWorker do
6
+ context "create a mailer robot worker" do
7
+ it "should create mailer robot worker for first station in Block DSL way" do
8
+ # WebMock.allow_net_connect!
9
+ VCR.use_cassette "robot_worker/mailer_robot/block/create-worker-single-station", :record => :new_episodes do
10
+ @template = "<html><body><h1>Hello {{user}} Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"
11
+ line = CF::Line.create("mailer_robot","Digitization") do |l|
12
+ CF::InputFormat.new({:line => l, :name => "to", :valid_type => "general", :required => "true"})
13
+ CF::Station.create({:line => l, :type => "work"}) do |s|
14
+ CF::RobotWorker.create({:station => s, :type => "mailer_robot", :settings => {:to => ["manish.das@sprout-technology.com"], :template => @template, :template_variables => {"user" =>"Manish"}}})
15
+ end
16
+ end
17
+ run = CF::Run.create(line, "mailer_robot_run", [{"to"=> "manish.das@sprout-technology.com"}])
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 Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
21
+ output.first.final_output.first.template.should eql("<html><body><h1>Hello {{user}} Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>")
22
+ output.first.final_output.first.template_variables.user.should eql("Manish")
23
+ output.first.final_output.first.template_variables.email.should eql("{{email}}")
24
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
25
+ line.stations.first.worker.reward.should eql(8)
26
+ line.stations.first.worker.number.should eql(1)
27
+ line.stations.first.worker.settings.should eql({:to => ["manish.das@sprout-technology.com"], :template => @template, :template_variables => {"user" =>"Manish"}})
28
+ line.stations.first.worker.type.should eql("MailerRobot")
29
+ end
30
+ end
31
+
32
+ it "should create mailer robot worker for first station in a plain ruby way" do
33
+ # WebMock.allow_net_connect!
34
+ VCR.use_cassette "robot_worker/mailer_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
35
+ @template = "<html><body><h1>Hello {{user}} Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"
36
+ line = CF::Line.new("mailer_robot_1","Digitization")
37
+ input_format = CF::InputFormat.new({:name => "to", :required => "true", :valid_type => "general"})
38
+ line.input_formats input_format
39
+
40
+ station = CF::Station.new({:type => "work"})
41
+ line.stations station
42
+
43
+ worker = CF::RobotWorker.create({:type => "mailer_robot", :settings => {:to => ["manish.das@sprout-technology.com"], :template => @template, :template_variables => {"user" =>"Manish"}}})
44
+ line.stations.first.worker = worker
45
+
46
+ run = CF::Run.create(line, "mailer_robot_run_1", [{"to"=> "manish.das@sprout-technology.com"}])
47
+ output = run.final_output
48
+ output.first.final_output.first.recipients_of_to.should eql(["manish.das@sprout-technology.com"])
49
+ output.first.final_output.first.sent_message_for_to.should eql(["<html><body><h1>Hello Manish Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>"])
50
+ output.first.final_output.first.template.should eql("<html><body><h1>Hello {{user}} Welcome to CLoudfactory!!!!</h1><p>Thanks for using!!!!</p></body></html>")
51
+ output.first.final_output.first.template_variables.user.should eql("Manish")
52
+ output.first.final_output.first.template_variables.email.should eql("{{email}}")
53
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
54
+ line.stations.first.worker.reward.should eql(8)
55
+ line.stations.first.worker.number.should eql(1)
56
+ line.stations.first.worker.settings.should eql({:to => ["manish.das@sprout-technology.com"], :template => @template, :template_variables => {"user" =>"Manish"}})
57
+ line.stations.first.worker.type.should eql("MailerRobot")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ module CF
4
+ describe CF::RobotWorker do
5
+ context "create a media converter robot worker" do
6
+ xit "should create media_converter_robot worker for first station in a plain ruby way" do
7
+ # WebMock.allow_net_connect!
8
+ VCR.use_cassette "robot_worker/media_converter_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
9
+ line = CF::Line.new("media_converter_robot","Digitization")
10
+
11
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
12
+ line.input_formats input_format
13
+
14
+ input_format_1 = CF::InputFormat.new({:name => "to", :required => false, :valid_type => "general"})
15
+ line.input_formats input_format_1
16
+
17
+ input_format_2 = CF::InputFormat.new({:name => "audio_quality", :required => false, :valid_type => "general"})
18
+ line.input_formats input_format_2
19
+
20
+ input_format_3 = CF::InputFormat.new({:name => "video_quality", :required => false, :valid_type => "general"})
21
+ line.input_formats input_format_3
22
+
23
+ station = CF::Station.new({:type => "work"})
24
+ line.stations station
25
+
26
+ worker = CF::RobotWorker.create({:type => "media_converter_robot", :settings => {:url => "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov", :to => "mpg", :audio_quality => "320", :video_quality => "3"}})
27
+ line.stations.first.worker = worker
28
+
29
+ form = CF::TaskForm.new({:title => "Enter text", :instruction => "Describe"})
30
+ line.stations.first.form = form
31
+
32
+ form_fields = CF::FormField.new({:label => "Description", :field_type => "SA", :required => "true"})
33
+ line.stations.first.form.form_fields form_fields
34
+
35
+ run = CF::Run.create(line, "media_converter_robot_run", [{"url"=> "www.s3.amazon.com/converted/20110518165230/ten.mpg", "to" => "mpg", "audio_quality" => "320", "video_quality" => "3", "meta_data_text"=>"media"}])
36
+ @final_output = run.final_output
37
+ line.stations.first.worker.number.should eq(1)
38
+ @final_output.first.final_output.first.audio_quality.should eql("320")
39
+ @final_output.first.final_output.first.video_quality.should eql("3")
40
+ @final_output.first.final_output.first.to.should eql("mpg")
41
+ converted_url = @final_output.first.final_output.first.converted_file_from_url.first
42
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
43
+ end
44
+ end
45
+
46
+ xit "should create media_converter_robot in block DSL way" do
47
+ # WebMock.allow_net_connect!
48
+ VCR.use_cassette "robot_worker/media_converter_robot/block/create-worker-block-dsl-way", :record => :new_episodes do
49
+ line = CF::Line.create("media_converter_robot_1","Digitization") do |l|
50
+ CF::InputFormat.new({:line => l, :name => "url", :required => true, :valid_type => "url"})
51
+ CF::InputFormat.new({:line => l, :name => "to", :required => false, :valid_type => "general"})
52
+ CF::InputFormat.new({:line => l, :name => "audio_quality", :required => false, :valid_type => "general"})
53
+ CF::InputFormat.new({:line => l, :name => "video_quality", :required => false, :valid_type => "general"})
54
+ CF::Station.create({:line => l, :type => "work"}) do |s|
55
+ CF::RobotWorker.create({:station => s, :type => "media_converter_robot", :settings => {:url => "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov", :to => "mpg", :audio_quality => "320", :video_quality => "3"}})
56
+ end
57
+ end
58
+
59
+ run = CF::Run.create(line, "media_converter_robot_run_1", [{"url"=> "www.s3.amazon.com/converted/20110518165230/ten.mpg", "to" => "mpg", "audio_quality" => "320", "video_quality" => "3", "meta_data_text"=>"media"}])
60
+
61
+ @final_output = run.final_output
62
+ line.stations.first.worker.number.should eq(1)
63
+ @final_output.first.final_output.first.audio_quality.should eql("320")
64
+ @final_output.first.final_output.first.video_quality.should eql("3")
65
+ @final_output.first.final_output.first.to.should eql("mpg")
66
+ converted_url = @final_output.first.final_output.first.converted_file_from_url.first
67
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url}").should eql(true)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module CF
5
+ describe CF::RobotWorker do
6
+ context "create a media splitting robot worker" do
7
+ it "should create media splitting robot worker for first station in Block DSL way" do
8
+ # WebMock.allow_net_connect!
9
+ VCR.use_cassette "robot_worker/media_splitting_robot/block/create-worker-single-station", :record => :new_episodes do
10
+ line = CF::Line.create("media_splitting_robot","Digitization") do |l|
11
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
12
+ CF::Station.create({:line => l, :type => "work"}) do |s|
13
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
14
+ end
15
+ end
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
+ output = run.final_output
18
+ output.first.final_output.first.overlapping_time.should eql("1")
19
+ output.first.final_output.first.split_duration.should eql("2")
20
+ converted_url_1= output.first.final_output.first.splits_of_url.first.first
21
+ converted_url_2= output.first.final_output.first.splits_of_url.first.last
22
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_1}").should eql(true)
23
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_2}").should eql(true)
24
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
25
+ line.stations.first.worker.reward.should eql(5)
26
+ line.stations.first.worker.number.should eql(1)
27
+ line.stations.first.worker.settings.should eql({:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"})
28
+ line.stations.first.worker.type.should eql("MediaSplittingRobot")
29
+ end
30
+ end
31
+
32
+ it "should create media splitting robot worker for first station in a plain ruby way" do
33
+ # WebMock.allow_net_connect!
34
+ VCR.use_cassette "robot_worker/media_splitting_robot/plain-ruby/create-worker-in-first-station", :record => :new_episodes do
35
+ line = CF::Line.new("media_splitting_robot_1","Digitization")
36
+ input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
37
+ line.input_formats input_format
38
+
39
+ station = CF::Station.new({:type => "work"})
40
+ line.stations station
41
+
42
+ worker = CF::RobotWorker.create({:type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
43
+ line.stations.first.worker = worker
44
+
45
+ run = CF::Run.create(line, "media_splitting_robot_run_1", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
46
+ output = run.final_output
47
+ output.first.final_output.first.overlapping_time.should eql("1")
48
+ output.first.final_output.first.split_duration.should eql("2")
49
+ converted_url_1= output.first.final_output.first.splits_of_url.first.first
50
+ converted_url_2= output.first.final_output.first.splits_of_url.first.last
51
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_1}").should eql(true)
52
+ File.exist?("/Users/manish/apps/cloudfactory/public#{converted_url_2}").should eql(true)
53
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
54
+ line.stations.first.worker.reward.should eql(5)
55
+ line.stations.first.worker.number.should eql(1)
56
+ line.stations.first.worker.settings.should eql({:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"})
57
+ line.stations.first.worker.type.should eql("MediaSplittingRobot")
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
data/spec/run_spec.rb ADDED
@@ -0,0 +1,298 @@
1
+ require 'spec_helper'
2
+
3
+ module CF
4
+ describe CF::Run do
5
+ context "create a new run" do
6
+ it "for a line in block dsl way" do
7
+ VCR.use_cassette "run/block/create-run", :record => :new_episodes do
8
+ # WebMock.allow_net_connect!
9
+ line = CF::Line.create("Digarde-007","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
+ CF::Station.create({:line => l, :type => "work"}) do |s|
13
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
14
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
15
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
16
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
17
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
18
+ end
19
+ end
20
+ end
21
+
22
+ run = CF::Run.create(line, "runnamee1", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
23
+
24
+ line.title.should eq("Digarde-007")
25
+
26
+ line.stations.first.input_formats.first['name'].should eq("Company")
27
+ line.stations.first.input_formats.first['required'].should eq(true)
28
+
29
+ line.stations[0].type.should eq("WorkStation")
30
+
31
+ line.stations[0].worker.number.should eq(1)
32
+ line.stations[0].worker.reward.should eq(20)
33
+
34
+ line.stations[0].form.title.should eq("Enter text from a business card image")
35
+ line.stations[0].form.instruction.should eq("Describe")
36
+
37
+ line.stations[0].form.form_fields[0].label.should eq("First Name")
38
+ line.stations[0].form.form_fields[0].field_type.should eq("SA")
39
+ line.stations[0].form.form_fields[0].required.should eq(true)
40
+
41
+ run.title.should eq("runnamee1")
42
+ runfile = File.read(run.file)
43
+ runfile.should == File.read(File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
44
+ end
45
+ end
46
+
47
+ it "should create a production run for input data as plain data" do
48
+ # WebMock.allow_net_connect!
49
+ VCR.use_cassette "run/block/create-run-without-file", :record => :new_episodes do
50
+ line = CF::Line.create("Digitizard--11111000","Digitization") do |l|
51
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
52
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
53
+ CF::Station.create({:line => l, :type => "work"}) do |s|
54
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
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 => "SA", :required => "true"})
57
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
58
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
59
+ end
60
+ end
61
+ end
62
+ run = CF::Run.create(line, "run-name--11111000", [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}])
63
+ run.input.should eql( [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}])
64
+ end
65
+ end
66
+
67
+ it "for an existing line" do
68
+ VCR.use_cassette "run/block/create-run-of-an-existing-line", :record => :new_episodes do
69
+ line = CF::Line.create("Digitizeard123","Digitization") do |l|
70
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
71
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
72
+ CF::Station.create({:line => l, :type => "work"}) do |s|
73
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
74
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
75
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
76
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
77
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
78
+ end
79
+ end
80
+ end
81
+ old_line = CF::Line.info(line.title)
82
+ run = CF::Run.create(old_line,"Runusingline", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
83
+ run.title.should eq("Runusingline")
84
+
85
+ end
86
+ end
87
+
88
+ it "for a line in a plain ruby way" do
89
+ VCR.use_cassette "run/plain-ruby/create-run", :record => :new_episodes do
90
+ line = CF::Line.new("Digitize--ard1", "Digitization")
91
+ station = CF::Station.new({:type => "work"})
92
+ line.stations station
93
+ input_format_1 = CF::InputFormat.new({:name => "Company", :required => true, :valid_type => "general"})
94
+ input_format_2 = CF::InputFormat.new({:name => "Website", :required => true, :valid_type => "url"})
95
+ line.input_formats input_format_1
96
+ line.input_formats input_format_2
97
+ worker = CF::HumanWorker.new({:number => 1, :reward => 20})
98
+ line.stations.first.worker = worker
99
+
100
+ form = CF::TaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe"})
101
+ line.stations.first.form = form
102
+
103
+ form_fields_1 = CF::FormField.new({:label => "First Name", :field_type => "SA", :required => "true"})
104
+ line.stations.first.form.form_fields form_fields_1
105
+ form_fields_2 = CF::FormField.new({:label => "Middle Name", :field_type => "SA"})
106
+ line.stations.first.form.form_fields form_fields_2
107
+ form_fields_3 = CF::FormField.new({:label => "Last Name", :field_type => "SA", :required => "true"})
108
+ line.stations.first.form.form_fields form_fields_3
109
+
110
+ run = CF::Run.create(line,"Run-in-plain-ruby-way", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
111
+
112
+ line.title.should eq("Digitize--ard1")
113
+ line.stations.first.type.should eq("WorkStation")
114
+
115
+ line.input_formats[0].name.should eq("Company")
116
+ line.input_formats[0].required.should eq(true)
117
+ line.input_formats[1].name.should eq("Website")
118
+ line.input_formats[1].required.should eq(true)
119
+
120
+ line.stations.first.worker.number.should eql(1)
121
+ line.stations.first.worker.reward.should eql(20)
122
+
123
+ line.stations.first.form.title.should eql("Enter text from a business card image")
124
+ line.stations.first.form.instruction.should eql("Describe")
125
+
126
+ line.stations.first.form.form_fields[0].label.should eql("First Name")
127
+ line.stations.first.form.form_fields[0].field_type.should eql("SA")
128
+ line.stations.first.form.form_fields[0].required.should eql(true)
129
+ line.stations.first.form.form_fields[1].label.should eql("Middle Name")
130
+ line.stations.first.form.form_fields[1].field_type.should eql("SA")
131
+ line.stations.first.form.form_fields[2].label.should eql("Last Name")
132
+ line.stations.first.form.form_fields[2].field_type.should eql("SA")
133
+ line.stations.first.form.form_fields[2].required.should eql(true)
134
+ end
135
+ end
136
+
137
+ it "should fetch result" do
138
+ VCR.use_cassette "run/block/create-run-fetch-result", :record => :new_episodes do
139
+ line = CF::Line.create("Digarde-00111111111","Digitization") do |l|
140
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
141
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
142
+ CF::Station.create({:line => l, :type => "work"}) do |s|
143
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
144
+ CF::TaskForm.create({:station => s, :title => "Enter blah from card image", :instruction => "Describe"}) do |i|
145
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
146
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
147
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
148
+ end
149
+ end
150
+ end
151
+ run = CF::Run.create(line, "run-name-result-0111111111", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
152
+ @final_output = run.final_output
153
+ @final_output.first.meta_data['company'].should eql("Apple")
154
+ @final_output.first.final_outputs.last['first-name'].should eql("Bob")
155
+ @final_output.first.final_outputs.last['last-name'].should eql("Marley")
156
+ end
157
+ end
158
+
159
+ xit "should fetch result of the specified station" do
160
+ VCR.use_cassette "run/block/fetch-result-of-specified-station", :record => :new_episodes do
161
+ line = CF::Line.create("Digitizeard-run-111","Digitization") do |l|
162
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
163
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
164
+ CF::Station.create({:line => l, :type => "work"}) do |s|
165
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
166
+ CF::TaskForm.create({:station => s, :title => "Enter name of CEO :station", :instruction => "Describe"}) do |i|
167
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
168
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
169
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
170
+ end
171
+ end
172
+ end
173
+ run = CF::Run.create(line, "run-name-run", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
174
+ # debugger
175
+ @final_output = run.final_output
176
+ @final_output.first.meta_data['company'].should eql("Apple")
177
+ @final_output.first.final_outputs.last['first-name'].should eql("Bob")
178
+ @final_output.first.final_outputs.last['last-name'].should eql("Marley")
179
+
180
+ result_of_station_1 = run.output(:station => 1)
181
+ result_of_station_1.first.meta_data['company'].should eql("Apple")
182
+ end
183
+ end
184
+
185
+ it "should fetch result of the specified station with run title" do
186
+ # WebMock.allow_net_connect!
187
+ VCR.use_cassette "run/block/fetch-result-with-title", :record => :new_episodes do
188
+ line = CF::Line.create("keyword_matching_robot_result","Digitization") do |l|
189
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
190
+ CF::Station.create({:line => l, :type => "work"}) do |s|
191
+ CF::RobotWorker.create({:station => s, :type => "text_extraction_robot", :settings => {:url => ["{url}"]}})
192
+ end
193
+ CF::Station.create({:line => l, :type => "work"}) do |s1|
194
+ CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
195
+ end
196
+ end
197
+ 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"}])
198
+ output = run.final_output
199
+ output.first.final_output.first.included_keywords_count_in_contents_of_url.should eql(["3", "2", "2"])
200
+ output.first.final_output.first.keyword_included_in_contents_of_url.should eql(["SaaS", "see", "additional"])
201
+ line.stations.first.worker.class.should eql(CF::RobotWorker)
202
+ line.stations.first.worker.reward.should eql(1)
203
+ line.stations.first.worker.number.should eql(1)
204
+ line.stations.first.worker.settings.should eql({:url => ["{url}"]})
205
+ line.stations.first.worker.type.should eql("TextExtractionRobot")
206
+ line.stations.last.worker.class.should eql(CF::RobotWorker)
207
+ line.stations.last.worker.reward.should eql(1)
208
+ line.stations.last.worker.number.should eql(1)
209
+ line.stations.last.worker.settings.should eql({:content => ["{contents_of_url}"], :keywords => ["SaaS","see","additional","deepak","saroj"]})
210
+ line.stations.last.worker.type.should eql("KeywordMatchingRobot")
211
+ output_of_station_1 = CF::Run.output({:title => "keyword_matching_robot_run_result", :station => 1})
212
+ output_of_station_2 = CF::Run.output({:title => "keyword_matching_robot_run_result", :station => 2})
213
+ output_of_station_2['keyword_included_in_contents_of_url'].should eql(["SaaS", "see", "additional"])
214
+ output_of_station_2['included_keywords_count_in_contents_of_url'].should eql(["3", "2", "2"])
215
+ end
216
+ end
217
+
218
+ it "should create production run with invalid input_format for input" do
219
+ # WebMock.allow_net_connect!
220
+ VCR.use_cassette "run/block/create-run-invalid-data", :record => :new_episodes do
221
+ line = CF::Line.create("media_splitting_robot_3","Digitization") do |l|
222
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
223
+ CF::Station.create({:line => l, :type => "work"}) do |s|
224
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
225
+ end
226
+ end
227
+ run = CF::Run.create(line, "media_splitting_robot_run_3", [{"url_1"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
228
+ run.errors.should eql(["Extra Headers in file: [url_1]", "Insufficient Headers in file: [url]"])
229
+ end
230
+ end
231
+
232
+ it "should create production run with invalid data" do
233
+ # WebMock.allow_net_connect!
234
+ VCR.use_cassette "run/block/create-run-invalid-file", :record => :new_episodes do
235
+ line = CF::Line.create("media_splitting_robot_4","Digitization") do |l|
236
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
237
+ CF::Station.create({:line => l, :type => "work"}) do |s|
238
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
239
+ end
240
+ end
241
+ run = CF::Run.create(line, "media_splitting_robot_run_4", File.expand_path("../../fixtures/input_data/media_converter_robot.csv", __FILE__))
242
+ run.errors.should eql(["Extra Headers in file: [url_1]", "Insufficient Headers in file: [url]"])
243
+
244
+ end
245
+ end
246
+
247
+ it "should create production run with used title data" do
248
+ # WebMock.allow_net_connect!
249
+ VCR.use_cassette "run/block/create-run-used-title", :record => :new_episodes do
250
+ line = CF::Line.create("media_splitting_robot_5","Digitization") do |l|
251
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
252
+ CF::Station.create({:line => l, :type => "work"}) do |s|
253
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
254
+ end
255
+ end
256
+ run = CF::Run.create(line, "media_splitting_robot_run_5", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
257
+ 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"}])
258
+ run_1.errors.should eql("[\"Title is already taken for this account\"]")
259
+ end
260
+ end
261
+
262
+ it "should create production run and find created run" do
263
+ # WebMock.allow_net_connect!
264
+ VCR.use_cassette "run/block/create-run-and-find", :record => :new_episodes do
265
+ line = CF::Line.create("media_splitting_robot_6","Digitization") do |l|
266
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
267
+ CF::Station.create({:line => l, :type => "work"}) do |s|
268
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
269
+ end
270
+ end
271
+ run = CF::Run.create(line, "media_splitting_robot_run_6", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
272
+ found_run = CF::Run.find("media_splitting_robot_run_6")
273
+ found_run.code.should eql(200)
274
+ found_run.title.should eql("media_splitting_robot_run_6")
275
+ found_run.line.title.should eql("media_splitting_robot_6")
276
+ found_run.line.department.should eql("Digitization")
277
+ found_run.status.should eql("active")
278
+ end
279
+ end
280
+
281
+ it "should create production run and try to find run with unused title" do
282
+ # WebMock.allow_net_connect!
283
+ VCR.use_cassette "run/block/find-run-with-unused-title", :record => :new_episodes do
284
+ line = CF::Line.create("media_splitting_robot_7","Digitization") do |l|
285
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
286
+ CF::Station.create({:line => l, :type => "work"}) do |s|
287
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
288
+ end
289
+ end
290
+ run = CF::Run.create(line, "media_splitting_robot_run_7", [{"url"=> "http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"}])
291
+ found_run = CF::Run.find("unused_title")
292
+ found_run.code.should eql(404)
293
+ found_run.errors.should eql("Run document not found using selector: {:tenant_id=>BSON::ObjectId('4def16fa5511274d98000014'), \"account_id\"=>BSON::ObjectId('4def122255112748d7000003'), :title=>\"unused_title\"}")
294
+ end
295
+ end
296
+ end
297
+ end
298
+ end