|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
class Subject::UserUsedInfoService < ApplicationService
|
|
|
|
|
class Subjects::UserUsedInfoService < ApplicationService
|
|
|
|
|
attr_reader :subject, :shixun_ids
|
|
|
|
|
|
|
|
|
|
def initialize(subject)
|
|
|
|
@ -8,19 +8,17 @@ class Subject::UserUsedInfoService < ApplicationService
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def call
|
|
|
|
|
users = User.joins(:myshixuns).where(myshixuns: {shixun_id: shixun_ids}).group(:user_id)
|
|
|
|
|
|
|
|
|
|
users_info = []
|
|
|
|
|
users.includes(:myshixuns, :games).each do |user|
|
|
|
|
|
games = user.games
|
|
|
|
|
users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2})
|
|
|
|
|
users.each do |user|
|
|
|
|
|
myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)}
|
|
|
|
|
name = "#{user.lastname}#{user.firstname}"
|
|
|
|
|
passed_myshixun_count = user.myshixuns.select{|m| m.status == 1}.size
|
|
|
|
|
passed_games_count = games.select{|g| g.status == 2}.size
|
|
|
|
|
passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size
|
|
|
|
|
passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size
|
|
|
|
|
code_line_count = "未完成"
|
|
|
|
|
evaluate_count = games.sum(evaluate_count)
|
|
|
|
|
cost_time = games.sum(:cost_time)
|
|
|
|
|
user_login = user.login
|
|
|
|
|
users_info << {login: user_login, name: name, passed_myshixun_count: passed_myshixun_count,
|
|
|
|
|
evaluate_count = myshixuns.map{|m| m.output_times }.sum
|
|
|
|
|
cost_time = myshixuns.map{|m|m.total_cost_time }.sum
|
|
|
|
|
users_info << {login: user.login, name: name, passed_myshixun_count: passed_myshixun_count,
|
|
|
|
|
passed_games_count: passed_games_count, code_line_count: code_line_count,
|
|
|
|
|
evaluate_count: evaluate_count, cost_time: cost_time}
|
|
|
|
|
end
|
|
|
|
|