作业积分显示平均分
This commit is contained in:
parent
5d5159f4c7
commit
f956b27953
|
@ -836,7 +836,7 @@ class CoursesController < ApplicationController
|
||||||
sql_select = ""
|
sql_select = ""
|
||||||
if groupid == 0
|
if groupid == 0
|
||||||
sql_select = "SELECT members.*,(
|
sql_select = "SELECT members.*,(
|
||||||
SELECT SUM(student_works.final_score)
|
SELECT AVG(student_works.final_score)
|
||||||
FROM student_works,homework_commons
|
FROM student_works,homework_commons
|
||||||
WHERE student_works.homework_common_id = homework_commons.id
|
WHERE student_works.homework_common_id = homework_commons.id
|
||||||
AND homework_commons.course_id = #{@course.id}
|
AND homework_commons.course_id = #{@course.id}
|
||||||
|
@ -848,7 +848,7 @@ class CoursesController < ApplicationController
|
||||||
WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}"
|
WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}"
|
||||||
else
|
else
|
||||||
sql_select = "SELECT members.*,(
|
sql_select = "SELECT members.*,(
|
||||||
SELECT SUM(student_works.final_score)
|
SELECT AVG(student_works.final_score)
|
||||||
FROM student_works,homework_commons
|
FROM student_works,homework_commons
|
||||||
WHERE student_works.homework_common_id = homework_commons.id
|
WHERE student_works.homework_common_id = homework_commons.id
|
||||||
AND homework_commons.course_id = #{@course.id}
|
AND homework_commons.course_id = #{@course.id}
|
||||||
|
|
|
@ -116,21 +116,23 @@ class Member < ActiveRecord::Base
|
||||||
|
|
||||||
# 查找每个学生每个作业的评分
|
# 查找每个学生每个作业的评分
|
||||||
def student_homework_score
|
def student_homework_score
|
||||||
score_count = 0
|
|
||||||
homework_score = StudentWork.find_by_sql("SELECT homework_commons.name,student_works.final_score as score
|
homework_score = StudentWork.find_by_sql("SELECT homework_commons.name,student_works.final_score as score
|
||||||
FROM student_works,homework_commons
|
FROM student_works,homework_commons
|
||||||
WHERE student_works.homework_common_id = homework_commons.id
|
WHERE student_works.homework_common_id = homework_commons.id
|
||||||
AND homework_commons.course_id = #{self.course_id}
|
AND homework_commons.course_id = #{self.course_id}
|
||||||
AND student_works.user_id = #{self.user_id}")
|
AND student_works.user_id = #{self.user_id}")
|
||||||
homework_score.each do |homework|
|
score_count = 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
|
||||||
mem_score = 0
|
|
||||||
if homework[:score]
|
|
||||||
mem_score = homework[:score]
|
|
||||||
end
|
|
||||||
score_count = score_count + mem_score
|
|
||||||
end
|
|
||||||
[homework_score, format("%0.2f", score_count)]
|
[homework_score, format("%0.2f", score_count)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def student_work_score
|
||||||
|
StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_work_score_avg
|
||||||
|
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
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def validate_role
|
def validate_role
|
||||||
|
|
|
@ -17,17 +17,17 @@
|
||||||
<h2><%= @member_score.user.name %> 历次作业积分</h2>
|
<h2><%= @member_score.user.name %> 历次作业积分</h2>
|
||||||
<ul class="tscore_box">
|
<ul class="tscore_box">
|
||||||
<li ><span class="c_blue02 w280">作业名称</span><span class="c_blue02 w70">得分</span></li>
|
<li ><span class="c_blue02 w280">作业名称</span><span class="c_blue02 w70">得分</span></li>
|
||||||
<% @member_score.student_homework_score[0].each do |homework_score| %>
|
<% @member_score.student_work_score.each do |homework_score| %>
|
||||||
<li>
|
<li>
|
||||||
<span class="c_grey02 w280">
|
<span class="c_grey02 w280">
|
||||||
<%= homework_score.name %>
|
<%= homework_score.name %>
|
||||||
</span>
|
</span>
|
||||||
<span class="c_red w70">
|
<span class="c_red w70">
|
||||||
<%= format("%0.2f",homework_score[:score].nil? ? 0 : homework_score[:score]) %>
|
<%= format("%0.2f",homework_score.final_score.nil? ? 0 : homework_score.final_score) %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score[1] %></span></li>
|
<li><span class="c_blue03 w280">作业积分(平均分)</span><span class="c_red w70"><%= @member_score.student_work_score_avg %></span></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue