diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 08ef1acb7..887f76220 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -1,14 +1,31 @@ namespace :video do desc "get video play data" task :data => :environment do - start_time = [Time.utc(2019,8,19,0,0,0), Time.utc(2019,11,10,0,0,0)] - end_time = [Time.utc(2019,11,09,23,59,59), Time.utc(2020,2,6,23,59,59)] + start_times = ['2019-08-19T00:00:00Z', '2019-11-10T00:00:00Z'] + end_times = ['2019-11-09T23:59:59Z', '2020-02-06T00:00:00Z'] Video.all.each do |video| vv = 0 play_duration = 0 + start_times.each_with_index do |time, index| + start_time = time + end_time = end_times[index] + 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 \ No newline at end of file