You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/lib/tasks/get_video_data.rake

31 lines
942 B

namespace :video do
desc "get video play data"
task :data => :environment do
start_times = ['2019-08-19 00:00:00', '2019-11-10 00:00:00']
end_times = ['2019-11-06 23:59:59', '2019-02-06 23:59:59']
Video.all.each do |video|
vv = 0
play_duration = 0
start_times.each_with_index do |time, index|
start_time = time.to_time.getutc
end_time = end_times[index].to_time.getutc
data = AliyunVod::Service.video_data(video.uuid, start_time, end_time)
puts data
if data[:VideoPlayStatisDetails].present?
sum_duration = data[:VideoPlayStatisDetails][:VideoPlayStatisDetail].map(&:PlayDuration).sum
sum_vv = data[:VideoPlayStatisDetails][:VideoPlayStatisDetail].map(&:vv).sum
vv += sum_vv
play_duration += sum_duration
end
end
video.update!(vv: vv, play_duration: play_duration)
puts video.id
end
end
end