Created
January 11, 2010 23:57
-
-
Save markmarkoh/274739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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