<commit_before>require 'haml'
require 'json'
require 'mongo'
require 'sinatra'
require 'uri'

def get_connection
	return @db_connection if @db_connection
	db = URI.parse(ENV['MONGOHQ_URL'])
	db_name = db.path.gsub(/^\//, '')
	@db_connection = Mongo::Connection.new(db.host, db.port).db(db_name)
	@db_connection.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?)
	@db_connection
end

get '/' do
    haml :index
end

get '/places' do
    content_type :json
    db = get_connection
    output = ''
    coll = db.collection("places")
    coll.find().each do |row|
        output += row.inspect
    end
    output
end

get '/places/:time' do
    content_type :json
    db = get_connection
    output = ''
    coll = db.collection("places")
    coll.find("minutes" => {"$lte" => params[:time].to_i}).each do |row|
        output += row.inspect
    end
    output
end

__END__
<commit_msg>web.rb: refined JSON<commit_after>require 'haml'
require 'json'
require 'mongo'
require 'sinatra'
require 'uri'

def get_connection
	return @db_connection if @db_connection
	db = URI.parse(ENV['MONGOHQ_URL'])
	db_name = db.path.gsub(/^\//, '')
	@db_connection = Mongo::Connection.new(db.host, db.port).db(db_name)
	@db_connection.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?)
	@db_connection
end

get '/' do
    haml :index
end

get '/places' do
    content_type :json
    db = get_connection
    coll = db.collection("places")
    cursor = coll.find()
	JSON.pretty_generate(cursor.to_a)
end

get '/places/:time' do
    content_type :json
    db = get_connection
    coll = db.collection("places")
	cursor = coll.find("minutes" => {"$lte" => 60})
	JSON.pretty_generate(cursor.to_a)
end

__END__

{'fraction_non_alphanumeric': 0.14301552106430154, 'fraction_numerical': 0.0011086474501108647, 'mean_word_length': 3.0470852017937218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5838352', 'n_tokens_mistral': 702, 'n_tokens_neox': 642, 'n_words': 140}