Created
September 17, 2010 03:28
-
-
Save bikashp/583616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RAILS APP / PHP APP, ETC | |
# RUBY GEM / PHP LIBRARY / JAVA LIBRARY, ETC | |
# REST API | |
# PLATFORM + ASSEMBLY LINES | |
# Build the assembly line | |
# Each AssemblyLine has 1 or more Stations | |
# Each Station has at least one HumanWorker or 1 RobotWorker | |
# Each Station also has Instructions and (optional) Input Data | |
line = AssemblyLine.new(:title: "Bizcard digitization", :public: true, :tags: "Image tagging, digitization, bizcard") | |
#Station.new(:name: "Ocr", :assembly_line: line) | |
ocr_station = Station.new("Ocr",line) | |
#ocr_worker = OcrWorker.new(ocr_station) | |
ocr_worker = OcrWorker.new(ocr_station, {:reward: 10}) | |
#ocr_station.instruction = OcrInstruction.new({:user_input: ""}) | |
#line.stations << ocr_station | |
# review_station = Station.new() | |
# # review_station.input = ocr_station.output /// But no need because AssemblyLine does this automatically | |
# review_station.worker = HumanWorker.new({:number: 3}) | |
# review_station.instruction = HumanInstruction.new() | |
# line.stations << review_station | |
# line.send_to_platform | |
# Assembly Line 1 (template/class) | |
# - Global description and design of a Line that is used to select the line for a production run | |
# Assembly Line 2 (instance) | |
# - Takes one unit and performs a series of tasks at stations to give one result | |
# Do a production run on the assembly line | |
run = ProductionRun.new(:assembly_line: Line.find(14573), :title:: "First 100 Bizcards (trial)") | |
run.input = FileInputData.new(path) # or GoogleSpreadsheet.import(url) | |
run.start | |
run.pause | |
run.cancel | |
run.delete | |
run.status | |
run.notify(callback_url) | |
# Do another production run on that assembly line | |
line = DigitalFactory.find(36537) | |
run = ProductionRun.new(:assembly_line: line, :title:: "10,000 Bizcards - urgent!") | |
# | |
# w = RobotWorker.new | |
# w.get_instruction_form | |
# | |
# w.send(instructions, input_data) | |
# Run Document #1 | |
{ | |
"title": "Find info for these 50 companies", | |
"line_id": 234245, | |
"order": {"amount": 23454, "service_charge": 2342}, | |
"result": { | |
"units": [ | |
[{"task_id": "32klj423l23kj4","company": "Apple", "website": "http://www.apple.com"}], | |
[{"task_id": "32klj423l23kj4","company": "Microsoft", "website": "http://www.microsoft.com"}], | |
[{"task_id": "32klj423l23kj4","company": "Google", "website": "http://www.google.com"}] | |
], | |
"version": 1, | |
"station_id": 23454, | |
"versions": [ ] | |
} | |
} | |
# Run Document #2 | |
{ | |
"title": "Find info for these 50 companies", | |
"line_id": BSON::ObjectId(234245) | |
"order": {:_id: 2342, :amount: 23454, :service_charge: 2342} | |
"result": { | |
"units": [ | |
[{"ceo": "Steve Jobs", "email": "info@apple.com"}, {"ceo": "Steve Job", "email": "info@apple.com"}], | |
[{"ceo": "Steve Balmer", "email": "info@microsoft.com"}, {"ceo": "Bill Gates", "email": "info@apple.com"}], | |
... | |
[{"ceo": "Larry Page", "email": "info@google.com"}, {"ceo": "Sergey Brin", "email": "info@apple.com"}] | |
] | |
"version": 2 | |
"versions": [ | |
{ "units": [ | |
[{:company: "Apple", :website: "http://www.apple.com"}], | |
[{:company: "Microsoft", :website: "http://www.microsoft.com"}], | |
... | |
[{:company: "Google", :website: "http://www.google.com"}] | |
], | |
"version": 1 | |
} | |
] | |
} | |
} | |
# Run Document #3 | |
{ | |
"title": "Find info for these 50 companies", | |
"line_id": 23453453, | |
"order": {"amount": 23454, "service_charge": 2342}, | |
"stations": [ | |
{ "station_design_id": 312, | |
"units": [ | |
{"results": [{"task_id": "234s324sdff","worker_id": "234dsfsdf3424", "company": "Apple", "website": "http://www.apple.com"}]}, | |
{"results": [{"task_id": "sdfwewer324324","worker_id": "234dsfsdf3424", "company": "Microsoft", "website": "http://www.microsoft.com"}]}, | |
{"results": [{"task_id": "sdf234324","worker_id": "234dsfsdf3424", "company": "Google", "website": "http://www.google.com"}]} | |
] | |
}, | |
{ "station_design_id": 1234, | |
"units": [ | |
{"results": [{"task_id": "sdfwe234","worker_id": "234dsfsdf3424", "ceo": "Steve Jobs", "email": "info@apple.com"}, {"task_id": "sdfwe234","worker_id": "fddsr33465sdf", "ceo": "Steve Ballmer", "email": "info@appleinc.com"}]}, | |
{"results": [{"task_id": "234sdfsfd","worker_id": "234dsfsdf3424", "ceo": "Steve Balmer", "email": "info@microsoft.com"}, {"task_id": "234sdfsfd","worker_id": "sfds34344sdf", "ceo": "Steve Jobs", "email": "contact@microsoft.com"}]}, | |
{"results": [{"task_id": "sdfsdfsdfwerwer234","worker_id": "234dsfsdf3424", "ceo": "Larry Page", "email": "info@google.com"}, {"task_id": "sdfsdfsdfwerwer234","worker_id": "sdgdf45412dsfds", "ceo": "Larry Bran", "email": "info@googleco.com"}]} | |
] | |
}, | |
{ "station_design_id": 123, | |
"units": [ | |
{"results": [{"task_id": "23423432dsfdsf","worker_id": "234dsfsdf3424", "ceo": "Steve Jobs", "email": "info@apple.com"}]}, | |
{"results": [{"task_id": "234234sdfsdf","worker_id": "234dsfsdf3424", "ceo": "Steve Balmer", "email": "info@microsoft.com"}]}, | |
{"results": [{"task_id": "2342dsafdsf","worker_id": "234dsfsdf3424", "ceo": "Larry Page", "email": "info@google.com"}]} | |
] | |
} | |
] | |
} | |
# Line | |
{ | |
"title": "Company Finder", | |
"description": "Find the companies information", | |
"input_template_columns": [ | |
{"field_id": "field_1", "label": "company name", "field_type": "text_data", | |
"options": {"value": "Sprout", "required": true, "validation_format": "general"}} | |
] | |
"station_design_ids": [312, 1234, 123], | |
"run_ids": [234,5,2234,52343,123] | |
"user_id": 2323 | |
} | |
# StationDesign 1 | |
{ | |
"title": "2 people research each company", | |
"line_id": 153, | |
"instruction": { | |
"title": "Give ceo, email of following companies", | |
"form_fields":[ | |
{"field_id": "field_1", "label": "Instructions", "type": "descriptive_content", "options": {"value": "Here is the company and its website link, fill out form below:", "show_label": false}}, | |
{"field_id": "field_2", "label": "ceo", "type": "short_answer"}, | |
{"field_id": "field_3", "label": "email", "type": "email", "options": {"required": true}} | |
] | |
}, | |
"worker": {"worker_type": "competitor", "reward": 2, "number": 2, "options": {"approval_rating": 75, "auto_approval_time": 7200, "question_reservation_time": 1200} } | |
} | |
# StationDesign 2 | |
{ | |
"title": "Choose the correct result out of the 2", | |
"line_id": 153, | |
"instruction": { | |
"title": "Determine correct CEO and email for the following company", | |
"form_fields":[ | |
{"field_id": "field_1", "label": "Pre-Instructions", "type": "descriptive_content", "options": {"value": "Multiple people were asked to complete the task below. See their answers and select the correct/best one", "show_label": false}}, | |
{"field_id": "field_2", "label": "Instructions", "type": "descriptive_content", "options": {"value": "Here is the company and its website link, fill out form below", "show_label": false}}, | |
{"field_id": "field_2", "label": "Company", "type": "descriptive_content", "value": "Email: ||station.previous.previous.results[0].company||"}, | |
{"field_id": "field_3", "label": "Website", "type": "descriptive_content", "value": "Email: ||station.previous.previous.results[0].website||"} | |
{"field_id": "field_4", "label": "Choose the correct result:", "type": "multiple_choice", "values": ["||station.previous.results[0]||", "||station.previous.results[1]||"]} | |
] | |
}, | |
"worker": {"worker_type": "judge", "reward": 1, "number": 1, "approval_rating": 75, "auto_approval_time": 7200, "question_reservation_time": 1200 } | |
} | |
# StationDesign 3 (Robot(OCR) worker) | |
{ | |
"title": "Review company website, email", | |
"line_id": 153, | |
"instruction": { | |
"title": "Find whether the CEO given relates to the company website or not", | |
"form_fields":[ | |
{"field_id": "field_5", "label": "Is it correct?", "type": "boolean"} | |
] | |
}, | |
"worker": {"worker_type": "OCR", "reward": 4, "number": 1, "approval_rating": 75, "auto_approval_time": 7200, "question_reservation_time": 1200 } | |
} | |
{ | |
"title": "Find info for these 50 companies", | |
"line_id": 23453453, | |
"order": {"amount": 23454, "service_charge": 2342}, | |
"stations": [ | |
{ "station_design_id": 312}, | |
{ "station_design_id": 312}, | |
{ "station_design_id": 312} | |
] | |
} | |
unit = Unit.new | |
unit.results << Result.new({:company => "Apple"}) | |
stations.first.units << unit | |
{ | |
"title": "Find info for these 50 companies", | |
"line_id": 23453453, | |
"order": {"amount": 23454, "service_charge": 2342}, | |
"stations": [ | |
{ "station_design_id": 312, | |
"units": [ | |
"results": [{"company": "Apple"}] | |
]}, | |
{ "station_design_id": 312}, | |
{ "station_design_id": 312} | |
] | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run = line.runs.build(:title => "Production run of Company info line") | |
inputs = File.read("#{Rails.root}/spec/support/company.csv") | |
run.input_data(inputs) | |
class Run | |
include Mongoid::Document | |
def input_data(inputs) | |
csv_contents = CSV.parse(inputs) | |
csv_header = csv_contents[0].map{|a| a.strip } | |
csv_contents[1..-1].each do |item| | |
# TODO: Validation. | |
# Note:: While validating input data, collect invalid row(data) and process the others. Display invalid data to | |
# user later | |
next unless item # Escape nil items. This may result while reading csv file with blank line | |
# Convert csv data to hash. ['id','company'], [1, 'Google'] => {'id' => 1, 'company' => 'Google'} | |
data = Hash[csv_header.zip(item.map{|a| a.strip })] | |
# Add the unit as input data to the production run (which will in turn pass it on to the first station) | |
run.stations.first.units << Unit.new(data) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment