<commit_before>class SuggestedAnswer < ActiveRecord::Base

  belongs_to :user
  belongs_to :room_question

  validates :user_id, :room_question_id, presence: true
  validates :value, presence: true

  before_save :check_valid
  after_save :update_room

  protected

  def check_valid
    self.is_valid = room_question.question.valid_answer?(self.value)
  end

  def update_room
    if self.is_valid?
      room_question.update_attributes(winner_id: self.user_id)
      Rating::update_ratings(room_question.room.users, self.user)
    end
  end

end<commit_msg>Updated DailyStatistics after user suggested correct answer<commit_after>class SuggestedAnswer < ActiveRecord::Base

  belongs_to :user
  belongs_to :room_question

  validates :user_id, :room_question_id, presence: true
  validates :value, presence: true

  before_save :check_valid
  after_save :update_room

  protected

  def check_valid
    self.is_valid = room_question.question.valid_answer?(self.value)
  end

  def update_room
    if self.is_valid?
      room_question.update_attributes(winner_id: self.user_id)
      Rating::update_ratings(room_question.room.users, self.user)
      answer_time = Time.now - room_question.created_at
      answers_in_a_row = 0
      for q in room_question.room.room_questions.order('created_at DESC').offset(1)
        break if q.winner_id != self.user_id
        answers_in_a_row += 1
      end
      DailyStatistics.update_for_user(self.user, room_question.room.locale, answer_time, answers_in_a_row)
    end
  end

end
{'fraction_non_alphanumeric': 0.07353906762967827, 'fraction_numerical': 0.001969796454366382, 'mean_word_length': 4.183673469387755, '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': '1439386', 'n_tokens_mistral': 507, 'n_tokens_neox': 497, 'n_words': 100}