|
|
|
@ -1494,6 +1494,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_course_videos.course_video_id) AS num
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.end_at IS NOT NULL
|
|
|
|
|
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id}
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id")
|
|
|
|
@ -1523,6 +1524,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
SELECT watch_course_videos.course_video_id, COUNT(watch_course_videos.course_video_id) AS num
|
|
|
|
|
FROM watch_course_videos
|
|
|
|
|
JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id
|
|
|
|
|
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
|
|
|
|
|
WHERE course_videos.course_id = #{@course.id} AND watch_course_videos.user_id = #{current_user.id} AND watch_course_videos.end_at IS NOT NULL
|
|
|
|
|
GROUP BY watch_course_videos.course_video_id
|
|
|
|
|
) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id")
|
|
|
|
@ -1543,9 +1545,12 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 课堂视频的统计总览
|
|
|
|
|
def watch_statics
|
|
|
|
|
@total_duration = @course.course_videos.joins(:watch_course_videos).sum(:total_duration).round(2)
|
|
|
|
|
@frequencies = @course.course_videos.joins([watch_course_videos: :watch_video_histories]).count(:id)
|
|
|
|
|
@people_num = @course.course_videos.joins(:watch_course_videos).count(:id)
|
|
|
|
|
course_videos = @course.course_videos.joins(:watch_course_videos).joins("
|
|
|
|
|
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
|
|
|
|
|
")
|
|
|
|
|
@total_duration = course_videos.sum(:total_duration).round(0)
|
|
|
|
|
@frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id").count(:id)
|
|
|
|
|
@people_num = course_videos.count(:id)
|
|
|
|
|
render json: {
|
|
|
|
|
total_duration: @total_duration,
|
|
|
|
|
freq: @frequencies,
|
|
|
|
|