Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migrate to cats
  • Loading branch information
samoli committed Jun 7, 2012
1 parent 9779ff5 commit 4cb02f7
Show file tree
Hide file tree
Showing 44 changed files with 476 additions and 365 deletions.
5 changes: 1 addition & 4 deletions .env_template
@@ -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
2 changes: 0 additions & 2 deletions Gemfile
Expand Up @@ -2,8 +2,6 @@ source 'https://rubygems.org'

gem 'rails', '3.2.2'
gem 'sqlite3'
gem "paperclip", "~> 3.0"
gem 'aws-sdk', '~> 1.3.4'
gem 'shared_workforce', '~> 0.2.2'
gem 'jquery-rails'

Expand Down
20 changes: 0 additions & 20 deletions Gemfile.lock
Expand Up @@ -29,13 +29,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
aws-sdk (1.3.9)
httparty (~> 0.7)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
builder (3.0.0)
cocaine (0.2.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand All @@ -52,9 +46,6 @@ GEM
factory_girl (~> 3.2.0)
railties (>= 3.0.0)
hike (1.2.1)
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.2)
Expand All @@ -70,14 +61,6 @@ GEM
mocha (0.11.4)
metaclass (~> 0.0.1)
multi_json (1.3.5)
multi_xml (0.5.1)
nokogiri (1.5.2)
paperclip (3.0.4)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand Down Expand Up @@ -129,18 +112,15 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
uuidtools (2.1.2)

PLATFORMS
ruby

DEPENDENCIES
aws-sdk (~> 1.3.4)
coffee-rails (~> 3.2.1)
factory_girl_rails
jquery-rails
mocha
paperclip (~> 3.0)
rails (= 3.2.2)
sass-rails (~> 3.2.3)
shared_workforce (~> 0.2.2)
Expand Down
66 changes: 66 additions & 0 deletions app/controllers/cats_controller.rb
@@ -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
83 changes: 0 additions & 83 deletions app/controllers/users_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/users_helper.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/audit.rb
@@ -0,0 +1,4 @@
class Audit < ActiveRecord::Base
belongs_to :cat

end
20 changes: 20 additions & 0 deletions app/models/cat.rb
@@ -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
16 changes: 0 additions & 16 deletions app/models/user.rb

This file was deleted.

18 changes: 18 additions & 0 deletions app/tasks/crop_cat_task.rb
@@ -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
19 changes: 19 additions & 0 deletions app/tasks/improve_description_of_cat_task.rb
@@ -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
20 changes: 20 additions & 0 deletions app/tasks/rotate_cat_task.rb
@@ -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
36 changes: 36 additions & 0 deletions app/tasks/tag_cat_task.rb
@@ -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
22 changes: 0 additions & 22 deletions app/tasks/tag_photo_task.rb

This file was deleted.

0 comments on commit 4cb02f7

Please sign in to comment.