From dc0e45c0ed535a5a3e0bc3273265e556cbae23fe Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 18:51:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subjects/course_used_info_service.rb | 8 ++--- .../subjects/data_statistic_service.rb | 5 ++- .../subjects/shixun_used_info_service.rb | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 app/services/subjects/shixun_used_info_service.rb diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb index 188a96fd7..f60c4a6ca 100644 --- a/app/services/subjects/course_used_info_service.rb +++ b/app/services/subjects/course_used_info_service.rb @@ -1,10 +1,8 @@ class Subjects::CourseUsedInfoService < ApplicationService - attr_reader :subject, :user - def initialize(subject, user) + attr_reader :subject + def initialize(subject) @subject = subject - @user = user - @shixuns = subject.shixuns - @shixun_ids = @shixuns.pluck(:id) + @shixun_ids = subject.shixuns.pluck(:id) end def call diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb index 4ab7488c6..9dc2db09a 100644 --- a/app/services/subjects/data_statistic_service.rb +++ b/app/services/subjects/data_statistic_service.rb @@ -1,8 +1,7 @@ class Subjects::DataStatisticService < ApplicationService - attr_reader :subject, :user - def initialize(subject, user) + attr_reader :subject + def initialize(subject) @subject = subject - @user = user @shixuns = subject.shixuns @shixun_ids = @shixuns.pluck(:id) end diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb new file mode 100644 index 000000000..1dda483d4 --- /dev/null +++ b/app/services/subjects/shixun_used_info_service.rb @@ -0,0 +1,31 @@ +class Subjects::ShixunUsedInfoService < ApplicationService + attr_reader :subject, :stages + def initialize(subject) + @subject = subject + @stages = subject.stages.includes(shixuns: [myshixuns: :games, homework_commons_shixuns: [homework_common: :course]]) + end + + def call + shixun_infos = [] + stages.each do |stage| + position = stage.position + stage.shixuns.each_with_index do |shixun, index| + stage = "#{position}-#{index+1}" + name = shixun.name + challenge_count = shixun.challenges_count + course_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course_id}.uniq.size + school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size + used_count = shixun.myshixuns_count + passed_count = shixun.myshixuns.select{|m| m.status == 1}.size + evaluate_count = shixun.myshixuns.map{|m| m.games.sum(:evaluate_count).to_i}.sum + passed_ave_time = (passed_count > 0) ? + (shixun.myshixuns.map{|m| m.status == 1 && m.games.sum(:cost_time).to_i}.sum / passed_count) : 0 + shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, + school_count: school_count, used_count: used_count, passed_count: passed_count, + evaluate_count: evaluate_count, passed_ave_time: passed_ave_time} + end + shixun_infos + end + end + +end