<commit_before>class Country < ActiveRecord::Base

  def self.update_sentiments
    Country.all.each do |c|
      tweets = Tweet.where("country_code = '#{c.country_code}' and sentiment_score is not null")
      overall_sentiment = (tweets.pluck(:sentiment_score).inject(:+) / tweets.length).round(2)
      c.update_attributes(overall_sentiment: overall_sentiment)
    end
  end

  def self.new_countries
    Tweet.all.each do |t|
      Country.find_or_create_by(country_code: t.country_code)
    end
  end
end
<commit_msg>Account for edge case in country model when updating overall sentiment<commit_after>class Country < ActiveRecord::Base

  def self.update_sentiments
    Country.all.each do |c|
      tweets = Tweet.where("country_code = '#{c.country_code}' and sentiment_score is not null")

      unless tweets.empty?
        overall_sentiment = (tweets.pluck(:sentiment_score).inject(:+) / tweets.length).round(2)
        c.update_attributes(overall_sentiment: overall_sentiment)
      end
    end
  end

  def self.new_countries
    Tweet.all.each do |t|
      Country.find_or_create_by(country_code: t.country_code)
    end
  end
end

{'fraction_non_alphanumeric': 0.09798775153105861, 'fraction_numerical': 0.0017497812773403325, 'mean_word_length': 3.7666666666666666, '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': '5152645', 'n_tokens_mistral': 379, 'n_tokens_neox': 372, 'n_words': 79}