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.
|
|
|
namespace :video do
|
|
|
|
desc "get video play data"
|
|
|
|
task :data => :environment do
|
|
|
|
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
|