<commit_before>require 'elasticsearch/model'

class Response < ApplicationRecord
  include Elasticsearch::Model

  def as_indexed_json(options={})
    {
      id: id,
      uid: uid,
      question_uid: question_uid,
      parent_id: parent_id,
      parent_uid: parent_uid,
      text: text,
      feedback: feedback,
      count: count,
      child_count: child_count,
      first_attempt_count: first_attempt_count,
      author: author,
      status: grade_status,
    }
  end

  def grade_status
    if feedback.nil?
      return 4
    elsif parent_uid || parent_id
      optimal ? 2 : 3
    else
      optimal ? 0 : 1
    end
  end

end
<commit_msg>set up mapping for elasticsearch<commit_after>require 'elasticsearch/model'

class Response < ApplicationRecord
  include Elasticsearch::Model

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :text, fielddata: true
      indexes :id, type: 'integer'
      indexes :uid, type: 'string'
      indexes :question_uid, type: 'string'
      indexes :parent_id, type: 'integer'
      indexes :parent_uid, type: 'string'
      indexes :feedback, type: 'text'
      indexes :count, type: 'integer'
      indexes :child_count, type: 'integer'
      indexes :first_attempt_count, type: 'integer'
      indexes :author, type: 'string'
      indexes :status, type: 'integer'
      indexes :created_at, type: 'integer'
    end
  end

  def as_indexed_json(options={})
    {
      id: id,
      uid: uid,
      question_uid: question_uid,
      parent_id: parent_id,
      parent_uid: parent_uid,
      text: text,
      feedback: feedback,
      count: count,
      child_count: child_count,
      first_attempt_count: first_attempt_count,
      author: author,
      status: grade_status,
      created_at: created_at.to_i
    }
  end

  def grade_status
    if feedback.nil?
      return 4
    elsif parent_uid || parent_id
      optimal ? 2 : 3
    else
      optimal ? 0 : 1
    end
  end

end

{'fraction_non_alphanumeric': 0.08472012102874432, 'fraction_numerical': 0.005547150781643974, 'mean_word_length': 2.5942028985507246, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5733934', 'n_tokens_mistral': 648, 'n_tokens_neox': 629, 'n_words': 175}