Permalink
Browse files

[ryan, tim] graph calculations should recalculate the last sample

  • Loading branch information...
1 parent 0b62239 commit 9976e5479001064edb037e5e6a1f99c5144bf449 perf committed Jan 18, 2012
@@ -9,6 +9,7 @@ def series
def update_series_data
self.series_data ||= initialize_cache
+ remove_last_sample_from_cache
remaining_interval_samples.each do |sample|
sample.stats.each do|stat|
@@ -31,6 +32,12 @@ def initialize_cache
empty_cache
end
+ def remove_last_sample_from_cache
+ series_data.values.each do |cache|
+ cache["data"].pop
+ end
+ end
+
def remaining_interval_samples
sample_skip = size_of_cache_data
interval_samples.skip(sample_skip)
@@ -28,7 +28,6 @@ def calculate(measurement)
set_start_time(measurement) unless start_time
if within_interval?(measurement)
-
update_time(measurement)
update_stats(measurement)
return self
@@ -58,7 +58,7 @@ class GraphCalculationTest < ActiveSupport::TestCase
{"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
+ {"name"=>"ninety_eighth_value", "data"=>[], "yAxis"=>0}].sort{|a,b| a["name"] <=> b["name"]}, subject.series.sort{|a,b| a["name"] <=> b["name"]}
end
test "calling series does not update subject" do
@@ -70,5 +70,27 @@ class GraphCalculationTest < ActiveSupport::TestCase
assert_nil subject.series_data
end
+ test "update series data recalculates last sample" do
+ report = Report.create
+ subject = TestSubject.create :report => report
+
+ 9.times do |value|
+ subject.calculate TestMeasurement.new(:value => value, :timestamp => value)
+ end
+
+ subject.complete
+
+ subject.update_series_data
+
+ assert_equal [[2,4],[6,8]], subject.series_data["max_value"]["data"]
+
+
+ subject.calculate TestMeasurement.new(:value => 9, :timestamp => 9)
+ subject.complete
+
+ subject.update_series_data
+ assert_equal [[2,4],[7,9]], subject.series_data["max_value"]["data"]
+ end
+
end
end

0 comments on commit 9976e54

Please sign in to comment.