json.partial! "homework_public_navigation", locals: {homework: @homework, course: @course, user: @current_user}

json.partial! "homework_btn_check", locals: {identity: @user_course_identity, homework: @homework, user: @current_user}

json.partial! "student_btn_check", locals: {identity: @user_course_identity, homework: @homework, work: @work}

json.work_count @work_count
json.all_member_count @all_member_count
json.course_group_count @course.course_groups_count

json.ta_mode @homework_detail_manual.ta_mode

json.is_evaluation @is_evaluation ? @is_evaluation : false

json.work_public @homework.work_public
json.allow_late @homework.allow_late

if @user_course_identity < Course::STUDENT

  json.calculation_time @homework.calculation_time if @homework.homework_type == "practice"
  # 教师身份的评阅、提交状态、分班过滤
  if @homework.homework_type != "practice"
    json.teacher_comment teacher_comment @homework, @current_user.id
  end
  json.task_status homework_status @homework, @member
  json.course_group_info course_group_info @course, @current_user.id

elsif @user_course_identity == Course::STUDENT
  json.commit_count studentwork_count @homework, 1, @member
  json.uncommit_count studentwork_count @homework, 0, @member
  json.left_time left_time @homework, @current_user.id

  if @homework.homework_type == "practice"
    json.(@work, :id, :work_status, :update_time, :ultimate_score)
    json.calculation_time @work.calculation_time
    json.late_penalty @work.late_penalty if @homework.allow_late
    json.cost_time @work.myshixun.try(:total_spend_time)
    json.work_score work_score_format(@work.work_score, true, @score_open)
    json.final_score work_score_format(@work.final_score, true, @score_open)
    json.efficiency work_score_format(@work.efficiency, true, @score_open)
    json.eff_score work_score_format(@work.eff_score, true, @score_open)
    json.complete_count @work.myshixun.try(:passed_count)
  else
    json.(@work, :id, :work_status, :update_time, :ultimate_score)

    json.work_score work_score_format(@work.work_score, true, @score_open)
    json.final_score work_score_format(@work.final_score, true, @score_open)
    json.teacher_score work_score_format(@work.teacher_score, true, @score_open)
    json.student_score work_score_format(@work.student_score, true, @score_open)
    json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @score_open)

    json.ta_comment_count @work.ta_comment_count

    json.late_penalty @work.late_penalty if @homework.allow_late

    if @homework.anonymous_comment
      json.student_comment_count @work.student_comment_num
      json.absence_penalty @work.absence_penalty
    end

    if @homework.anonymous_appeal
      json.appeal_all_count @work.appeal_all_count
      json.appeal_deal_count @work.appeal_deal_count
      json.appeal_penalty @work.appeal_penalty
    end

    if @homework.homework_type == "group"
      if @homework.homework_detail_group.base_on_project
        json.project_info project_info @work, @current_user, @user_course_identity
      end
      json.work_group @work.work_group_name
      json.is_leader @work.user_id == @work.commit_user_id
    end

  end
  json.user_login @work.user.login
  json.student_id @work.user.student_id
  json.user_name @work.user.real_name
  json.group_name @member.course_group_name
end

if @homework.homework_type == "practice"
  json.challenges_count @shixun.challenges_count
  json.work_efficiency @homework.work_efficiency

  json.student_works @student_works.each do |work|
    json.(work, :id, :work_status, :update_time, :ultimate_score)

    json.late_penalty work.late_penalty if @homework.allow_late
    json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open)
    json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open)
    json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open)
    json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open)

    json.cost_time work.myshixun.try(:total_spend_time)
    json.complete_count work.myshixun.try(:passed_count)
    json.user_login work.user.try(:login)
    json.user_name work.user.try(:real_name)
    json.student_id work.user.try(:student_id)
    json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
  end
elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
  json.anonymous_comment @homework.anonymous_comment
  json.anonymous_appeal @homework.anonymous_appeal

  json.student_works @student_works.each do |work|
    if @is_evaluation
      json.(work, :id, :work_status, :update_time)

      json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true)
      # json.student_comment_count anon_comments(@current_user, work.id).count

      # 申诉条数
      if @homework.anonymous_appeal
        json.appeal_all_count work.my_appeal_all_count @current_user.id
        json.appeal_deal_count work.my_appeal_deal_count @current_user.id
      end
    else
      json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score,
          :teaching_asistant_score, :ultimate_score)

      json.late_penalty work.late_penalty if @homework.allow_late
      json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open)
      json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open)
      json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @score_open)
      json.student_score work_score_format(work.student_score, @current_user == work.user, @score_open)
      json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @score_open)

      # 助教评分次数
      json.ta_comment_count work.ta_comment_count

      # 作品匿评条数
      if @homework.anonymous_comment
        json.student_comment_count @homework_detail_manual.comment_status > 2 ? work.student_comment_num : 0
        json.absence_penalty work.absence_penalty
      end

      json.student_id work.user.try(:student_id)
      json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
      if @homework.homework_type == "group"
        if @homework.homework_detail_group.base_on_project
          json.project_info project_info work, @current_user, @user_course_identity
        end
        json.is_leader work.user_id == work.commit_user_id
        json.work_group work.work_group_name
      end

      # 申诉条数
      if @homework.anonymous_appeal
        json.appeal_all_count work.appeal_all_count
        json.appeal_deal_count work.appeal_deal_count
        json.appeal_penalty work.appeal_penalty
      end
    end

    json.user_login @is_evaluation ?  "--" : work.user.try(:login)
    json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name)

  end
end



