课堂视频限定统计学生

courseware
anke1460 5 years ago
parent 21caa0b9c2
commit 5bcc9fbb41

@ -26,14 +26,13 @@ class CourseVideosController < ApplicationController
@watch_course_videos = course_video.watch_course_videos.joins("
JOIN watch_video_histories ON watch_video_histories.watch_course_video_id = watch_course_videos.id
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4
").group("watch_video_histories.watch_course_video_id").where("watch_course_videos.end_at IS NOT NULL").select("watch_course_videos.id")
@count = @watch_course_videos.count.count
if params[:group_id].present?
@watch_course_videos = @watch_course_videos.joins("
JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id}
").where("course_members.course_group_id = ?", params[:group_id])
@watch_course_videos = @watch_course_videos.where("course_members.course_group_id = ?", params[:group_id])
end
@watch_course_videos = @watch_course_videos.select("count(watch_video_histories.id) AS freq, watch_course_videos.*")

@ -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,

@ -2,7 +2,7 @@ json.data do
json.array! @watch_course_videos do |d|
json.user_name d.user&.real_name
json.is_finished d.is_finished ? true : false
json.total_duration d.total_duration.round(2)
json.total_duration d.total_duration.round(0)
json.feq d['freq']
json.start_at d.start_at.to_s
json.end_at d.end_at.to_s

@ -3,7 +3,7 @@ json.data do
json.title d.title
json.user_name @current_user&.real_name
json.is_finished d.is_finished ? true : false
json.total_duration d.total_duration.round(2)
json.total_duration d.total_duration.round(0)
json.freq d['freq']
json.start_at d.start_at.to_s
json.end_at d.end_at.to_s

@ -4,7 +4,7 @@ json.videos do
json.title v.title
json.user_name v.user&.real_name
json.people_num v['people_num']
json.total_time v['total_time']
json.total_time v['total_time'].round(0)
end
end
json.count @count
Loading…
Cancel
Save