Created
April 17, 2015 05:24
-
-
Save 1Marc/627a1cf1064c3efed340 to your computer and use it in GitHub Desktop.
Video Stats
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
Methods.video_progress = function(user, events){ | |
var progress = _.groupBy(events, 'media_id'); | |
for (var key in progress){ | |
var v = progress[key] | |
var last_event = _.reduceRight(v, function(a,b){ | |
return (new Date(a.created_at) > new Date(a.created_at)) ? a : b; | |
}); | |
var percent = 0.0; | |
v.forEach(function(ev){ | |
percent += Number(ev.percent_viewed) | |
}); | |
if (percent > 1.0) percent = 1.0; | |
var o = { | |
percent: percent.toFixed(4), | |
last_watched: moment(last_event.received_at).format('YYYYMMDD'), | |
last_watched_diff: moment(last_event.received_at).fromNow() | |
} | |
progress[key] = o; | |
} | |
return progress; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment