<commit_before>module Stem
  module Util
    def swirl
      account = "default"
      etc = "#{ENV["HOME"]}/.swirl"
      config = \
      if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
        {
          :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
          :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
          :version => "2010-08-31"
        }
      else
        account = account.to_sym
        
        if File.exists?(etc)
          data = YAML.load_file(etc)
        else
          abort("I was expecting to find a .swirl file in your home directory.")
        end
        
        if data.key?(account)
          data[account]
        else
          abort("I don't see the account you're looking for")
        end
      end

      @swirl = Swirl::EC2.new config
    end

    def tags_to_filter(tags)
      if tags.is_a? Hash
        tags = tags.inject({}) do |h, (k, v)|
          # this is really awful. how can i make this non-awful?
          k = "tag:#{k}" unless k.to_s == "architecture"
          h[k.to_s] = v
          h
        end
        get_filter_opts(tags)
      elsif tags.is_a? Array
        get_filter_opts( { "tag-key" => tags.map(&:to_s) })
      else
        get_filter_opts( { "tag-key" => [tags.to_s] })
      end
    end

    def get_filter_opts(filters)
      opts = {}
      filters.each_with_index do |(k, v), n|
        opts["Filter.#{n}.Name"] = k.to_s
        v = [ v ] unless v.is_a? Array<commit_msg>convenience tagset_to_hash method this can probably find its way into swirl eventually with the rest of the tagging stuff.<commit_after>module Stem
  module Util
    def swirl
      account = "default"
      etc = "#{ENV["HOME"]}/.swirl"
      config = \
      if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
        {
          :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
          :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
          :version => "2010-08-31"
        }
      else
        account = account.to_sym
        
        if File.exists?(etc)
          data = YAML.load_file(etc)
        else
          abort("I was expecting to find a .swirl file in your home directory.")
        end
        
        if data.key?(account)
          data[account]
        else
          abort("I don't see the account you're looking for")
        end
      end

      @swirl = Swirl::EC2.new config
    end

    def tagset_to_hash(tagset)
      tagset["item"].inject({}) { |h,v| h[v["value"]] = v["key"]; h }
    end

    def tags_to_filter(tags)
      if tags.is_a? Hash
        tags = tags.inject({}) do |h, (k, v)|
          # this is really awful. how can i make this non-awful?
          k = "tag:#{k}" unless k.to_s == "architecture"
          h[k.to_s] = v
          h
        end
        get_filter_opts(tags)
      elsif tags.is_a? Array
        get_filter_opts( { "tag-key" => tags.map(&:to_s) })
      else
        get_filter_opts( { "tag-key" => [tags.to_s] })
      end
    end

    def get_filter_opts(filters)
      opts = {}
      filters.each_with_index do |(k, v), n|
        opts["Filter.#{n}.Name"] = k.to_s
        v = [ v ] unless v.is_a? Array
{'fraction_non_alphanumeric': 0.1243277443846884, 'fraction_numerical': 0.005694400506168934, 'mean_word_length': 1.8409703504043127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4285790', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1086, 'n_words': 259}