diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index e559253b..cfa3a281 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -25,11 +25,12 @@ class CompetitionTeamsController < ApplicationController shixun_ids = @shixuns.map(&:id) @myshixun_count_map = get_valid_myshixun_count(shixun_ids) + @original_myshixun_count_map = @myshixun_count_map.clone # forked shixun valid myshixun count forked_shixun_map = Shixun.where(status: 2, fork_from: shixun_ids).select('id, fork_from') forked_shixun_map = forked_shixun_map.each_with_object({}) { |sx, obj| obj[sx.id] = sx.fork_from } - 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 } + @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 } @course_count_map = get_valid_course_count(shixun_ids) forked_map = get_valid_course_count(forked_shixun_map.keys) @@ -38,6 +39,7 @@ class CompetitionTeamsController < ApplicationController @forked_course_count_map[forked_shixun_map[forked_id]] ||= 0 @forked_course_count_map[forked_shixun_map[forked_id]] += course_count end + @forked_shixun_map = forked_shixun_map # 课堂 diff --git a/app/views/competition_teams/show.html.erb b/app/views/competition_teams/show.html.erb index f8e1f1c5..f8c974b7 100644 --- a/app/views/competition_teams/show.html.erb +++ b/app/views/competition_teams/show.html.erb @@ -28,14 +28,20 @@ total_forked_myshixun_count += shixun['forked_myshixun_count'].to_i valid_course_count = @course_count_map.fetch(shixun.id, 0) - valid_student_count = @myshixun_count_map.fetch(shixun.id, 0) + valid_student_count = @original_myshixun_count_map.fetch(shixun.id, 0) score = if shixun.fork_from.blank? 500 + 50 * valid_course_count + 10 * valid_student_count else 100 + 10 * valid_course_count + 5 * valid_student_count end - score += @forked_course_count_map.fetch(shixun.id, 0) + + @forked_shixun_map.each do |shixun_id, fork_from_id| + next if fork_from_id != shixun.id + + score += 100 + 10 * @forked_shixun_map.fetch(shixun_id, 0) + 5 * @forked_myshixun_count_map.fetch(shixun_id, 0) + end + total_shixun_score += score %>