<commit_before>module Atheneum
  module Event
    class UpsertExam
      def self.execute!(body)
        import_from_json! body.except(:sender)
      end

      def self.import_from_json!(json)
        organization = Organization.find_by!(name: json.delete(:tenant))
        organization.switch!
        exam_data = parse_json json
        remove_previous_version exam_data[:id], exam_data[:guide_id]
        users = exam_data.delete(:users)
        exam = Exam.where(classroom_id: exam_data.delete(:id)).update_or_create! exam_data
        exam.process_users users
        exam.index_usage! organization
        exam
      end

      def self.parse_json(exam_json)
        exam = exam_json.except(:name, :language)
        exam[:guide_id] = Guide.find_by(slug: exam.delete(:slug)).id
        exam[:organization_id] = Organization.id
        exam[:users] = exam.delete(:uids).map { |uid| User.find_by(uid: uid) }.compact
        [:start_time, :end_time].each { |param| exam[param] = exam[param].to_time }
        exam
      end
<commit_msg>fix bug<commit_after>module Atheneum
  module Event
    class UpsertExam
      def self.execute!(body)
        import_from_json! body.except(:social_ids, :sender)
      end

      def self.import_from_json!(json)
        organization = Organization.find_by!(name: json.delete(:tenant))
        organization.switch!
        exam_data = parse_json json
        remove_previous_version exam_data[:id], exam_data[:guide_id]
        users = exam_data.delete(:users)
        exam = Exam.where(classroom_id: exam_data.delete(:id)).update_or_create! exam_data
        exam.process_users users
        exam.index_usage! organization
        exam
      end

      def self.parse_json(exam_json)
        exam = exam_json.except(:name, :language)
        exam[:guide_id] = Guide.find_by(slug: exam.delete(:slug)).id
        exam[:organization_id] = Organization.id
        exam[:users] = exam.delete(:uids).map { |uid| User.find_by(uid: uid) }.compact
        [:start_time, :end_time].each { |param| exam[param] = exam[param].to_time }
        exam
      end

{'fraction_non_alphanumeric': 0.11308097747963584, 'fraction_numerical': 0.0, 'mean_word_length': 2.902803738317757, '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': '4810278', 'n_tokens_mistral': 655, 'n_tokens_neox': 666, 'n_words': 118}