<commit_before>require 'google_drive'
require 'google_drive/auth'
require 'yaml'

module GoogleDriveHelper
  @@lookups = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/lookups.yaml')))

  def extract_metrics h, year, month, block
    Hash[h.map { |key, value| [key, metric_with_target(value, year, month, block)] }
    ]
  end

  def metric_with_target name, year, month, block
    location             = cell_location(year, name)
    location['document'] ||= @@lookups['document_keys'][environment]['default']
    ytd_method = location['ytd_method'] || @@lookups['default_ytd_method']
    ytd_aggregator = case ytd_method
    when "sum"
      Proc.new { |x| x.inject(0.0){|sum,val| sum + floatize(val) }}
    when "latest"
      Proc.new { |x| floatize(x.last) }
    end
    multiplier = location['multiplier'] || @@lookups['default_multiplier']
    data = {}
    data[:actual] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['actual']]
          ) * multiplier) if location['actual']
    data[:latest] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['latest']].slice(0,month).select{|x| x.to_f != 0.0}.last
          ) * multiplier) if location['latest']
    data[:annual_target] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['annual_target']]
          ) * multiplier) if location['annual_target']<commit_msg>Helper fetching targets or not depending on lookup<commit_after>require 'google_drive'
require 'google_drive/auth'
require 'yaml'

module GoogleDriveHelper
  @@lookups = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/lookups.yaml')))

  def extract_metrics h, year, month, block
    Hash[h.map { |key, value| [key, metric_with_target(value, year, month, block)] }
    ]
  end

  def extract_metric name, year, month, block
    location = cell_location year, name
    if location.has_key? "cell_ref"
      metrics_cell name, year, block
    else
      metric_with_target name, year, month, block
    end
  end

  def metric_with_target name, year, month, block
    location             = cell_location(year, name)
    location['document'] ||= @@lookups['document_keys'][environment]['default']
    ytd_method = location['ytd_method'] || @@lookups['default_ytd_method']
    ytd_aggregator = case ytd_method
    when "sum"
      Proc.new { |x| x.inject(0.0){|sum,val| sum + floatize(val) }}
    when "latest"
      Proc.new { |x| floatize(x.last) }
    end
    multiplier = location['multiplier'] || @@lookups['default_multiplier']
    data = {}
    data[:actual] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['actual']]
          ) * multiplier) if location['actual']
    data[:latest] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['latest']].slice(0,month).select{|x| x.to_f != 0.0}.last
          ) * multiplier) if location['latest']
    data[:annual_target] = (block.call(
            metrics_worksheet(location['document'], location['sheet'])[location['annual_target']]
          ) * multiplier) if location['annual_target']
{'fraction_non_alphanumeric': 0.15955473098330242, 'fraction_numerical': 0.0030921459492888066, 'mean_word_length': 3.9314024390243905, 'pattern_counts': {'":': 0, '<': 3, '<?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': '953909', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1008, 'n_words': 197}