cloudfactory 0.4.5 → 0.4.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## 0.4.5 (2012-02-14)
2
+ * Template and Template file added for bulk goldstandards from csv
3
+ * Line deletion with runs bug fixed
4
+
1
5
  ## 0.4.5 (2012-02-01)
2
6
 
3
7
  * Gold Standard added for line
@@ -82,12 +82,11 @@ module Cf # :nodoc: all
82
82
 
83
83
  # Check whether this line has existing runs or not
84
84
  resp_runs = CF::Run.all({:line_title => line_title})
85
-
86
- if resp_runs.has_key?("runs") && resp_runs['runs'].present?
85
+ if resp_runs.has_key?('total_runs') && (resp_runs['runs'] || resp_runs['test_runs'])
87
86
  say("!!! Warning !!!\nThe following are the existing production runs based on this line.", :yellow)
88
87
  existing_runs = Cf::Production.new([],{'line' => line_title, 'all' => true})
89
88
  existing_runs.list
90
-
89
+
91
90
  say("\n!!! Warning !!!\nDeleting this line will also delete all the existing production runs based on this line.\n", :yellow)
92
91
  delete_forcefully = agree("Do you still want to delete this line? [y/n] ")
93
92
  say("\n")
@@ -297,26 +296,33 @@ module Cf # :nodoc: all
297
296
  end
298
297
 
299
298
  #check the presence of gold standard and create goldstandards for the station
300
- say "Adding Gold Standards to stations", :green
301
299
  gold_standards = station_file['station']['gold_standards']
302
300
  if gold_standards
301
+ say "Adding Gold Standards to stations", :green
302
+ if gold_standards["template_file"]
303
+ gold_template_source = gold_standards["template_file"]
304
+ if File.exist?(gold_template_source)
305
+ gold_template = YAML::load(File.read(gold_template_source).strip)
306
+ gold_standards.merge!("template" => gold_template)
307
+ end
308
+ end
303
309
  if gold_standards.class == Hash#gold_standards["file"]
304
310
  gold_standard = CF::GoldStandard.new(gold_standards.merge!({:line => line,:station => s }))
305
- say_status "GoldStandard", "parameters '#{gold_standards}'"
311
+ say_status "GoldStandard from file", "'#{gold_standards[:file]}'"
306
312
  display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
307
313
  else
308
314
  gold_standards.each do |gold_options|
309
315
  gold_standard = CF::GoldStandard.new(gold_options.merge({:line => line,:station => s }))
310
- say_status "GoldStandard", "parameters '#{gold_options}'"
316
+ say_status "GoldStandard", "'#{gold_options["name"]}'"
311
317
  display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
312
318
  end
313
319
  end
314
320
  end
315
321
 
316
322
  #######create badge #########
317
- say "Adding Badges to station", :green
318
323
  badges = station_file['station']['badges']
319
324
  if badges
325
+ say "Adding Badges to station", :green
320
326
  badges.each do |s_badge|
321
327
  form = s_badge["test_attributes"]["form_attributes"]
322
328
  unless form.blank?
@@ -328,7 +334,7 @@ module Cf # :nodoc: all
328
334
  end
329
335
  end
330
336
  badge = CF::Badge.new(s_badge.merge({:line => line,:station => s }))
331
- say_status "Badge","parameters '#{s_badge}'"
337
+ say_status "Badge","'#{s_badge["name"] }'"
332
338
  display_error(line_title, "#{badge.errors}") if badge.errors.present?
333
339
  end
334
340
  end
@@ -343,17 +349,24 @@ module Cf # :nodoc: all
343
349
  end
344
350
 
345
351
  #check the presence of gold standard and create goldstandards for the line
346
- say "Adding GoldStandards to Line", :green
347
352
  gold_standards = line_dump['gold_standards'].presence
348
353
  if gold_standards
354
+ say "Adding GoldStandards to Line", :green
355
+ if gold_standards["template_file"]
356
+ gold_template_source = gold_standards["template_file"]
357
+ if File.exist?(gold_template_source)
358
+ gold_template = YAML::load(File.read(gold_template_source).strip)
359
+ gold_standards.merge!("template" => gold_template)
360
+ end
361
+ end
349
362
  if gold_standards.class == Hash#gold_standards["file"]
350
363
  gold_standard = CF::GoldStandard.new(gold_standards.merge!({:line => line}))
351
- say_status "GoldStandard", "parameters '#{gold_standards}'"
364
+ say_status "GoldStandard from file", "'#{gold_standards[:file]}'"
352
365
  display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
353
366
  else
354
367
  gold_standards.each do |gold_options|
355
368
  gold_standard = CF::GoldStandard.new(gold_options.merge(:line => line))
356
- say_status "GoldStandard", "parameters '#{gold_options}'"
369
+ say_status "GoldStandard", "'#{gold_options["name"]}'"
357
370
  display_error(line_title, "#{gold_standard.errors}") if gold_standard.errors.present?
358
371
  end
359
372
  end
@@ -9,7 +9,6 @@
9
9
 
10
10
  title: <%= title.underscore.dasherize %>
11
11
  public: false
12
- public: true
13
12
  description: A shiny new assembly line ready for you to customize. Right now it is finding people dates (uncomment and try for fun) but you should just replace everything below accordingly for your line.
14
13
 
15
14
  # Department to build line in (See http://cloudfactory.com/developers/resources/department.html)
@@ -34,14 +34,15 @@ module CF
34
34
  if !@line.nil? || @station
35
35
  options.delete(:station) if @settings[:station].present?
36
36
  options.delete(:line)
37
+ # for bulk_gold_standard
37
38
  if options[:file] || options["file"]
38
39
  options.symbolize_keys!
39
40
  file_upload = File.new(options[:file], 'rb')
40
41
  if @station
41
- resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/stations/#{@station.index}/gold_standards.json", {:file => file_upload})
42
+ resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/stations/#{@station.index}/gold_standards.json", {:file => file_upload,:template => options[:template]})
42
43
  @station.gold_standards = self
43
44
  else
44
- resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/gold_standards.json", {:file => file_upload})
45
+ resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/gold_standards.json", {:file => file_upload,:template => options[:template]})
45
46
  @line.gold_standards = self
46
47
  end
47
48
  else
@@ -242,7 +242,7 @@ module CF
242
242
  puts gold_standard_options[:file]
243
243
  if File.exist?(gold_standard_options[:file].to_s)
244
244
  file_upload = File.new(gold_standard_options[:file], 'rb')
245
- resp = self.class.post("/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json", {:file => file_upload})
245
+ resp = self.class.post("/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json", {:file => file_upload, :template => gold_standard_options[:template]})
246
246
  gold_standard = CF::GoldStandard.new()
247
247
  resp.each do |gs|
248
248
  gold_standard.settings.merge!(gs.to_hash)
@@ -338,7 +338,7 @@ module CF
338
338
  if gold_standard_options[:file]
339
339
  if File.exist?(gold_standard_options[:file].to_s)
340
340
  file_upload = File.new(gold_standard_options[:file], 'rb')
341
- resp = self.class.post("/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json", {:file => file_upload})
341
+ resp = self.class.post("/lines/#{CF.account_name}/#{line.title.downcase}/gold_standards.json", {:file => file_upload,:template => gold_standard_options[:template]})
342
342
  gold_standard = CF::GoldStandard.new()
343
343
  resp.each do |gs|
344
344
  gold_standard.settings.merge!(gs.to_hash)
@@ -1,3 +1,3 @@
1
1
  module CF # :nodoc: all
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.5.1"
3
3
  end
@@ -27,7 +27,7 @@ describe CF::Badge do
27
27
  @badge = CF::Badge.create({
28
28
  :line => line,
29
29
  :station => s,
30
- :name => "Tomb Digitizer",
30
+ :name => "Tomb Digitizer#{Time.now}",
31
31
  :description => "This badge qualifies you to work on tomb digitization tasks.",
32
32
  :max_badges => 100,
33
33
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -65,7 +65,7 @@ describe CF::Badge do
65
65
  })
66
66
  end
67
67
  badge = CF::Badge.new({
68
- :name => "Tomb Digitizer",
68
+ :name => "Tomb Digitizer#{Time.now}",
69
69
  :description => "This badge qualifies you to work on tomb digitization tasks.",
70
70
  :max_badges => 100,
71
71
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -109,7 +109,7 @@ describe CF::Badge do
109
109
  @badge = CF::Badge.new({
110
110
  :line => line,
111
111
  :station => s,
112
- :name => "Tomb Digitizer",
112
+ :name => "Tomb Digitizer#{Time.now}",
113
113
  :description => "This badge qualifies you to work on tomb digitization tasks.",
114
114
  :max_badges => 100,
115
115
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -163,7 +163,7 @@ describe CF::Badge do
163
163
  @badge = CF::Badge.new({
164
164
  :line => line,
165
165
  :station => s,
166
- :name => "Tomb Digitizer",
166
+ :name => "Tomb Digitizer#{Time.now}",
167
167
  :description => "This badge qualifies you to work on tomb digitization tasks.",
168
168
  :max_badges => 100,
169
169
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -209,7 +209,7 @@ describe CF::Badge do
209
209
  })
210
210
  end
211
211
  badge = CF::Badge.new({
212
- :name => "Tomb Digitizer",
212
+ :name => "Tomb Digitizer#{Time.now}",
213
213
  :description => "This badge qualifies you to work on tomb digitization tasks.",
214
214
  :max_badges => 100,
215
215
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -256,7 +256,7 @@ describe CF::Badge do
256
256
  })
257
257
  end
258
258
  badge = CF::Badge.new({
259
- :name => "Tomb Digitizer",
259
+ :name => "Tomb Digitizer#{Time.now}",
260
260
  :description => "This badge qualifies you to work on tomb digitization tasks.",
261
261
  :max_badges => 100,
262
262
  :gold_standards => ["#{@gold_standard.settings[:name]}"],
@@ -85,6 +85,49 @@ describe CF::GoldStandard do
85
85
  line.gold_standards.first.settings["input"].should eql({"Website"=>"aaple.com"})
86
86
  line.gold_standards.first.settings["expected_output"].present?.should eql(true)
87
87
  end
88
+
89
+ it "should add gold standard to a line from a csv with predefined code template in Block DSL way" do
90
+ WebMock.allow_net_connect!
91
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
92
+ sleep 1
93
+ line = CF::Line.create(title,"Digitization") do |l|
94
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
95
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
96
+ CF::Station.create({:line => l, :type => "work"}) do |s|
97
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
98
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
99
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
100
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
101
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
102
+ end
103
+ end
104
+ end
105
+ gold_standard = CF::GoldStandard.new({:line => line,:file =>"./spec/gold_standards.csv",
106
+ :template=>[{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}]})
107
+ gold_standard.settings[:template].should eql([{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}])
108
+ line.gold_standards.should include(gold_standard)
109
+ end
110
+
111
+ it "should add gold standard to a line from a csv with predefined code template in plain ruby way" do
112
+ WebMock.allow_net_connect!
113
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
114
+ sleep 1
115
+ line = CF::Line.create(title,"Digitization") do |l|
116
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
117
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
118
+ end
119
+ station = CF::Station.new({:type => "work"})
120
+ line.stations station
121
+ gold_standard = CF::GoldStandard.new({:file =>"./spec/gold_standards.csv",
122
+ :template=>[{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}]})
123
+ line.gold_standards gold_standard
124
+ line.gold_standards.first.settings["expected_output"].should eql({"first_name"=>{"value"=>"<% John.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, "last_name"=>{"value"=>"<% Lennon.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, "company"=>{"value"=>"Sprout"}})
125
+ line.gold_standards.first.settings["name"].should eql("gold_standard_1")
126
+ line.gold_standards.first.settings["input"].should eql({"Website"=>"aaple.com"})
127
+ line.gold_standards.first.settings["expected_output"].present?.should eql(true)
128
+ end
129
+
130
+
88
131
  end
89
132
 
90
133
  context "should add goldstandard to a station" do
@@ -175,5 +218,49 @@ describe CF::GoldStandard do
175
218
  line.stations.first.gold_standards.first.settings["input"].should eql({"Website"=>"aaple.com"})
176
219
  line.stations.first.gold_standards.first.settings["expected_output"].present?.should eql(true)
177
220
  end
221
+
222
+ it "should add gold standard to the station from csv with predefined code template in block DSL way" do
223
+ WebMock.allow_net_connect!
224
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
225
+ sleep 1
226
+ line = CF::Line.create(title,"Digitization") do |l|
227
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
228
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
229
+ end
230
+ station = CF::Station.create({:line => line, :type => "work"}) do |s|
231
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 10})
232
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
233
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
234
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
235
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
236
+ end
237
+ @gold_standard = CF::GoldStandard.create({ :line => line,
238
+ :station => s,
239
+ :file =>"./spec/gold_standards.csv",
240
+ :template=>[{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}]
241
+ })
242
+ end
243
+ @gold_standard.settings[:template].should eql([{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}])
244
+ line.stations.first.gold_standards.should include(@gold_standard)
245
+ end
246
+
247
+ it "should add gold standard to a station from csv with predefined code template in plain ruby way" do
248
+ WebMock.allow_net_connect!
249
+ title = "line_title#{Time.new.strftime('%Y%b%d-%H%M%S')}".downcase
250
+ sleep 1
251
+ line = CF::Line.create(title,"Digitization") do |l|
252
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
253
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
254
+ end
255
+ station = CF::Station.new({:type => "work"})
256
+ line.stations station
257
+ gold_standard = CF::GoldStandard.new({:file =>"./spec/gold_standards.csv",:template=>[{"first_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, {"last_name"=>"<% {{variable}}.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}] })
258
+ line.stations.first.gold_standards gold_standard
259
+ line.stations.first.gold_standards.first.settings["expected_output"].should eql({"first_name"=>{"value"=>"<% John.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, "last_name"=>{"value"=>"<% Lennon.sort.eql?first_name.each{|a| a.downcase!}.sort %>"}, "company"=>{"value"=>"Sprout"}})
260
+ line.stations.first.gold_standards.first.settings["name"].should eql("gold_standard_1")
261
+ line.stations.first.gold_standards.first.settings["input"].should eql({"Website"=>"aaple.com"})
262
+ line.stations.first.gold_standards.first.settings["expected_output"].present?.should eql(true)
263
+ end
264
+
178
265
  end
179
266
  end
@@ -1,2 +1,2 @@
1
- Website,image_url,first_name,last_name,company
2
- aaple.com,http://onwired.com/images/portfolio/linda-stanley-business-card.jpg,John,Lennon,Sprout
1
+ Website,first_name,last_name,company
2
+ aaple.com,John,Lennon,Sprout
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cloudfactory
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.5
5
+ version: 0.4.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - CloudFactory.com
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-01 00:00:00 Z
13
+ date: 2012-02-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n