Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Created January 11, 2010 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmarkoh/274739 to your computer and use it in GitHub Desktop.
Save markmarkoh/274739 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo'
def db
$db ||= Mongo::Connection.new("localhost", 27017).db("logs")
end
def logs
$logs ||= db.collection("flex")
end
class Chart
@@reduce_count = "function(key, values) { " +
"var sum = 0; " +
"values.forEach(function(f) { " +
" sum += f.count; " +
"}); " +
"return {count: sum};" +
"};"
def self.upload_types
@map = "function() { emit(this.uploadType, {count: 1}); }"
@reduce = @@reduce_count
#@results = logs.map_reduce(@map, @reduce)
@results = logs.map_reduce(@map, @reduce,{'query'=> {"function" => "upload"}})
end
#return data set where requests are grouped and counted per day(86400 seconds)
def self.count_all_activity
@map = "function() { emit(this.time - (this.time % 86400), {count: 1}); }"
@reduce = @@reduce_count
@results = logs.map_reduce(@map, @reduce)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment