Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[ryan, tim] calling series just returns current cache. need to call u…

…pdate series data to actually calculate it
  • Loading branch information...
commit d96305aaf8d609cfb32381ad7e6eb82d5352f8fd 1 parent 99d1c26
perf authored
2  Gemfile.lock
View
@@ -10,7 +10,7 @@ GIT
PATH
remote: .
specs:
- active_metric (1.4.0.1)
+ active_metric (1.4.1)
bson_ext (= 1.4.0)
mongo (= 1.4.0)
rails (~> 3.1)
8 lib/active_metric/behavior/graph_calculation.rb
View
@@ -3,12 +3,11 @@ module GraphCalculation
#REQUIRES SUMMARY AND INTERVAL SAMPLES AND SERIES DATA
def series
- update_all_series
- self.save!
- series_data.values
+ data = series_data || initialize_cache
+ data.values
end
- def update_all_series
+ def update_series_data
self.series_data ||= initialize_cache
remaining_interval_samples.each do |sample|
@@ -18,6 +17,7 @@ def update_all_series
end
end
end
+ self.save!
end
def initialize_cache
4 lib/active_metric/sample.rb
View
@@ -10,7 +10,7 @@ class Sample
field :start_time, :type => Integer
field :end_time, :type => Integer
field :timestamp, :type => Integer
- field :measurement_count, :type => Float, :default => 0.0
+ field :measurement_count, :type => Integer, :default => 0
field :sum, :type => Integer, :default => 0
index :timestamp
@@ -100,7 +100,7 @@ def update_time(measurement)
self.sum += measurement.timestamp
self.measurement_count += 1
self.end_time = measurement.timestamp
- self.timestamp = self.sum / self.measurement_count
+ self.timestamp = (self.sum / self.measurement_count).to_i
end
def update_stats(measurement)
1  lib/active_metric/subject.rb
View
@@ -6,6 +6,7 @@ class Subject
belongs_to :report, :class_name => "ActiveMetric::Report", :polymorphic => true
has_many :samples, :class_name => "ActiveMetric::Sample", :as => :samplable, :dependent => :destroy
+
field :name, :type => String
field :series_data, :type => Hash
33 test/behavior_tests/graph_calculation_test.rb
View
@@ -3,7 +3,7 @@
module ActiveMetric
class GraphCalculationTest < ActiveSupport::TestCase
- test "can calculate series" do
+ test "can update series data" do
report = Report.create
subject = TestSubject.create :report => report
@@ -14,7 +14,7 @@ class GraphCalculationTest < ActiveSupport::TestCase
subject.complete
report.subjects.each do |subject|
- subject.series
+ subject.update_series_data
assert_equal [[2,4],[7,9]], subject.series_data["max_value"]["data"]
assert_equal [[2,0],[7,5]], subject.series_data["min_value"]["data"]
assert_equal [[2,2],[7,7]], subject.series_data["mean_value"]["data"]
@@ -32,7 +32,7 @@ class GraphCalculationTest < ActiveSupport::TestCase
end
subject.complete
- subject.series
+ subject.update_series_data
assert_equal 2, subject.size_of_cache_data
15.times do |value|
@@ -41,9 +41,34 @@ class GraphCalculationTest < ActiveSupport::TestCase
subject.complete
assert_equal 2, subject.size_of_cache_data
- subject.series
+ subject.update_series_data
assert_equal 5, subject.size_of_cache_data
end
+ test "series return empty cache if no series data" do
+ report = Report.create
+ subject = TestSubject.create :report => report
+
+ assert_nil subject.series_data
+
+ assert_equal [
+ {"name"=>"max_value", "data"=>[], "yAxis"=>0},
+ {"name"=>"min_value", "data"=>[], "yAxis"=>0},
+ {"name"=>"mean_value", "data"=>[], "yAxis"=>0},
+ {"name"=>"test_count", "data"=>[], "yAxis"=>1},
+ {"name"=>"eightieth_value", "data"=>[], "yAxis"=>0},
+ {"name"=>"standard_deviation_value", "data"=>[], "yAxis"=>0},
+ {"name"=>"ninety_eighth_value", "data"=>[], "yAxis"=>0}], subject.series
+ end
+
+ test "calling series does not update subject" do
+ report = Report.create
+ subject = TestSubject.create :report => report
+
+ subject.series
+
+ assert_nil subject.series_data
+ end
+
end
end
4 test/report_test.rb
View
@@ -13,7 +13,7 @@ class ReportTest < ActiveSupport::TestCase
subject.complete
assert_nil subject.series_data
- subject.series
+ subject.update_series_data
assert_equal 2, subject.series_data.values.first["data"].count
@@ -22,7 +22,7 @@ class ReportTest < ActiveSupport::TestCase
assert_nil subject.series_data
- subject.series
+ subject.update_series_data
assert_equal 2, subject.series_data.values.first["data"].count
end
Please sign in to comment.
Something went wrong with that request. Please try again.