<commit_before>class ThingseeCloudDatum
  def self.deliver(type)

    require 'rubygems'
    require 'httparty'
    require 'json'

    begin
      device_id = ENV["THINGSEE_ID"]
      device_token = ENV["THINGSEE_TOKEN"]
      query_base = "http://api.thingsee.com/v1/events/"+device_id+"?type=sense"
      query_headers = { 'Content-Type' => 'application/json', 'Authorization' => device_token}

      if type == "temperature"
        record = Array.new
        #get only the latest temperature data
        query = query_base+"&senses=0x00060100&limit=1"

        # record = [
        # "latitude",
        # "longitude",
        # "mtime", (timestamp of data push to cloud)
        # "temperature",
        # "source (=thingsee)"]

        result = HTTParty.get(query,
                               {
                                   :headers => query_headers
                               })
        # TODO set up lookup so that it doesn't matter if order of data in json-response is random
        # atm lookup is dependent on order of sense data in hash; if specified data not present in hash, value is nil
        temperature = result['events'][0]['cause']['senses'][0]['val'] if result['events'][0]['cause']['senses'][0]
        latitude = result['events'][0]['cause']['senses'][1]['val'] if result['events'][0]['cause']['senses'][1]
        longitude = result['events'][0]['cause']['senses'][2]['val'] if result['events'][0]['cause']['senses'][2]
        timestamp = result['events'][0]['timestamp'] if result['events'][0]['timestamp']

        record << latitude
        record << longitude
        record << timestamp
        record << temperature
        record << 'thingsee'

        return record
      end
      if type == "air_quality"
        record = Array.new
        return record
      end
    rescue
      "error"
    end
  end
end<commit_msg>nil data throws error<commit_after>class ThingseeCloudDatum
  def self.deliver(type)

    require 'rubygems'
    require 'httparty'
    require 'json'

    begin
      device_id = ENV["THINGSEE_ID"]
      device_token = ENV["TH<PASSWORD>E_TOKEN"]
      query_base = "http://api.thingsee.com/v1/events/"+device_id+"?type=sense"
      query_headers = { 'Content-Type' => 'application/json', 'Authorization' => device_token}

      if type == "temperature"
        record = Array.new
        #get only the latest temperature data
        query = query_base+"&senses=0x00060100&limit=1"

        # record = [
        # "latitude",
        # "longitude",
        # "mtime", (timestamp of data push to cloud)
        # "temperature",
        # "source (=thingsee)"]

        result = HTTParty.get(query,
                               {
                                   :headers => query_headers
                               })
        # TODO set up lookup so that it doesn't matter if order of data in json-response is random
        # atm lookup is dependent on order of sense data in hash; if specified data not present in hash, value is nil

        temperature = result['events'][0]['cause']['senses'][0]['val'] if result['events'][0]['cause']['senses'][0]
        latitude = result['events'][0]['cause']['senses'][1]['val'] if result['events'][0]['cause']['senses'][1]
        longitude = result['events'][0]['cause']['senses'][2]['val'] if result['events'][0]['cause']['senses'][2]
        timestamp = result['events'][0]['timestamp'] if result['events'][0]['timestamp']

        record << latitude
        record << longitude
        record << timestamp
        record << temperature
        record << 'thingsee'
        record.each {|entry|
          if entry.nil?
            raise "nil"
          end
        }

        return record
      end
      if type == "air_quality"
        record = Array.new
        return record
      end
    rescue
      "error"
    end
  end
end
{'fraction_non_alphanumeric': 0.14085603112840467, 'fraction_numerical': 0.01297016861219196, 'mean_word_length': 2.270568278201866, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5276727', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1082, 'n_words': 273}