<commit_before># frozen_string_literal: true
json.array! @assessments do |assessment|
  json.id assessment.id
  json.title assessment.title
  json.description assessment.description
  json.published assessment.published
  json.baseExp assessment.base_exp
  json.timeBonusExp assessment.time_bonus_exp
  json.hasPersonalTimes assessment.has_personal_times
  json.affectsPersonalTimes assessment.affects_personal_times
  json.tabId assessment.tab_id
  json.autograded assessment.autograded
  json.sessionPassword assessment.session_password
  json.tabbedView assessment.tabbed_view
  json.skippable assessment.skippable
  json.delayedGradePublication assessment.delayed_grade_publication
  json.showPrivate assessment.show_private
  json.showEvaluation assessment.show_evaluation
  json.viewPassword assessment.view_password
  json.usePublic assessment.use_public
  json.usePrivate assessment.use_private
  json.useEvaluation assessment.use_evaluation
  json.allowPartialSubmission assessment.allow_partial_submission
  json.randomization assessment.randomization
  json.showMcqAnswer assessment.show_mcq_answer
  json.showMcqMrqSolution assessment.show_mcq_mrq_solution
  json.blockStudentViewingAfterSubmitted assessment.block_student_viewing_after_submitted
end<commit_msg>feat(assessments): index responds to json<commit_after># frozen_string_literal: true
achievements_enabled = !current_component_host[:course_achievements_component].nil?
submissions_hash = @assessments.to_h { |assessment| [assessment.id, assessment.submissions] }

json.display do
  json.student current_course_user&.student? || false
  json.gamified current_course.gamified?
  json.randomization current_course.allow_randomization
  json.achievements achievements_enabled
  json.bonusAttributes show_bonus_attributes?
  json.endTimes show_end_at?
  json.canCreateAssessments can?(:create, Course::Assessment.new(tab: @tab))

  json.category do
    json.id @category.id
    json.title @category.title
    json.tabs @category.tabs.each do |tab|
      json.id tab.id
      json.title tab.title
    end
  end

  json.tabId @tab.id
end

json.assessments @assessments do |assessment|
  json.id assessment.id
  json.title assessment.title

  json.passwordProtected !assessment.view_password.nil?
  json.published assessment.published?
  json.autograded assessment.autograded?
  json.hasPersonalTimes current_course.show_personalized_timeline_features && assessment.has_personal_times?
  json.affectsPersonalTimes current_course.show_personalized_timeline_features && assessment.affects_personal_times?
  json.url course_assessment_path(current_course, assessment)

  assessment_with_loaded_timeline = @items_hash[assessment.id].actable
  can_attempt_assessment = can?(:attempt, assessment_with_loaded_timeline)
  json.canAttempt can_attempt_assessment

  submissions = submissions_hash[assessment.id]
  attempting_submission = submissions.find(&:attempting?)
  submitted_submission = submissions.find { |submission| !submission.attempting? }

  action_url = nil
  if !current_course_user || !can_attempt_assessment
    status = 'unavailable'
  elsif cannot?(:access, assessment) && can_attempt_assessment
    status = 'locked'
    action_url = course_assessment_path(current_course, assessment)
  elsif !attempting_submission.nil?
    status = 'attempting'
    action_url = edit_course_assessment_submission_path(current_course, assessment, attempting_submission)
  elsif !submitted_submission.nil?
    status = 'submitted'
    action_url = edit_course_assessment_submission_path(current_course, assessment, submitted_submission)
  else
    status = 'open'
    action_url = course_assessment_attempt_path(current_course, assessment)
  end

  json.status status
  json.actionUrl action_url

  can_view_submissions = can?(:view_all_submissions, assessment)
  json.submissionsUrl course_assessment_submissions_path(current_course, assessment) if can_view_submissions

  can_edit_assessment = can?(:manage, assessment)
  json.editUrl edit_course_assessment_path(current_course, assessment) if can_edit_assessment

  if achievements_enabled
    achievement_conditionals = @conditional_service.achievement_conditional_for(assessment)

    top_dependants = achievement_conditionals.first(3)
    json.topDependants top_dependants do |achievement|
      json.url course_achievement_path(current_course, achievement)
      json.badgeUrl achievement_badge_path(achievement)
      json.title achievement.title
    end

    dependants_count = achievement_conditionals.size
    json.remainingDependantsCount dependants_count - top_dependants.size if dependants_count > top_dependants.size
  end

  json.baseExp assessment.base_exp if current_course.gamified? && assessment.base_exp > 0

  assessment_time = @items_hash[assessment.id].time_for(current_course_user)
  json.conditionSatisfied !condition_not_satisfied(
    can_attempt_assessment,
    assessment_with_loaded_timeline,
    assessment_time
  )

  json.isStartTimeBegin !assessment_not_started(assessment_time)
  json.startAt do
    json.partial! 'course/lesson_plan/items/personal_or_ref_time', locals: {
      item: @items_hash[assessment.id],
      course_user: current_course_user,
      attribute: :start_at,
      datetime_format: :short
    }
  end

  has_bonus_attributes = assessment_time.bonus_end_at.present? && assessment.time_bonus_exp > 0
  if show_bonus_attributes? && has_bonus_attributes
    json.timeBonusExp assessment.time_bonus_exp
    json.isBonusEnded assessment.bonus_end_at <= Time.zone.now
    json.bonusEndAt do
      json.partial! 'course/lesson_plan/items/personal_or_ref_time', locals: {
        item: @items_hash[assessment.id],
        course_user: current_course_user,
        attribute: :bonus_end_at,
        datetime_format: :short
      }
    end
  end

  has_end_time = assessment_time.end_at.present?
  if show_end_at? && has_end_time
    json.isEndTimePassed assessment.ended?
    json.endAt do
      json.partial! 'course/lesson_plan/items/personal_or_ref_time', locals: {
        item: @items_hash[assessment.id],
        course_user: current_course_user,
        attribute: :end_at,
        datetime_format: :short
      }
    end
  end
end
{'fraction_non_alphanumeric': 0.07036797934151065, 'fraction_numerical': 0.0004841833440929632, 'mean_word_length': 5.421761658031088, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6985148', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1886, 'n_words': 312}