count_statistic=UserExtensions.where(school_id:@school.id).select('SUM(IF(identity=0, 1, 0)) AS teachers_count, SUM(IF(identity=1, 1, 0)) AS students_count').first
@teachers=User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count,
(SELECTcount(c.id)FROMcoursesc,course_membersmWHEREc.id!=1309andm.course_id=c.idANDm.rolein(1,2,3)andc.school_id=#{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count
FROM`users`,user_extensionsuewhereusers.id=ue.user_idandue.identity=0andue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10")
course_ids=Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}")
myshixun_ids=StudentWork.select("myshixun_id").where("homework_common_id in (#{homeworks.map(&:id).join(',').strip==""?-1:homeworks.map(&:id).join(',')}) and myshixun_id is not null")
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day-1.day).beginning_of_day}' AND outputs.created_at < '#{(end_day-1.day).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{end_day.beginning_of_day+(i*2).hour}' AND outputs.created_at < '#{end_day.beginning_of_day+((i+1)*2).hour}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-7.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-7.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(i+1).days).end_of_day}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-30.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-30.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+(3*i).days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(3*(i+1)).days).end_of_day}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(i+1).days).end_of_day}'").first.try(:count).to_i
@total_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
@trend_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b