Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added functionality to track videos viewed in full.

  • Loading branch information...
commit 683583d1784d3ef2476defc97e3edac401babb9f 1 parent ceaff09
@cjstewart88 authored
View
1  app/assets/javascripts/main.js
@@ -408,6 +408,7 @@ function previousSong () {
function onPlayerStateChange (newState) {
// if track ended
if (newState.data == 0) {
+ $.get('/video_viewed/' + videos[currenttrack].VideoID);
nextSong();
}
}
View
9 app/controllers/api_controller.rb
@@ -9,6 +9,15 @@ def search
render :json => ""
end
+ def video_viewed
+ VideoView.create({
+ :video_id => params[:video_id],
+ :who => request.remote_ip
+ })
+
+ render :json => ""
+ end
+
def user_playlist
response = []
user = User.where(:username => params[:username]).first
View
3  app/controllers/stats_controller.rb
@@ -14,6 +14,7 @@ def overall_stats
@overall_stats = []
@overall_stats << ["searches made" , Searches.count]
+ @overall_stats << ["videos watched in full" , VideoView.count]
@overall_stats << ["playlists created" , Playlist.count]
@overall_stats << ["videos added to playlists" , Video.count]
@overall_stats << ["users registered" , User.count]
@@ -23,6 +24,7 @@ def past_7_days_stats
@past_7_days_stats = []
@past_7_days_stats << ["searches made" , Searches.where("created_at >= ?", Date.today-7).count]
+ @past_7_days_stats << ["videos watched in full" , VideoView.where("created_at >= ?", Date.today-7).count]
@past_7_days_stats << ["playlists created" , Playlist.where("created_at >= ?", Date.today-7).count]
@past_7_days_stats << ["videos added to playlists" , Video.where("created_at >= ?", Date.today-7).count]
@past_7_days_stats << ["users registered" , User.where("created_at >= ?", Date.today-7).count]
@@ -32,6 +34,7 @@ def today_stats
@today_stats = []
@today_stats << ["searches made" , Searches.where("created_at >= ?", Date.today).count]
+ @today_stats << ["videos watched in full" , VideoView.where("created_at >= ?", Date.today).count]
@today_stats << ["playlists created" , Playlist.where("created_at >= ?", Date.today).count]
@today_stats << ["videos added to playlists" , Video.where("created_at >= ?", Date.today).count]
@today_stats << ["users registered" , User.where("created_at >= ?", Date.today).count]
View
2  app/models/video_view.rb
@@ -0,0 +1,2 @@
+class VideoView < ActiveRecord::Base
+end
View
1  config/routes.rb
@@ -4,6 +4,7 @@
root :to => "application#index"
get "/insert_search/:search_type/:search" => "api#search"
+ get "/video_viewed/:video_id" => "api#video_viewed"
get "/:username/playlist/:playlist_name.json" => "api#user_playlist"
get "/stats" => "stats#index"
View
5 db/migrate/20120404034836_drop_favorites_table.rb
@@ -1,5 +0,0 @@
-class DropFavoritesTable < ActiveRecord::Migration
- def up
- drop_table :favorites
- end
-end
View
10 db/migrate/20120622013455_create_video_views.rb
@@ -0,0 +1,10 @@
+class CreateVideoViews < ActiveRecord::Migration
+ def change
+ create_table :video_views do |t|
+ t.string :video_id
+ t.string :who
+
+ t.timestamps
+ end
+ end
+end
View
17 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120404034836) do
+ActiveRecord::Schema.define(:version => 20120622013455) do
create_table "banned_videos", :force => true do |t|
t.integer "user_id"
@@ -20,13 +20,6 @@
t.datetime "updated_at"
end
- create_table "playlist", :force => true do |t|
- t.integer "user_id"
- t.string "name"
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
create_table "playlists", :force => true do |t|
t.string "playlist_name"
t.integer "user_id"
@@ -37,9 +30,9 @@
create_table "searches", :force => true do |t|
t.string "what"
t.string "who"
+ t.string "search_type"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "search_type"
end
create_table "users", :force => true do |t|
@@ -56,16 +49,14 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "username"
- t.boolean "premium"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
- create_table "video", :force => true do |t|
- t.integer "playlist_id"
+ create_table "video_views", :force => true do |t|
t.string "video_id"
- t.string "video_title"
+ t.string "who"
t.datetime "created_at"
t.datetime "updated_at"
end
View
9 test/fixtures/video_views.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ video_id: MyString
+ who: MyString
+
+two:
+ video_id: MyString
+ who: MyString
View
7 test/unit/video_view_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class VideoViewTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.