|
|
|
@ -17,7 +17,8 @@ class CompetitionTeamsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
@team_user_ids = @team.team_members.pluck(:user_id)
|
|
|
|
|
|
|
|
|
|
shixuns = Shixun.where(user_id: @team_user_ids, status: 2).where('shixuns.created_at > ?', Time.parse('2018-06-01'))
|
|
|
|
|
shixuns = Shixun.where(user_id: @team_user_ids, status: 2)
|
|
|
|
|
.where('shixuns.created_at > ? && shixuns.created_at <= ?', Time.parse('2018-06-01'), @competition.end_time)
|
|
|
|
|
shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2')
|
|
|
|
|
shixuns = shixuns.select('shixuns.id, shixuns.identifier, shixuns.user_id, shixuns.myshixuns_count, shixuns.name, shixuns.fork_from, sum(forked_shixuns.myshixuns_count) forked_myshixun_count')
|
|
|
|
|
@shixuns = shixuns.group('shixuns.id').order('shixuns.myshixuns_count desc').includes(:creator)
|
|
|
|
@ -30,18 +31,30 @@ class CompetitionTeamsController < ApplicationController
|
|
|
|
|
forked_myshixun_count_map = get_valid_myshixun_count(forked_shixun_map.keys)
|
|
|
|
|
forked_myshixun_count_map.each { |k, v| @myshixun_count_map[forked_shixun_map[k]] += v }
|
|
|
|
|
|
|
|
|
|
# todo:使用新版course_members
|
|
|
|
|
@course_count_map = get_valid_course_count(shixun_ids)
|
|
|
|
|
forked_map = get_valid_course_count(forked_shixun_map.keys)
|
|
|
|
|
@forked_course_count_map = {}
|
|
|
|
|
forked_map.each do |forked_id, course_count|
|
|
|
|
|
@forked_course_count_map[forked_shixun_map[forked_id]] ||= 0
|
|
|
|
|
@forked_course_count_map[forked_shixun_map[forked_id]] += course_count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 课堂
|
|
|
|
|
course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01'))
|
|
|
|
|
.where('courses.created_at <= ?', @competition.end_time)
|
|
|
|
|
.joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)')
|
|
|
|
|
.where(course_members: { user_id: @team_user_ids }).pluck(:id)
|
|
|
|
|
courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()')
|
|
|
|
|
@courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count')
|
|
|
|
|
.group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0')
|
|
|
|
|
|
|
|
|
|
course_ids = @courses.map(&:id)
|
|
|
|
|
@course_myshixun_map = Myshixun.joins(student_works: :homework_common)
|
|
|
|
|
.where(homework_commons: { course_id: @courses.map(&:id) })
|
|
|
|
|
.where(homework_commons: { course_id: course_ids })
|
|
|
|
|
.where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)')
|
|
|
|
|
.group('homework_commons.course_id').count
|
|
|
|
|
@course_shixun_count_map = get_valid_shixun_count(course_ids)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def search_teacher
|
|
|
|
@ -345,6 +358,28 @@ class CompetitionTeamsController < ApplicationController
|
|
|
|
|
.group('shixun_id').count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_valid_course_count(ids)
|
|
|
|
|
percentage_sql = StudentWork.where('homework_common_id = homework_commons.id')
|
|
|
|
|
.select('count(compelete_status !=0 ) as finish, count(*) as total')
|
|
|
|
|
.having('finish > (total / 2)').to_sql
|
|
|
|
|
|
|
|
|
|
Course.joins(shixun_homework_commons: :homework_commons_shixuns)
|
|
|
|
|
.where('shixun_id in (?)', ids)
|
|
|
|
|
.where("exists (#{percentage_sql})")
|
|
|
|
|
.group('shixun_id').count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_valid_shixun_count(ids)
|
|
|
|
|
percentage_sql = StudentWork.where('homework_common_id = homework_commons.id')
|
|
|
|
|
.select('count(compelete_status !=0 ) as finish, count(*) as total')
|
|
|
|
|
.having('finish > (total / 2)').to_sql
|
|
|
|
|
Shixun.joins(homework_commons_shixuns: :homework_common)
|
|
|
|
|
.where(homework_commons: { homework_type: 3 })
|
|
|
|
|
.where('course_id in (?)', ids)
|
|
|
|
|
.where("exists (#{percentage_sql})")
|
|
|
|
|
.group('course_id').count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def record_agent_user_action
|
|
|
|
|
# 记录是否是引流用户的行为
|
|
|
|
|
ip = request.remote_ip
|
|
|
|
|