2015-06-30 15:17:22 +08:00
|
|
|
|
# encoding: utf-8
|
2015-01-20 17:42:18 +08:00
|
|
|
|
module ApiHelper
|
|
|
|
|
#获取用户的工作单位
|
|
|
|
|
def get_user_work_unit user
|
|
|
|
|
work_unit = ""
|
|
|
|
|
if user.user_extensions.identity == 0 || user.user_extensions.identity == 1
|
|
|
|
|
work_unit = user.user_extensions.school.name unless user.user_extensions.school.nil?
|
|
|
|
|
elsif user.user_extensions.identity == 3
|
|
|
|
|
work_unit = user.user_extensions.occupation
|
|
|
|
|
elsif user.user_extensions.identity == 2
|
|
|
|
|
work_unit = user.firstname
|
|
|
|
|
end
|
|
|
|
|
work_unit
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取用户地区
|
|
|
|
|
def get_user_location user
|
|
|
|
|
location = ""
|
|
|
|
|
location << (user.user_extensions.location || '')
|
|
|
|
|
location << (user.user_extensions.location_city || '')
|
|
|
|
|
location
|
|
|
|
|
end
|
2015-01-21 15:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_assigned_homeworks(homeworks, n, index)
|
|
|
|
|
homeworks += homeworks
|
|
|
|
|
homeworks[index + 1 .. index + n]
|
|
|
|
|
end
|
2015-01-22 17:21:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stars_to_json_like starts,show_jour,homework,show_name
|
|
|
|
|
result = []
|
|
|
|
|
starts.each do |s|
|
|
|
|
|
comment = get_homework_review homework,show_jour,s.rater
|
|
|
|
|
rater_name = show_name ? s.rater.login : l(:label_anonymous)
|
|
|
|
|
rater_id = show_name ? s.rater.id : ''
|
|
|
|
|
result << {:rater_id =>rater_id ,:rater_name => rater_name,:created_at => format_time(s.created_at),:stars => s.stars,:comment => comment}
|
|
|
|
|
end
|
|
|
|
|
result
|
|
|
|
|
end
|
2015-02-06 11:22:29 +08:00
|
|
|
|
|
|
|
|
|
#########################################################
|
|
|
|
|
#sw
|
|
|
|
|
#获取课程未匿评数量
|
|
|
|
|
#param: user => "用户", course_id => "查询的课程ID"
|
|
|
|
|
#return: 作业的数量
|
|
|
|
|
#########################################################
|
2015-02-06 15:52:34 +08:00
|
|
|
|
def get_course_anonymous_evaluation user,course
|
2015-02-06 11:22:29 +08:00
|
|
|
|
count = 0
|
|
|
|
|
if course
|
|
|
|
|
is_teacher = is_course_teacher user,course
|
|
|
|
|
if is_teacher #如果是老师,显示学生提交的作业数
|
|
|
|
|
course.homeworks.each do |bid|
|
|
|
|
|
count += bid.homeworks.count
|
|
|
|
|
end
|
|
|
|
|
else #如果是学生,显示未匿评的数量
|
|
|
|
|
course.homeworks.each do |bid|
|
|
|
|
|
count += get_student_not_batch_homework_list bid,user
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-02-06 15:52:34 +08:00
|
|
|
|
[count,is_teacher]
|
2015-02-06 11:22:29 +08:00
|
|
|
|
end
|
2015-03-19 14:41:31 +08:00
|
|
|
|
|
|
|
|
|
def get_user_language user
|
|
|
|
|
(user.language.nil? || user.language == "") ? 'zh':user.language
|
|
|
|
|
end
|
2015-06-30 15:17:22 +08:00
|
|
|
|
|
|
|
|
|
# 获取课程作业的状态
|
|
|
|
|
def get_homework_status homework
|
|
|
|
|
homework_status = ""
|
|
|
|
|
if !homework.nil?
|
|
|
|
|
if homework.homework_type == 1 && homework.homework_detail_manual
|
|
|
|
|
case homework.homework_detail_manual.comment_status
|
|
|
|
|
when 1
|
|
|
|
|
homework_status = show_homework_deadline homework
|
|
|
|
|
when 2
|
|
|
|
|
homework_status = "正在匿评中"
|
|
|
|
|
when 3
|
|
|
|
|
homework_status = "匿评已结束"
|
|
|
|
|
end
|
|
|
|
|
elsif homework.homework_type == 0
|
|
|
|
|
homework_status = "未启用匿评"
|
|
|
|
|
elsif homework.homework_type == 2
|
|
|
|
|
homework_status = "编程作业"
|
|
|
|
|
else
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
homework_status
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-03 12:22:33 +08:00
|
|
|
|
#获取作业的是否可以匿评的描述
|
|
|
|
|
def homework_status_desc homework
|
|
|
|
|
if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业
|
|
|
|
|
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
2015-07-04 09:35:04 +08:00
|
|
|
|
link = "截止日期之前不可启动匿评"
|
2015-07-03 12:22:33 +08:00
|
|
|
|
elsif homework.student_works.count >= 2 #作业份数大于2
|
|
|
|
|
case homework.homework_detail_manual.comment_status
|
|
|
|
|
when 1
|
|
|
|
|
link = '启动匿评'
|
|
|
|
|
when 2
|
|
|
|
|
link = '关闭匿评'
|
|
|
|
|
when 3
|
|
|
|
|
link = " 匿评结束"
|
|
|
|
|
end
|
|
|
|
|
else
|
2015-07-04 09:35:04 +08:00
|
|
|
|
link = "提交作业数大于2才可启动匿评"
|
2015-07-03 12:22:33 +08:00
|
|
|
|
end
|
|
|
|
|
else
|
2015-07-04 09:35:04 +08:00
|
|
|
|
link = "未开启匿评作业不可启动匿评"
|
2015-07-03 12:22:33 +08:00
|
|
|
|
end
|
|
|
|
|
link
|
|
|
|
|
end
|
|
|
|
|
|
2015-06-30 15:17:22 +08:00
|
|
|
|
#获取
|
|
|
|
|
def get_submit_sutdent_list homework
|
|
|
|
|
studentlist = []
|
|
|
|
|
if homework.is_a?(Hash) && homework.key?(:studentlist)
|
|
|
|
|
studentlist = homework[:studentlist]
|
|
|
|
|
else
|
|
|
|
|
homework.student_works.order("created_at desc").page(1).per(6).each do |work|
|
|
|
|
|
studentlist << work.user
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
studentlist
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#计算作业的截止日期,剩余日期
|
|
|
|
|
def show_homework_deadline homework
|
2015-07-03 12:22:33 +08:00
|
|
|
|
day = 0
|
|
|
|
|
if (day = (Date.parse(homework.end_time.to_s) - Date.parse(Time.now.to_s)).to_i) > 0
|
2015-07-07 17:18:29 +08:00
|
|
|
|
"距作业截止还有" << day.to_s << "天"
|
2015-07-03 12:22:33 +08:00
|
|
|
|
else
|
|
|
|
|
"已截止,但可补交"
|
|
|
|
|
end
|
2015-06-30 15:17:22 +08:00
|
|
|
|
end
|
2015-07-07 17:18:29 +08:00
|
|
|
|
|
|
|
|
|
#获取作业中学生的匿评比率
|
|
|
|
|
# 匿评比率 = 学生总共评价的作业的作业份数 / 作业份数 * 分配数 * 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
|
2015-07-10 11:05:33 +08:00
|
|
|
|
( homework_eva_completed_task_num / homework_eva_task_num.to_f * 100 ) .round(1)
|
2015-07-07 17:18:29 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2015-01-20 17:42:18 +08:00
|
|
|
|
end
|