<commit_before>require "mongo"

module MongoFormatter
  class Formatter
    include Mongo

    def initialize(runtime, path, options)
      @runtime = runtime

      @client = MongoClient.new("localhost", ENV["TEST_MONGO_PORT"])
      @db = @client.db(ENV["TEST_RESULT_DB"] || "meteor")
      @collection = @db.collection("results")

      @result = {:name => device_name, :id => device_id}
    end

    def after_features(features)
      scenarios = @runtime.scenarios.map do |scenario|
        {name: scenario.name,
         status: scenario.status.to_s,
         exception: scenario.exception ? scenario.exception.message : ""}
      end
      @result["scenarios"] = scenarios
      @collection.update({:id => @result[:id]}, {:$set => @result}, {:upsert => true})
    end

    private

    def device_name
      ENV["DEVICE_NAME"] || device_id  
    end

    def device_id
      ENV["ADB_DEVICE_ARG"] || ENV["DEVICE_TARGET"]
    end
  end
end<commit_msg>Added test time<commit_after>require "mongo"

module MongoFormatter
  class Formatter
    include Mongo

    def initialize(runtime, path, options)
      @runtime = runtime

      @client = MongoClient.new("localhost", ENV["TEST_MONGO_PORT"])
      @db = @client.db(ENV["TEST_RESULT_DB"] || "meteor")
      @collection = @db.collection("results")

      @result = {:name => device_name, :id => device_id, :date => Time.new}
    end

    def after_features(features)
      scenarios = @runtime.scenarios.map do |scenario|
        {name: scenario.name,
         status: scenario.status.to_s,
         exception: scenario.exception ? scenario.exception.message : ""}
      end
      @result["scenarios"] = scenarios
      @collection.update({:id => @result[:id]}, {:$set => @result}, {:upsert => true})
    end

    private

    def device_name
      ENV["DEVICE_NAME"] || device_id  
    end

    def device_id
      ENV["ADB_DEVICE_ARG"] || ENV["DEVICE_TARGET"]
    end
  end
end
{'fraction_non_alphanumeric': 0.13695090439276486, 'fraction_numerical': 0.0, 'mean_word_length': 2.9917525773195877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '6252865', 'n_tokens_mistral': 624, 'n_tokens_neox': 593, 'n_words': 131}