优化《作业评分》

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-12-24 18:31:45 +08:00
parent 8e87e83ad8
commit 0e7f7a4254
6 changed files with 80 additions and 63 deletions

View File

@ -213,12 +213,12 @@ class CoursesController < ApplicationController
q = "#{params[:name].strip}" q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:incourse] if params[:incourse]
@results = searchStudent_by_name(@course, q) @results = searchmember_by_name(@@member_scores, q)
elsif params[:ingroup] elsif params[:ingroup]
@group = CourseGroup.find(params[:search_group_id]) @group = CourseGroup.find(params[:search_group_id])
@results = searchgroupstudent_by_name(@group, @course, q) @results = @results =searchgroupmember_by_name(@@member_scores, @group, q)
end end
@member_scores = @@member_scores
@result_count = @results.count @result_count = @results.count
@results = paginateHelper @results @results = paginateHelper @results
@ -234,8 +234,7 @@ class CoursesController < ApplicationController
end end
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@members = searchStudent(@course)
@membercount = @members.count
@course_groups = @course.course_groups @course_groups = @course.course_groups
end end
@ -244,8 +243,7 @@ class CoursesController < ApplicationController
@subPage_title = l :label_student_list @subPage_title = l :label_student_list
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@members = searchStudent(@course)
@membercount = @members.count
@course_groups = @course.course_groups @course_groups = @course.course_groups
end end
@ -258,8 +256,7 @@ class CoursesController < ApplicationController
end end
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@members = searchStudent(@course)
@membercount = @members.count
@course_groups = @course.course_groups @course_groups = @course.course_groups
end end
@ -312,28 +309,18 @@ class CoursesController < ApplicationController
@is_remote = true @is_remote = true
if params[:group_id] && params[:group_id] != "0" if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id]) @group = CourseGroup.find(params[:group_id])
@results = searchStudent_by_group(@group, @course) @results = @@member_scores.find_all {|mem| mem.course_group_id == group.id}
else else
@results = searchStudent(@course) @results = @@member_scores
end end
@@result = @results @@result = @results
@member_scores = @@member_scores
@members = searchStudent(@course) @members = searchStudent(@course)
@membercount = @members.count @membercount = @members.count
@results = paginateHelper @results @results = paginateHelper @results
end end
def search_group_members group
@subPage_title = l :label_student_list
@render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
@member_scores = @@member_scores
@members = searchStudent(@course)
@membercount = @members.count
@results = searchStudent_by_group(group, @course)
@@result = @results
@results = paginateHelper @results
end
def member def member
## 有角色参数的才是课程,没有的就是项目 ## 有角色参数的才是课程,没有的就是项目
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@ -350,8 +337,9 @@ class CoursesController < ApplicationController
when '2' when '2'
@subPage_title = l :label_student_list @subPage_title = l :label_student_list
@@member_scores = student_homework_score @@member_scores = student_homework_score
@member_scores = @@member_scores @members = @@member_scores
@members = searchStudent_sort(@course, 'desc', @@member_scores) # @member_scores = @@member_scores
# @members = searchStudent_sort(@course, 'desc', @@member_scores)
@membercount = @members.count @membercount = @members.count
else else
@ -375,7 +363,7 @@ class CoursesController < ApplicationController
@show_serch = params[:role] == '2' @show_serch = params[:role] == '2'
@subPage_title = l :label_student_list @subPage_title = l :label_student_list
@render_file = 'member_list' @render_file = 'member_list'
@member_scores = @@member_scores
unless @@result.nil? unless @@result.nil?
@results = @@result.reverse @results = @@result.reverse
@@result = @results @@result = @results
@ -384,7 +372,7 @@ class CoursesController < ApplicationController
end end
# 显示每个学生的作业评分详情 # 显示每个学生的作业评分详情
def show_member_score def show_member_score
@member_scores = @@member_scores
@member_score = Member.find(params[:member_id]) if params[:member_id] @member_score = Member.find(params[:member_id]) if params[:member_id]
respond_to do |format| respond_to do |format|
format.html {render :layout => 'course_base'} format.html {render :layout => 'course_base'}
@ -895,23 +883,34 @@ class CoursesController < ApplicationController
def student_homework_score def student_homework_score
teachers = find_course_teachers(@course) teachers = find_course_teachers(@course)
score_count = 0 homework_scores = Member.find_by_sql("SELECT id, user_id,course_id, course_group_id,created_on,IFNULL(SUM(CASE WHEN t_score <> 0 AND t_score IS NOT NULL THEN t_score ELSE s_score END),0) as score
FROM (
homeworks = HomeworkAttach.find_by_sql("SELECT homework_attaches.id SELECT members.id as id, members.user_id AS user_id, members.course_id AS course_id, members.created_on as created_on,members.course_group_id AS course_group_id,
FROM homework_attaches, bids where (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (3040,4762,4765)) AS t_score,
homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{@course.id} (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (3040,4762,4765)) AS s_score
and homework_attaches.bid_id = bids.id)") FROM `homework_attaches` , members
homeworks = homeworks.map {|homework| homework.id}.join(",") WHERE members.course_id = #{@course.id}
homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.user_id, AVG(s1.stars) AS t_score, AND members.user_id NOT IN (#{teachers}) AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id})
AVG(s2.stars) AS s_score AND homework_attaches.user_id = members.user_id
FROM homework_attaches, seems_rateable_rates s1,seems_rateable_rates s2 WHERE ) AS table1 GROUP BY user_id ORDER BY score DESC")
homework_attaches.id in (#{homeworks}) and s1.rateable_type = 'HomeworkAttach' and s1.rateable_id = homework_attaches.id homework_scores
AND s1.rater_id IN (#{teachers}) and s2.rateable_type = 'HomeworkAttach'
and s2.rateable_id = homework_attaches.id
AND s2.rater_id not IN (#{teachers})")
end end
#获取课程的老师列表 #获取课程的老师列表
def find_course_teachers course def find_course_teachers course
searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",") searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",")
end end
#当加入,退出分班时查询分班的学生
def search_group_members group
@subPage_title = l :label_student_list
@render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
@members = searchStudent(@course)
@membercount = @members.count
@results = @@member_scores.find_all {|mem| mem.course_group_id == group.id}
@@result = @results
@results = paginateHelper @results
end
end end

View File

@ -175,22 +175,7 @@ module CoursesHelper
end end
members members
end end
def searchStudent_sort project, sort_by, member_scores
#searchPeopleByRoles(project, StudentRoles)
members = []
project.members.each do |m|
if m && m.user && m.user.allowed_to?(:as_student,project)
members << m
end
end
members.sort!{ |mem1, mem2| mem1.student_homework_score(member_scores)[1].to_f <=> mem2.student_homework_score(member_scores)[1].to_f}
if sort_by == "desc"
members.reverse!
end
members
end
def searchStudent_by_name project, name def searchStudent_by_name project, name
@ -206,6 +191,32 @@ module CoursesHelper
end end
members members
end end
def searchmember_by_name members, name
#searchPeopleByRoles(project, StudentRoles)
mems = []
members.each do |m|
username = m.user[:lastname].to_s + m.user[:firstname].to_s
if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
mems << m
end
end
mems
end
def searchgroupmember_by_name members, name, group
#searchPeopleByRoles(project, StudentRoles)
mems = []
members.each do |m|
if m.course_group_id == group.id
username = m.user[:lastname].to_s + m.user[:firstname].to_s
if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
mems << m
end
end
end
mems
end
def searchgroupstudent_by_name(group, project, name) def searchgroupstudent_by_name(group, project, name)
members = [] members = []
group.members.each do |m| group.members.each do |m|

View File

@ -115,9 +115,16 @@ class Member < ActiveRecord::Base
end end
# 查找每个学生每个作业的评分 # 查找每个学生每个作业的评分
def student_homework_score homework_scores def student_homework_score
score_count = 0 score_count = 0
homework_score = homework_scores.find_all { |e| e.user_id == self.user_id} homework_score = HomeworkAttach.find_by_sql("SELECT bids.`name`, 0 as score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
AND rateable_id = homework_attaches.id ) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
AND rateable_id = homework_attaches.id ) AS s_score
FROM homework_attaches, bids where homework_attaches.user_id = #{self.user_id}
and homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{self.course_id})
AND homework_attaches.bid_id = bids.id ")
homework_score.each do |homework| homework_score.each do |homework|
if !homework.t_score.nil? && homework.t_score != 0 if !homework.t_score.nil? && homework.t_score != 0
score = homework.t_score score = homework.t_score

View File

@ -68,7 +68,7 @@
<% end %> <% end %>
</ul> </ul>
<% if @subPage_title == l(:label_student_list) %> <% if @subPage_title == l(:label_student_list) %>
<%= link_to member.student_homework_score(@member_scores)[1].to_s, { <%= link_to format("%0.2f",member.score.to_s), {
:action => 'show_member_score', :action => 'show_member_score',
:member_id => member.id, :member_id => member.id,
:remote => true}, :remote => true},

View File

@ -27,7 +27,7 @@
<% end %> <% end %>
</ul> </ul>
<% if @subPage_title == l(:label_student_list) %> <% if @subPage_title == l(:label_student_list) %>
<%= link_to member.student_homework_score(@member_scores)[1].to_s, { <%= link_to format("%0.2f",member.score.to_s), {
:action => 'show_member_score', :action => 'show_member_score',
:member_id => member.id, :member_id => member.id,
:remote => true}, :remote => true},

View File

@ -39,7 +39,7 @@
<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(@member_scores)[0].each do |homework_score| %> <% @member_score.student_homework_score[0].each do |homework_score| %>
<% if !homework_score.t_score.nil? && homework_score.t_score != 0 %> <% if !homework_score.t_score.nil? && homework_score.t_score != 0 %>
<% score = homework_score.t_score %> <% score = homework_score.t_score %>
<% else %> <% else %>
@ -51,7 +51,7 @@
<% end %> <% end %>
<li><span class="c_grey02 w280"><%= homework_score.name %></span><span class="c_red w70"><%= format("%0.2f",score) %></span></li> <li><span class="c_grey02 w280"><%= homework_score.name %></span><span class="c_red w70"><%= format("%0.2f",score) %></span></li>
<% end %> <% end %>
<li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score(@member_scores)[1] %></span></li> <li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score[1] %></span></li>
</ul> </ul>