diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 45f4da0de..54223a155 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -237,7 +237,7 @@ class CoursesController < ApplicationController def work_score sort = params[:sort] || "desc" - group_ids = params[:group_ids] + group_ids = params[:group_ids].is_a?(Array) ? params[:group_ids] : params[:group_ids].split(",") if params[:group_ids] @course_members = course_work_scores @course, sort, group_ids if @user_course_identity == Course::STUDENT user_ids = @course_members.map(&:user_id) @@ -249,7 +249,17 @@ class CoursesController < ApplicationController end def act_score - + group_ids = params[:group_ids].is_a?(Array) ? params[:group_ids] : params[:group_ids].split(",") if params[:group_ids] + all_members = course_act_scores @course, group_ids + @course_members = all_members[0 .. 9] + if @user_course_identity == Course::STUDENT + user_ids = all_members.map(&:user_id) + rank = user_ids.index(current_user.id).to_i + 1 + if rank > 10 + current_member = all_members.select{|member| member.user_id == current_user.id} + @course_members << current_member + end + end end def join_excellent_course @@ -1501,7 +1511,7 @@ class CoursesController < ApplicationController sql_select = %Q{ SELECT a.*, (message_num*0.2 + message_reply_num*0.1 + resource_num*0.5 + homework_journal_num*0.1 + graduation_num + homework_num + exercise_num + poll_num*0.7 + exercise_score * 0.7 + graduation_score * 0.7 + homework_score * 0.7 + exp*#{max_rate}) AS score from - (select cm.*, users.experience as exp, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, + (select cm.*, users.experience as exp, (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} @@ -1525,7 +1535,6 @@ class CoursesController < ApplicationController (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num FROM course_members cm join users on cm.user_id = users.id - join user_extensions ue on ue.user_id = users.id WHERE cm.role = 4 and cm.course_id = #{course.id}) a ORDER BY score desc limit #{limit}; } CourseMember.find_by_sql(sql_select) @@ -1546,12 +1555,42 @@ class CoursesController < ApplicationController (SELECT IFNULL(sum(eu.score),0) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_score FROM course_members cm join users on cm.user_id = users.id + WHERE cm.role = 4 and cm.course_id = #{course.id} + } + + sql_select += %Q{ and cm.course_group_id in (#{group_ids.join(",")}) } if group_ids.present? + sql_select += %Q{ ) a ORDER BY score #{sort}; } + course_members = CourseMember.find_by_sql(sql_select) + course_members + end + + def course_act_scores course, group_ids + sql_select = %Q{ SELECT a.*, + (message_num*2 + message_reply_num + resource_num*5 + homework_journal_num + graduation_num*10 + homework_num*10 + exercise_num*10 + poll_num*7) AS score from + (select cm.*, + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} + AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{course.id} + AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, + (SELECT count(attachments.id) FROM attachments WHERE container_id = #{course.id} and container_type = "Course" + AND attachments.author_id = cm.user_id) AS resource_num, + (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND + jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{course.id}) AS homework_journal_num, + (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND + gt.course_id = #{course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, + (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND + hc.course_id = #{course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, + (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{course.id} + AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, + (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{course.id} + AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num + FROM course_members cm join users on cm.user_id = users.id join user_extensions ue on ue.user_id = users.id - WHERE cm.role = 4 and cm.course_id = #{course.id}) + WHERE cm.role = 4 and cm.course_id = #{course.id} } sql_select += %Q{ and cm.course_group_id in (#{group_ids.join(",")}) } if group_ids.present? - sql_select += %Q{ a ORDER BY score #{sort}; } + sql_select += %Q{ ) a ORDER BY score desc; } course_members = CourseMember.find_by_sql(sql_select) course_members end diff --git a/app/views/courses/act_score.json.jbuilder b/app/views/courses/act_score.json.jbuilder new file mode 100644 index 000000000..394497635 --- /dev/null +++ b/app/views/courses/act_score.json.jbuilder @@ -0,0 +1,7 @@ +json.course_members @course_members.each do |member| + user = member.user + json.user_login user.login + json.user_name user.real_name + # json.course_group member.course_group_name + json.total_score member.score +end \ No newline at end of file