<commit_before>require 'rubygems'
require 'bundler/setup'

require 'sinatra'
require 'tempodb'

API_KEY = "cc0c654d01774b128c1e0495de51784b"
API_SECRET = "a280c43f6b27400998a4aba0b1eb4545"

get '/data' do
  content_type :json

  client = TempoDB::Client.new(API_KEY, API_SECRET)

  start = Time.utc(2012, 9, 15)
  stop  = Time.utc(2012, 9, 16)
  keys  = ["temperature"]
  data = client.read(start, stop, keys: keys, interval: "1min", function: "mean")
  data = data.first.data.map{ |dp| {ts: dp.ts, value: dp.value} }
  data.to_json
end
<commit_msg>Allow setting of timestamps<commit_after>require 'rubygems'
require 'bundler/setup'

require 'sinatra'
require 'time'
require 'tempodb'

API_KEY = "cc0c654d01774b128c1e0495de51784b"
API_SECRET = "a280c43f6b27400998a4aba0b1eb4545"

get '/data' do
  content_type :json

  return [].to_json if (params[:start].nil? or Time.parse(params[:start]).nil?)
  return [].to_json if (params[:stop].nil? or Time.parse(params[:stop]).nil?)

  client = TempoDB::Client.new(API_KEY, API_SECRET)

  start = Time.parse params[:start]
  stop  = Time.parse params[:stop]
  keys  = ["temperature"]
  data = client.read(start, stop, keys: keys, interval: "1min", function: "mean")
  data = data.first.data.map{ |dp| {ts: dp.ts, value: dp.value} }
  data.to_json
end

{'fraction_non_alphanumeric': 0.14694508894044858, 'fraction_numerical': 0.07888631090487239, 'mean_word_length': 5.075117370892019, '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': '3551733', 'n_tokens_mistral': 582, 'n_tokens_neox': 516, 'n_words': 111}