<commit_before>namespace :report do

  desc 'Report all metrics every minute'
  task :minutely => :environment do
    hostname = `hostname`.gsub(/\n/, '')
    time = Time.now.to_i
    rounded_time = time - (time % 60)

    queue = Librato::Metrics::Queue.new
    queue.add :wheelchair_yes     => { :source => hostname, :measure_time => rounded_time, :value => Poi.fully_accessible.count   }
    queue.add :wheelchair_no      => { :source => hostname, :measure_time => rounded_time, :value => Poi.not_accessible.count     }
    queue.add :wheelchair_limited => { :source => hostname, :measure_time => rounded_time, :value => Poi.limited_accessible.count }
    queue.add :wheelchair_marked  => { :source => hostname, :measure_time => rounded_time, :value => Poi.tagged.count }
    queue.add :user_total         => { :source => hostname, :measure_time => rounded_time, :value => User.count }
    queue.add :user_with_osm_id   => { :source => hostname, :measure_time => rounded_time, :value => User.where('osm_id IS NOT NULL').count }
    queue.add :user_with_oauth    => { :source => hostname, :measure_time => rounded_time, :value => User.where('oauth_token IS NOT NULL AND oauth_secret IS NOT NULL').count }
    queue.add :login_total        => { :source => hostname, :measure_time => rounded_time, :value => User.sum(:sign_in_count), :type => :counter }

    if Counter.today.changed_within?(2)
      %w{ tag_website tag_iphone tag_android update_website update_iphone update_android create_website create_iphone create_android search_website search_iphone search_android }.each do |attrib|
        queue.add attrib => { :source => hostname, :measure_time => rounded_time, :value => Counter.sum(attrib), :type => :counter }
      end
    end
    queue.submit unless queue.empty?

  end

  desc 'Report all metrics every hour'
  task :hourly => [:regions, :iphone] do

  end

  desc 'Report iphone'
  task :iphone => :environment do
    IphoneCounter.outdated.map(&:destroy)

    time = Time.now.to_i
    rounded_time = time - (time % 60)
    queue = Librato::Metrics::Queue.new

    %w{device_versions os_versions app_versions}.each do |hash_method|
      IphoneCounter.send(hash_method.to_sym).each do |source, value|
        queue.add hash_method.singularize => {
          :source => source,
          :measure_time => rounded_time,
          :value => value
        }
      end
    end
    queue.submit unless queue.empty?
  end

  desc 'Report regions'
  task :regions => :environment do
    time = Time.now.to_i
    rounded_time = time - (time % 60)
    colors = {'yes' => '#86AF4D', 'no' => '#D6382F', 'limited' => '#F19D46'}

    hostname = `hostname`.gsub(/\n/, '')
    queue = Librato::Metrics::Queue.new
    Region.find_each do |region|
      %w{ yes no limited }.each do |status|
        metric_name = "#{region.slug.name}_#{status}"
        queue.add metric_name =>
        { :source => hostname,
          :measure_time => rounded_time,
          :value => region.pois.with_status(Poi::WHEELCHAIR_STATUS_VALUES[status.to_sym]).count,
        }
      end
    end
    queue.submit unless queue.empty?

    Region.find_each do |region|
      %w{ yes no limited }.each do |status|
        metric_name = "#{region.slug.name}_#{status}"<commit_msg>Report the total amount of nodes for regions inkl. subregions.<commit_after>namespace :report do

  desc 'Report all metrics every minute'
  task :minutely => :environment do
    hostname = `hostname`.gsub(/\n/, '')
    time = Time.now.to_i
    rounded_time = time - (time % 60)

    queue = Librato::Metrics::Queue.new
    queue.add :wheelchair_yes     => { :source => hostname, :measure_time => rounded_time, :value => Poi.fully_accessible.count   }
    queue.add :wheelchair_no      => { :source => hostname, :measure_time => rounded_time, :value => Poi.not_accessible.count     }
    queue.add :wheelchair_limited => { :source => hostname, :measure_time => rounded_time, :value => Poi.limited_accessible.count }
    queue.add :wheelchair_marked  => { :source => hostname, :measure_time => rounded_time, :value => Poi.tagged.count }
    queue.add :user_total         => { :source => hostname, :measure_time => rounded_time, :value => User.count }
    queue.add :user_with_osm_id   => { :source => hostname, :measure_time => rounded_time, :value => User.where('osm_id IS NOT NULL').count }
    queue.add :user_with_oauth    => { :source => hostname, :measure_time => rounded_time, :value => User.where('oauth_token IS NOT NULL AND oauth_secret IS NOT NULL').count }
    queue.add :login_total        => { :source => hostname, :measure_time => rounded_time, :value => User.sum(:sign_in_count), :type => :counter }

    if Counter.today.changed_within?(2)
      %w{ tag_website tag_iphone tag_android update_website update_iphone update_android create_website create_iphone create_android search_website search_iphone search_android }.each do |attrib|
        queue.add attrib => { :source => hostname, :measure_time => rounded_time, :value => Counter.sum(attrib), :type => :counter }
      end
    end
    queue.submit unless queue.empty?

  end

  desc 'Report all metrics every hour'
  task :hourly => [:regions, :iphone] do

  end

  desc 'Report iphone'
  task :iphone => :environment do
    IphoneCounter.outdated.map(&:destroy)

    time = Time.now.to_i
    rounded_time = time - (time % 60)
    queue = Librato::Metrics::Queue.new

    %w{device_versions os_versions app_versions}.each do |hash_method|
      IphoneCounter.send(hash_method.to_sym).each do |source, value|
        queue.add hash_method.singularize => {
          :source => source,
          :measure_time => rounded_time,
          :value => value
        }
      end
    end
    queue.submit unless queue.empty?
  end

  desc 'Report regions'
  task :regions => :environment do
    time = Time.now.to_i
    rounded_time = time - (time % 60)
    colors = {'yes' => '#86AF4D', 'no' => '#D6382F', 'limited' => '#F19D46'}

    hostname = `hostname`.gsub(/\n/, '')
    queue = Librato::Metrics::Queue.new
    Region.find_each do |region|
      %w{ yes no limited }.each do |status|
        metric_name = "#{region.slug.name}_#{status}"
        queue.add metric_name =>
        { :source => hostname,
          :measure_time => rounded_time,
          :value => region.pois_of_children.with_status(Poi::WHEELCHAIR_STATUS_VALUES[status.to_sym]).count,
        }
      end
    end
    queue.submit unless queue.empty?

    Region.find_each do |region|
      %w{ yes no limited }.each do |status|
        metric_name = "#{region.slug.name}_#{status}"
{'fraction_non_alphanumeric': 0.1335767533850601, 'fraction_numerical': 0.005476951163852123, 'mean_word_length': 3.2577720207253886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 109, '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': '730625', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2084, 'n_words': 500}