<commit_before># frozen_string_literal: true
module Course::Assessment::Submission::WorkflowEventConcern
  extend ActiveSupport::Concern

  included do
    before_validation :assign_experience_points, if: :workflow_state_changed?
  end

  protected

  # Handles the finalisation of a submission.
  #
  # This finalises all current answers as well.
  def finalise(_ = nil)
    self.submitted_at = Time.zone.now
    current_answers.select(&:attempting?).each(&:finalise!)

    assign_zero_experience_points if assessment.questions.empty?
  end

  # Handles the marking of a submission.
  #
  # This will grade all the answers, and set the points_awarded as a draft.
  def mark(_ = nil)
    publish_answers
  end

  def unmark(_ = nil)
    answers.each do |answer|
      answer.unmark! if answer.graded?
    end
  end

  # Handles the publishing of a submission.
  #
  # This grades all the answers as well.
  def publish(_ = nil)
    publish_answers

    self.publisher = User.stamper || User.system
    self.published_at = Time.zone.now<commit_msg>Freeze and recompute personal times on submit<commit_after># frozen_string_literal: true
module Course::Assessment::Submission::WorkflowEventConcern
  extend ActiveSupport::Concern
  include Course::LessonPlan::PersonalizationConcern

  included do
    before_validation :assign_experience_points, if: :workflow_state_changed?
  end

  protected

  # Handles the finalisation of a submission.
  #
  # This finalises all current answers as well.
  def finalise(_ = nil)
    self.submitted_at = Time.zone.now
    save!

    # Freeze personal time at whatever the current times for the user are
    course_user = creator.course_users.find_by(course: assessment.course)
    personal_time = assessment.find_or_create_personal_time_for(course_user)
    personal_time.save! if personal_time.changed?

    current_answers.select(&:attempting?).each(&:finalise!)

    assign_zero_experience_points if assessment.questions.empty?

    # Trigger timeline recomputation
    # NB: We are not recomputing on unsubmission because unsubmit is not done by the student
    update_personalized_timeline_for(course_user)
  end

  # Handles the marking of a submission.
  #
  # This will grade all the answers, and set the points_awarded as a draft.
  def mark(_ = nil)
    publish_answers
  end

  def unmark(_ = nil)
    answers.each do |answer|
      answer.unmark! if answer.graded?
    end
  end

  # Handles the publishing of a submission.
  #
  # This grades all the answers as well.
  def publish(_ = nil)
    publish_answers

    self.publisher = User.stamper || User.system
    self.published_at = Time.zone.now
{'fraction_non_alphanumeric': 0.07177937287495277, 'fraction_numerical': 0.0, 'mean_word_length': 3.8058076225045374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3874689', 'n_tokens_mistral': 829, 'n_tokens_neox': 784, 'n_words': 237}