Permalink
Browse files

Initial turk form complete with candidate display.

  • Loading branch information...
1 parent 809cfcc commit bda0b1cf366f26ca4239f8ef015f31d5aafe0070 @aantix committed Jan 3, 2012
Showing with 646 additions and 144 deletions.
  1. +6 −4 Gemfile
  2. +28 −25 Gemfile.lock
  3. BIN app/assets/images/candidates/barack_obama.jpg
  4. BIN app/assets/images/candidates/jon_huntsman.jpg
  5. BIN app/assets/images/candidates/michele_bachmann.jpg
  6. BIN app/assets/images/candidates/mitt_romney.jpg
  7. BIN app/assets/images/candidates/newt_gingrich.jpg
  8. BIN app/assets/images/candidates/rick_perry.jpg
  9. BIN app/assets/images/candidates/rick_santorum.jpg
  10. BIN app/assets/images/candidates/ron_paul.jpg
  11. BIN app/assets/images/spinner.gif
  12. BIN app/assets/images/stop_sign.gif
  13. +19 −0 app/assets/javascripts/bootstrap.js.coffee
  14. +5 −0 app/assets/stylesheets/bootstrap.css.less
  15. +10 −0 app/assets/stylesheets/{transcriptions.css.scss → transcription_segments.css.scss}
  16. +7 −8 app/controllers/transcriptions_controller.rb
  17. +8 −0 app/models/candidate.rb
  18. +3 −0 app/models/category.rb
  19. +12 −0 app/models/human_validation.rb
  20. +4 −0 app/models/party.rb
  21. +10 −0 app/models/transcription.rb
  22. +4 −0 app/models/transcription_segment.rb
  23. +24 −10 app/models/video.rb
  24. +29 −0 app/models/video_segment.rb
  25. +1 −1 app/views/layouts/application.html.erb
  26. +76 −34 app/views/transcriptions/_form.html.erb
  27. +55 −0 app/views/transcriptions/_video.html.erb
  28. +0 −3 app/views/transcriptions/edit.html.erb
  29. +1 −8 app/views/transcriptions/index.html.erb
  30. +0 −4 app/views/transcriptions/new.html.erb
  31. +15 −0 db/migrate/20111218092939_create_videos.rb
  32. +12 −0 db/migrate/20111218093459_create_candidates.rb
  33. +9 −0 db/migrate/20111218093518_create_parties.rb
  34. +4 −3 db/migrate/20111219012519_create_video_segments.rb
  35. +0 −3 db/migrate/20111219012934_create_transcriptions.rb
  36. +11 −0 db/migrate/20111220083350_create_human_validations.rb
  37. +5 −0 db/migrate/20111228013302_add_candidate_id_to_videos.rb
  38. +11 −0 db/migrate/20111228013916_create_transcription_segments.rb
  39. +5 −0 db/migrate/20120103095032_add_image_to_candidates.rb
  40. +5 −0 db/migrate/20120103101646_add_searchable_to_candidates.rb
  41. +45 −15 db/schema.rb
  42. +32 −8 db/seeds.rb
  43. +12 −0 lib/selectable.rb
  44. +6 −2 spec/controllers/transcriptions_controller_spec.rb
  45. +19 −0 spec/factories/video_factory.rb
  46. +6 −0 spec/factories/video_segment_factory.rb
  47. +8 −1 spec/models/candidate_spec.rb
  48. +9 −0 spec/models/human_validation_spec.rb
  49. +5 −0 spec/models/transcription_segment_spec.rb
  50. +19 −1 spec/models/video_segment_spec.rb
  51. +23 −2 spec/models/video_spec.rb
  52. +27 −12 spec/spec_helper.rb
  53. +51 −0 vendor/assets/javascripts/nested_form.js
  54. +5 −0 vendor/assets/javascripts/swfobject.js
View
10 Gemfile
@@ -8,7 +8,8 @@ gem 'rails', '3.1.3'
gem 'mysql2'
gem 'turkee', :git => 'git://github.com/aantix/turkee.git', :branch => 'turkee_rails31'
-gem 'youtube_search', :git => 'git@github.com:aantix/youtube_search.git'
+gem 'youtube_search'
+gem 'nested_form', :path => "/Users/jjones/Projects/nested_form"
# Gems used only for assets and not required
# in production environments by default.
@@ -34,6 +35,8 @@ gem 'jquery-rails'
group :development do
gem 'heroku'
+ gem "rspec"
+ gem "rspec-rails"
end
group :production do
@@ -53,9 +56,8 @@ group :test do
gem 'rb-fsevent', ">= 0.4.3.1"
#end
gem "rspec"
+ gem "rspec-rails"
gem "guard-rspec"
+ gem "database_cleaner"
end
-group :test,:development do
- gem "rspec-rails"
-end
View
@@ -1,31 +1,28 @@
GIT
remote: git://github.com/aantix/turkee.git
- revision: ac532e6b2ab0abc51bf689c8d268e04cf2492e5d
+ revision: 2a2022784832da40dc309a48dd722a461b142646
branch: turkee_rails31
specs:
turkee (1.1.1)
- lockfile (>= 1.4.3)
- rails (>= 3.0.7)
+ lockfile
+ rails (>= 3.1.1)
rturk (>= 2.3.0)
- turkee
-
-GIT
- remote: git@github.com:aantix/youtube_search.git
- revision: 05e2c5bcf77f39e3840852ad379fea2df4df5f9e
- specs:
- youtube_search (0.1.3)
GIT
remote: http://github.com/seyhunak/twitter-bootstrap-rails.git
- revision: 0cdce29680de8f904b2d798410d9397095b89664
+ revision: b747bae72b55122dd326067a5f7b624c68163f15
specs:
- twitter-bootstrap-rails (1.4.2)
+ twitter-bootstrap-rails (1.4.3)
actionpack
- jquery-rails (~> 1.0)
- less
+ jquery-rails (>= 1.0)
less-rails (~> 2.1.0)
railties
+PATH
+ remote: /Users/jjones/Projects/nested_form
+ specs:
+ nested_form (0.1.1)
+
GEM
remote: http://rubygems.org/
specs:
@@ -67,24 +64,27 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.1.3)
+ coffee-script-source (1.2.0)
commonjs (0.2.0)
therubyracer (~> 0.9.9)
+ database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
- execjs (1.2.12)
+ execjs (1.2.13)
multi_json (~> 1.0)
factory_girl (2.3.2)
activesupport
+ ffi (1.0.11)
growl (1.0.3)
- guard (0.8.8)
+ guard (0.9.4)
+ ffi (>= 0.5.0)
thor (~> 0.14.6)
- guard-rspec (0.5.9)
+ guard-rspec (0.5.11)
guard (>= 0.8.4)
guard-spork (0.4.1)
guard (>= 0.8.4)
spork (>= 0.8.4)
- heroku (2.16.3)
+ heroku (2.17.0)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
rubyzip
@@ -94,14 +94,14 @@ GEM
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
- json (1.6.3)
+ json (1.6.4)
launchy (2.0.5)
addressable (~> 2.2.6)
less (2.0.8)
commonjs (~> 0.2.0)
therubyracer (~> 0.9.9)
- less-rails (2.1.1)
- actionpack (~> 3.1.1)
+ less-rails (2.1.2)
+ actionpack (>= 3.1)
less (~> 2.0.7)
libv8 (3.3.10.4)
lockfile (2.1.0)
@@ -116,7 +116,7 @@ GEM
pg (0.12.0)
rake-compiler (~> 0.7)
polyglot (0.3.3)
- rack (1.3.5)
+ rack (1.3.6)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
@@ -187,22 +187,25 @@ GEM
turn (0.8.3)
ansi
tzinfo (0.3.31)
- uglifier (1.2.0)
+ uglifier (1.2.1)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ youtube_search (0.1.6)
PLATFORMS
ruby
DEPENDENCIES
coffee-rails
+ database_cleaner
factory_girl (>= 1.3.2)
growl (>= 1.0.3)
guard-rspec
guard-spork
heroku
jquery-rails
mysql2
+ nested_form!
pg
rails (= 3.1.3)
rb-fsevent (>= 0.4.3.1)
@@ -214,4 +217,4 @@ DEPENDENCIES
turn
twitter-bootstrap-rails!
uglifier
- youtube_search!
+ youtube_search
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,19 @@
+$ ->
+ $("body > .topbar").scrollSpy()
+$ ->
+ $(".tabs").tabs()
+$ ->
+ $("a[rel=twipsy]").twipsy live: true
+$ ->
+ $("a[rel=popover]").popover offset: 10
+$ ->
+ $(".topbar-wrapper").dropdown()
+$ ->
+ $(".alert-message").alert()
+$ ->
+ domModal = $(".modal").modal(
+ backdrop: true
+ closeOnEscape: true
+ )
+ $(".open-modal").click ->
+ domModal.toggle()
@@ -0,0 +1,5 @@
+@import "twitter/bootstrap";
+
+// Baseline grid
+@basefont: 13px;
+@baseline: 18px;
@@ -1,3 +1,13 @@
// Place all the styles related to the Transcriptions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
+
+.transcription_segments_transcription{
+ width: 500px;
+ height: 75px;
+}
+
+.candidate{
+ width: 100px;
+ float: left;
+}
@@ -2,7 +2,7 @@ class TranscriptionsController < ApplicationController
# GET /transcriptions
# GET /transcriptions.json
def index
- @transcriptions = Transcription.all
+ @transcriptions = Transcription.all
respond_to do |format|
format.html # index.html.erb
@@ -21,15 +21,14 @@ def show
end
end
- # GET /transcriptions/new
- # GET /transcriptions/new.json
def new
- @transcription = Transcription.new
+ @transcription = Transcription.new
+ @categories = Category.select_items
+ @candidates = Candidate.all_sorted
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @transcription }
- end
+ @transcription.video_segment = VideoSegment.find(params[:video_segment_id]) rescue nil
+
+ raise "Must provide a video segment id" if @transcription.video_segment_id.nil?
end
# GET /transcriptions/1/edit
View
@@ -1,3 +1,11 @@
+require 'selectable'
+
class Candidate < ActiveRecord::Base
+ include Selectable
belongs_to :party
+
+ scope :valid, :conditions => {:searchable => true}
+
+ scope :republicans, :conditions => {:party_id => [Party::REPUBLICANS,Party::NA]}
+ scope :democrats, :conditions => {:party_id => [Party::REPUBLICANS,Party::NA]}
end
View
@@ -1,2 +1,5 @@
+require 'selectable'
+
class Category < ActiveRecord::Base
+ include Selectable
end
@@ -0,0 +1,12 @@
+class HumanValidation < ActiveRecord::Base
+
+ def self.generate
+ gold_num1 = rand(100)
+ gold_num2 = rand(100)
+ gold_sum = gold_num1 + gold_num2
+
+ HumanValidation.create(:gold_num1 => rand(100),
+ :gold_num2 => rand(100),
+ :gold_sum => gold_sum)
+ end
+end
View
@@ -1,2 +1,6 @@
class Party < ActiveRecord::Base
+ DEMOCRATS = 1
+ REPUBLICANS = 2
+ NA = 3
+
end
@@ -1,2 +1,12 @@
class Transcription < ActiveRecord::Base
+ belongs_to :video_segment
+
+ has_many :transcription_segments
+ accepts_nested_attributes_for :transcription_segments
+
+
+ def candidate
+ video_segment.video.candidate
+ end
+
end
@@ -0,0 +1,4 @@
+class TranscriptionSegment < ActiveRecord::Base
+ belongs_to :transcription
+ belongs_to :candidate
+end
View
@@ -1,23 +1,37 @@
-require 'candidate'
-
class Video < ActiveRecord::Base
+ has_many :video_segments
+ belongs_to :candidate
+
+ def self.youtube_video_id(url)
+ query_string = url.split( '?', 2)[1]
+ if query_string
+ params = CGI.parse(query_string)
+ return params["v"][0] if params.has_key?("v")
+ end
+ end
def self.cache_latest
- candidates = Candidate.scoped.all
+ candidates = Candidate.valid
candidates.each do |candidate|
- search_all(candidate.name).tap{|videos| cache_search(videos)}
+ search_all(candidate.name).tap{|videos| cache_search(videos, candidate)}
end
end
private
- def self.cache_search(videos)
+ def self.cache_search(videos, candidate)
videos.each do |video|
- Video.create(:title => video.title,
- :url => video.video_id,
- :description => video.content,
- :published_at => video.published,
- :duration => video.duration) rescue next
+ next unless video["embeddable"]
+
+ # Creation will fail if video_id isn't unique
+ v = Video.create(:title => video["title"],
+ :url => video["video_id"],
+ :description => video["content"],
+ :published_at => video["published"],
+ :duration => video["duration"],
+ :candidate_id => candidate.id) rescue next
+
+ VideoSegment.partition(v)
end
end
@@ -1,2 +1,31 @@
class VideoSegment < ActiveRecord::Base
+ belongs_to :video
+ belongs_to :candidate
+
+ SEGMENT_LENGTH = 60 # seconds
+
+ def self.partition(video)
+ offset = 0
+ segments = video.duration / SEGMENT_LENGTH
+ remainder = video.duration % SEGMENT_LENGTH
+
+ (1..segments).each do
+ create_segment(video, offset, SEGMENT_LENGTH - 1)
+ offset+=SEGMENT_LENGTH
+ end
+
+ create_segment(video, offset, remainder) unless remainder == 0
+ end
+
+ def start_of
+ offset
+ end
+
+ def end_of
+ (offset + duration)
+ end
+
+ def self.create_segment(video, offset, duration)
+ video.video_segments.create(:offset => offset, :duration => duration)
+ end
end
@@ -3,7 +3,7 @@
<head>
<title>Politics</title>
<%= stylesheet_link_tag "application" %>
- <%= javascript_include_tag "application" %>
+ <%= javascript_include_tag "application", 'swfobject', "nested_form" %>
<%= csrf_meta_tags %>
</head>
Oops, something went wrong.

0 comments on commit bda0b1c

Please sign in to comment.