<commit_before>class Alert

  def self.ammount_in_the_last_year
     result = CartoDB::Connection.query("SELECT sum(alerts) as alerts FROM gfw2_forma_graphs WHERE date > (SELECT n FROM gfw2_forma_datecode WHERE now() -INTERVAL '12 months' < date ORDER BY date ASC LIMIT 1);")
     result[:rows].first[:alerts] rescue 0
  end

  def self.alerts_per_country
    results = CartoDB::Connection.query("SELECT count(*) as alerts_count, iso FROM gfw2_forma WHERE z=17 GROUP BY iso;")

    Hash[results[:rows].map{|r| [r[:iso].delete('{}'), r[:alerts_count]]}] rescue []
  end

  def self.alerts_per_month_per_country(country_iso_code)

    results = CartoDB::Connection.query(<<-SQL)
      SELECT sum(alerts) as count,
             iso,
             (SELECT date
              FROM gfw2_forma_datecode
              WHERE n = gfg.date) as date
      FROM gfw2_forma_graphs gfg
      WHERE iso = '#{country_iso_code}' AND date > (SELECT n
                                    FROM gfw2_forma_datecode
                                    WHERE now() -INTERVAL '15 months' < date
                                    ORDER BY date ASC LIMIT 1)
      GROUP BY iso, date
      ORDER BY date DESC;
    SQL

    results[:rows]

  end

end<commit_msg>Changed the time range back to 6 months<commit_after>class Alert

  def self.ammount_in_the_last_year
     result = CartoDB::Connection.query("SELECT sum(alerts) as alerts FROM gfw2_forma_graphs WHERE date > (SELECT n FROM gfw2_forma_datecode WHERE now() -INTERVAL '6 months' < date ORDER BY date ASC LIMIT 1);")
     result[:rows].first[:alerts] rescue 0
  end

  def self.alerts_per_country
    results = CartoDB::Connection.query("SELECT count(*) as alerts_count, iso FROM gfw2_forma WHERE z=17 GROUP BY iso;")

    Hash[results[:rows].map{|r| [r[:iso].delete('{}'), r[:alerts_count]]}] rescue []
  end

  def self.alerts_per_month_per_country(country_iso_code)

    results = CartoDB::Connection.query(<<-SQL)
      SELECT sum(alerts) as count,
             iso,
             (SELECT date
              FROM gfw2_forma_datecode
              WHERE n = gfg.date) as date
      FROM gfw2_forma_graphs gfg
      WHERE iso = '#{country_iso_code}' AND date > (SELECT n
                                    FROM gfw2_forma_datecode
                                    WHERE now() -INTERVAL '6 months' < date
                                    ORDER BY date ASC LIMIT 1)
      GROUP BY iso, date
      ORDER BY date DESC;
    SQL

    results[:rows]

  end

end
{'fraction_non_alphanumeric': 0.09149277688603531, 'fraction_numerical': 0.011637239165329053, 'mean_word_length': 2.324, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2533697', 'n_tokens_mistral': 823, 'n_tokens_neox': 753, 'n_words': 220}