From 6d85dd7ca432312c7618198902c98b7ee5f899cb Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 7 Jul 2015 17:18:29 +0800 Subject: [PATCH] =?UTF-8?q?app=E7=9A=84=E8=AF=BE=E7=A8=8B=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=95=8C=E9=9D=A2api=E4=BF=AE=E6=94=B9=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B4=BB=E8=B7=83=E5=AD=A6=E7=94=9F=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=EF=BC=8C=20=E8=8E=B7=E5=8F=96=E4=BD=9C=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E5=8C=BF=E8=AF=84=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/course_dynamic.rb | 15 +++++++-- app/api/mobile/entities/homework.rb | 17 +++++++--- app/api/mobile/entities/user.rb | 2 ++ app/helpers/api_helper.rb | 32 ++++++++++++++++++- app/services/courses_service.rb | 38 ++++++++++++++--------- db/schema.rb | 10 ++++++ 6 files changed, 93 insertions(+), 21 deletions(-) diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index f9bc5a8ee..fe31668ff 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -58,10 +58,11 @@ module Mobile course_dynamic_expose :document_count course_dynamic_expose :topic_count course_dynamic_expose :homework_count - + course_dynamic_expose :course_student_num + course_dynamic_expose :time_from_now course_dynamic_expose :current_user_is_member course_dynamic_expose :current_user_is_teacher - #在dynamics里解析出四种动态 + expose :documents,using:Mobile::Entities::Attachment do |f,opt| obj = nil f[:dynamics].each do |d| @@ -110,6 +111,16 @@ module Mobile obj end + expose :active_students,using:Mobile::Entities::User do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 7 + obj = d[:active_students] + end + end + obj + end + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index 03edd502f..db3e44119 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -30,6 +30,13 @@ module Mobile f.course.homework_commons.index(f) + 1 when :homework_status_teacher homework_status_desc f + when :student_evaluation_part + get_evaluation_part f ,3 + when :ta_evaluation_part + get_evaluation_part f , 2 + when :homework_anony_type + val = f.homework_type == 1 && !f.homework_detail_manual.nil? + val end end end @@ -79,12 +86,14 @@ module Mobile homework_expose :homework_submit_num homework_expose :homework_notsubmit_num - expose :submit_student_list ,using: Mobile::Entities::User do |f,opt| - get_submit_sutdent_list f - end - homework_expose :homework_status_student #老师看到的作业的状态 + homework_expose :homework_status_student #学生看到的作业的状态 homework_expose :homework_status_teacher #老师看到的状态 + homework_expose :student_evaluation_part #学生匿评比率 + homework_expose :ta_evaluation_part #教辅评价比率 + + homework_expose :homework_anony_type #是否是匿评作业 + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 2b3483625..16048c61a 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -53,6 +53,8 @@ module Mobile user_expose :score #学号 user_expose :student_num + # 活跃值 + user_expose :active_count end end diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index d3dc441ae..ac0357f53 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -129,9 +129,39 @@ module ApiHelper def show_homework_deadline homework day = 0 if (day = (Date.parse(homework.end_time.to_s) - Date.parse(Time.now.to_s)).to_i) > 0 - "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + "距作业截止还有" << day.to_s << "天" else "已截止,但可补交" end end + + #获取作业中学生的匿评比率 + # 匿评比率 = 学生总共评价的作业的作业份数 / 作业份数 * 分配数 * 100% + # 教辅匿评比率 = 教辅已经评价的作业份数 / 总的作业份数 * 100% + def get_evaluation_part homework,role + homework_eva_completed_task_num = 0 + homework_eva_task_num = 0 + #匿评作业 # 且匿评状态不是还没有开启匿评 + if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 + # 总共需要评价的任务数 + homework_eva_task_num = homework.homework_detail_manual.evaluation_num * homework.student_works.count + unless homework_eva_task_num == 0 #总任务数不为0 的情况下 + #获取已经评价了多少的份作业 student_work_score里记录了评价情况,每条记录有提交作业的id + #先求出提交作业的id集合 + work_ids = "(" + homework.student_works.map(&:id).join(",") + ")" + #只要 student_work_score 中的 student_work_id在work_ids集合中,那么久说明这个任务被完成了 + + sql = "select count(1) from student_works_scores where reviewer_role = #{role} and student_work_id in #{work_ids} " + homework_eva_completed_task_num = ActiveRecord::Base.connection().select_value(sql) + end + end + if homework_eva_task_num == 0 + 0 + else + ( homework_eva_completed_task_num / homework_eva_task_num.to_f * 100 ) .round(2) + end + + end + + end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 545ab1dac..94dcaf6fc 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -4,6 +4,7 @@ class CoursesService include CoursesHelper include HomeworkAttachHelper include ApiHelper + include ActionView::Helpers::DateHelper #参数school_id为0或不传时返回所有课程,否则返回对应学校的课程 #参数per_page_count分页功能,每页显示的课程数 @@ -657,22 +658,12 @@ class CoursesService membership.each do |mp| course = mp.course latest_course_dynamics = [] - dynamics_count = 0 - # 课程学霸 学生总分数排名靠前的5个人 - homework_count = course.homework_commons.count - sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << - " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,6" - better_students = User.find_by_sql(sql) - if homework_count != 0 && !better_students.empty? - latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> better_students} - dynamics_count += 1 - end + # 课程通知 latest_news = course.news.page(1).per(2).order("created_on desc") unless latest_news.first.nil? latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count, :news => latest_news.all} - dynamics_count += 1 end # 课程讨论区 @@ -694,12 +685,31 @@ class CoursesService homeworks = course.homework_commons.page(1).per(2).order('created_at desc') unless homeworks.first.nil? latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks} - dynamics_count += 1 end - latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } + latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } + # 课程学霸 学生总分数排名靠前的5个人 + homework_count = course.homework_commons.count + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,4" + better_students = User.find_by_sql(sql) + # 找出在课程讨论区发帖回帖数最多的 + active_students = [] + sql1 = " select users.*,count(author_id) active_count from messages " << + " LEFT JOIN users on messages.author_id = users.id " << + " where messages.board_id in (select id from boards where boards.course_id = #{course.id} ) " << + " GROUP BY messages.author_id ORDER BY count(author_id) desc " << + " limit 0,4" + active_students = User.find_by_sql(sql1) + if homework_count != 0 && !better_students.empty? + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 4,:better_students=> better_students} + end + unless active_students.empty? + latest_course_dynamics <<{:type=> 7,:time=>Time.now.to_s,:count=> 4,:active_students=>active_students} + end latest_course_dynamic = latest_course_dynamics.first unless latest_course_dynamic.nil? - result << {:course_name => course.name,:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course), :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => dynamics_count, :dynamics => latest_course_dynamics, :count => dynamics_count} + result << {:course_name => course.name,:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course), :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => "", :dynamics => latest_course_dynamics, + :course_student_num=>course ? course.members.count : 0,:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前"} end end #返回数组集合 diff --git a/db/schema.rb b/db/schema.rb index 988d5649a..78dfb5eee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -721,6 +721,16 @@ ActiveRecord::Schema.define(:version => 20150702073308) do add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_details_copy", :force => true do |t| + t.integer "journal_id", :default => 0, :null => false + t.string "property", :limit => 30, :default => "", :null => false + t.string "prop_key", :limit => 30, :default => "", :null => false + t.text "old_value" + t.text "value" + end + + add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_replies", :id => false, :force => true do |t| t.integer "journal_id" t.integer "user_id"