From cf4c6c83d363c1c6e8d865cca8c1ace481aa9f00 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 10 Jul 2015 17:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=A7=AF=E5=88=86=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=80=BB=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 4 ++-- app/models/member.rb | 4 ++++ app/views/courses/_show_member_score.html.erb | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 9e06ea83c..a0a61786c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -838,7 +838,7 @@ class CoursesController < ApplicationController sql_select = "" if groupid == 0 sql_select = "SELECT members.*,( - SELECT AVG(student_works.final_score) + SELECT SUM(student_works.final_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} @@ -850,7 +850,7 @@ class CoursesController < ApplicationController WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*,( - SELECT AVG(student_works.final_score) + SELECT SUM(student_works.final_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} diff --git a/app/models/member.rb b/app/models/member.rb index 057ea9570..292dd2034 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -143,6 +143,10 @@ class Member < ActiveRecord::Base StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").average(:final_score).try(:round, 2).to_f end + def student_work_score_sum + StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").sum(:final_score).try(:round, 2).to_f + end + protected def validate_role diff --git a/app/views/courses/_show_member_score.html.erb b/app/views/courses/_show_member_score.html.erb index b471bc17f..bdc1fa147 100644 --- a/app/views/courses/_show_member_score.html.erb +++ b/app/views/courses/_show_member_score.html.erb @@ -28,7 +28,7 @@ <% end %> -
  • 作业积分(平均分)<%= @member_score.student_work_score_avg %>
  • +
  • 作业积分(总分)<%= @member_score.student_work_score_sum %>