diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index e89646e3..07234e17 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1416,9 +1416,9 @@ class ExerciseController < ApplicationController exercise_cha_score = 0 answer_status = 0 challeng_path = challenge_path exercise_cha.challenge.path - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = exercise_cha.question_score - answer_status = 1 + if game.final_score >= 0 + exercise_cha_score = game.real_score exercise_cha.question_score + answer_status = game.status == 2 ? 1 : 0 end if exercise_cha.exercise_shixun_answers.where(:user_id => user.id).empty? if GameCode.where(:game_id => game.try(:id), :path => challeng_path).first.present? diff --git a/app/models/game.rb b/app/models/game.rb index 47674541..152ede0c 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -20,6 +20,11 @@ class Game < ActiveRecord::Base :answer_open, :test_sets_view, :cost_time, :star, :modify_time]) } + # 根据得分比例来算实际得分(试卷、实训作业) + def real_score score + self.final_score == challenge.score ? self.final_score : (self.final_score.to_f / challenge.score) * score + end + def had_done myshixun = self.myshixun challenge_count = myshixun.games.count diff --git a/lib/tasks/exercise_publish.rake b/lib/tasks/exercise_publish.rake index 98c50d97..3c5ccf83 100644 --- a/lib/tasks/exercise_publish.rake +++ b/lib/tasks/exercise_publish.rake @@ -31,7 +31,8 @@ namespace :exercise_publish do score2 = 0 score3 = 0 score4 = 0 - exercise_qustions = exercise.exercise_questions + exercise_user = exercise.exercise_users.where(user_id: user.id).first + exercise_qustions = exercise.user_question_list(exercise_user.try(:id)) exercise_qustions.each do |question| if question.question_type != 5 answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") @@ -69,9 +70,9 @@ namespace :exercise_publish do answer_status = 0 cha_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split(";") : [] challeng_path = cha_path.reject(&:blank?)[0].try(:strip) - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = exercise_cha.question_score - answer_status = 1 + if game.final_score >= 0 + exercise_cha_score = game.real_score exercise_cha.question_score + answer_status = game.status == 2 ? 1 : 0 end if exercise_cha.exercise_shixun_answers.where(:user_id => user.id).empty? if GameCode.where(:game_id => game.try(:id), :path => challeng_path).first.present?