Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Migrate to cats
- Loading branch information
Showing
44 changed files
with
476 additions
and
365 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
SHAREDWORKFORCE_API_KEY=my-api-key | ||
S3_KEY=my-s3-key | ||
S3_SECRET=my-s3-secret | ||
S3_BUCKET=my-s3-bucket | ||
SHAREDWORKFORCE_API_KEY=my-api-key |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
class CatsController < ApplicationController | ||
# GET /cats | ||
# GET /cats.json | ||
def index | ||
@cats = Cat.scoped | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @cats } | ||
end | ||
end | ||
|
||
# GET /cats/1 | ||
# GET /cats/1.json | ||
def show | ||
@cat = Cat.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @cat } | ||
end | ||
end | ||
|
||
# GET /cats/new | ||
# GET /cats/new.json | ||
def new | ||
@cat = Cat.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @cat } | ||
end | ||
end | ||
|
||
# POST /cats | ||
# POST /cats.json | ||
def create | ||
@cat = Cat.new(params[:cat]) | ||
|
||
respond_to do |format| | ||
if @cat.save | ||
format.html { redirect_to @cat, notice: 'Cat was successfully created.' } | ||
format.json { render json: @cat, status: :created, location: @cat } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @cat.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /cats/1 | ||
# PUT /cats/1.json | ||
def update | ||
@cat = Cat.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @cat.update_attributes(params[:cat]) | ||
format.html { redirect_to @cat, notice: 'Cat was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @cat.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Audit < ActiveRecord::Base | ||
belongs_to :cat | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Cat < ActiveRecord::Base | ||
|
||
has_many :audits | ||
after_save :tag_image, :if=>:image_url_changed? | ||
scope :finished, where('cropped_image_url IS NOT NULL') | ||
|
||
def tag_image | ||
TagCatTask.create(self) | ||
end | ||
|
||
def reject!(comment) | ||
update_attribute(:rejected, true) | ||
audit "Rejected because #{comment}" | ||
end | ||
|
||
def audit(comment) | ||
audits << Audit.new(:comment=>comment) | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CropCatTask | ||
include SharedWorkforce::Task | ||
|
||
title "Crop around the eyes, as closely as you can" | ||
|
||
answer_type :crop | ||
|
||
on_success :crop_cat | ||
|
||
def setup(cat) | ||
self.image_url = cat.rotated_image_url | ||
end | ||
|
||
def crop_cat(cat, responses) | ||
cat.audit "Eyes identified." | ||
cat.update_attribute(:cropped_image_url, responses.first[:new_image_url]) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ImproveDescriptionOfCatTask | ||
include SharedWorkforce::Task | ||
|
||
title "Improve the description of this cat" | ||
guidelines "Improve the descrption to make it more accurate, fix spelling mistakes, improve grammar and add some more descriptive language. (e.g. describe what it is doing)" | ||
|
||
answer_type :edit | ||
|
||
on_success :describe_cat | ||
|
||
def setup(cat) | ||
self.text = cat.description | ||
end | ||
|
||
def describe_cat(cat, responses) | ||
cat.audit "Cat described as #{responses.first[:answer]}." | ||
cat.update_attribute(:improved_description, responses.first[:answer]) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class RotateCatTask | ||
include SharedWorkforce::Task | ||
|
||
title "Make this cat upside down" | ||
guidelines "* Simply continue if the cat is already upside down" | ||
|
||
answer_type :rotate | ||
|
||
on_success :rotate_cat | ||
|
||
def setup(cat) | ||
self.image_url = cat.image_url | ||
end | ||
|
||
def rotate_cat(cat, responses) | ||
cat.audit "Cat flipped." | ||
cat.update_attribute(:rotated_image_url, responses.first[:new_image_url]) | ||
CropCatTask.create(cat) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class TagCatTask | ||
include SharedWorkforce::Task | ||
|
||
REJECT = ["Not a cat", "More than one cat"] | ||
ACCEPT = ["fluffy", "soft", "cute", "rough", "scary", "evil"] | ||
|
||
title "Tag this cat" | ||
answer_options REJECT + ACCEPT | ||
answer_type :tags | ||
|
||
on_success :tag_cat | ||
|
||
def setup(cat) | ||
self.image_url = cat.image_url | ||
end | ||
|
||
def tag_cat(cat, responses) | ||
answers = responses.map{|r| r[:answer] }.flatten | ||
cat.update_attribute("tags", answers.join(',')) | ||
|
||
if answers.any? {|a| a.in?(REJECT) } | ||
cat.reject!("image was #{answers.to_sentence}.") | ||
else | ||
if answers.any? | ||
cat.audit "Tagged as #{answers.to_sentence}." | ||
else | ||
cat.audit "No tags applied." | ||
end | ||
|
||
RotateCatTask.create(cat) | ||
ImproveDescriptionOfCatTask.create(cat) | ||
end | ||
|
||
cat.save! | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.