Permalink
Browse files

Added capability of cubicle to calculate durations between timestamps…

…, using a variety of different time intervals.
  • Loading branch information...
PlasticLizard committed Mar 21, 2010
1 parent 871d2b8 commit 21ac30de598d5e4c552a163b20c6499fa1cecb88
Showing with 15 additions and 2 deletions.
  1. +4 −1 cubicle.gemspec
  2. +11 −1 lib/cubicle.rb
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Nathan Stults"]
- s.date = %q{2010-03-18}
+ s.date = %q{2010-03-20}
s.description = %q{Cubicle provides a dsl and aggregation caching framework for automating the generation, execution and caching of map reduce queries when using MongoDB in Ruby. Cubicle also includes a MongoMapper plugin for quickly performing ad-hoc, multi-level group-by queries against a MongoMapper model.}
s.email = %q{hereiam@sonic.net}
s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
"lib/cubicle/data_level.rb",
"lib/cubicle/date_time.rb",
"lib/cubicle/dimension.rb",
+ "lib/cubicle/duration.rb",
"lib/cubicle/measure.rb",
"lib/cubicle/member.rb",
"lib/cubicle/member_list.rb",
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
"test/cubicle/cubicle_data_test.rb",
"test/cubicle/cubicle_query_test.rb",
"test/cubicle/cubicle_test.rb",
+ "test/cubicle/duration_test.rb",
"test/cubicle/mongo_mapper/aggregate_plugin_test.rb",
"test/cubicles/defect_cubicle.rb",
"test/log/test.log",
@@ -62,6 +64,7 @@ Gem::Specification.new do |s|
"test/cubicle/cubicle_data_test.rb",
"test/cubicle/cubicle_query_test.rb",
"test/cubicle/cubicle_test.rb",
+ "test/cubicle/duration_test.rb",
"test/cubicle/mongo_mapper/aggregate_plugin_test.rb",
"test/cubicles/defect_cubicle.rb",
"test/models/defect.rb",
View
@@ -126,8 +126,11 @@ def sum(*args)
end
def duration(*args)
+ options = args.extract_options!
+ options[:in] ||= durations_in
+ args << options
measures << (dur = Duration.new(*args))
- count("#{dur.name}_count".to_sym, :expression=>dur.expression) if dur.aggregation_method == :average
+ count("#{dur.name}_count".to_sym, :expression=>dur.expression) if dur.aggregation_method == :average
end
def average_duration(*args)
@@ -141,6 +144,13 @@ def total_duration(*args)
duration(*(args<<options))
end
+ def durations_in(unit_of_time = nil)
+ return (@duration_unit ||= :seconds) unless unit_of_time
+ @duration_unit = unit_of_time.to_s.pluralize.to_sym
+ end
+ alias :duration_unit :durations_in
+
+
def ratio(member_name, numerator, denominator)
measures << Ratio.new(member_name, numerator, denominator)
end

0 comments on commit 21ac30d

Please sign in to comment.