Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
19d5853b75
@ -1,14 +1,45 @@
|
||||
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-19 00:00:00', '2019-11-10 00:00:00']
|
||||
end_times = ['2019-11-09 23:59:59', '2020-02-06 00:00:00']
|
||||
|
||||
Video.all.each do |video|
|
||||
vv = 0
|
||||
play_duration = 0
|
||||
|
||||
start_times.each_with_index do |time, index|
|
||||
start_time = time.to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
end_time = end_times[index].to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
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
|
||||
|
||||
# 执行示例 bundle exec rake video:sample args=2933,'2019-08-19 00:00:00','2019-11-09 23:59:59'
|
||||
task :sample => :environment do
|
||||
if ENV['args']
|
||||
video_id = ENV['args'].split(",")[0]
|
||||
start_time = ENV['args'].split(",")[1].to_s.to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ') # 表示参与人数
|
||||
end_time = ENV['args'].split(",")[2].to_s.to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ') # 表示通过人数
|
||||
|
||||
video=Video.find video_id
|
||||
data = AliyunVod::Service.video_data(video.uuid, start_time, end_time)
|
||||
|
||||
puts data
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue