Commit 594f4d4ba5213cc8dc767949705a1c5bd1d3a2e0

Authored by Rafael Manzo
1 parent 86904b59

Fixed MetricResult history graph plot

app/assets/javascripts/module/graphic.js.coffee
@@ -13,19 +13,6 @@ class Module.Graphic @@ -13,19 +13,6 @@ class Module.Graphic
13 @display: (dates, values, container) -> 13 @display: (dates, values, container) ->
14 opts = {bezierCurve: false} 14 opts = {bezierCurve: false}
15 15
16 - #FIXME: Until this gets fixed https://github.com/nnnick/Chart.js/issues/76 this if is necessary  
17 - min_value = Math.min.apply(null, values)  
18 - max_value = Math.max.apply(null, values)  
19 -  
20 - if min_value == max_value  
21 - opts = {  
22 - bezierCurve: false,  
23 - scaleOverride: true,  
24 - scaleStartValue: (min_value - 30),  
25 - scaleSteps: 3,  
26 - scaleStepWidth: 1  
27 - }  
28 -  
29 data = { 16 data = {
30 labels : dates, 17 labels : dates,
31 datasets : [ 18 datasets : [
app/models/module_result.rb
1 class ModuleResult < KalibroClient::Entities::Processor::ModuleResult 1 class ModuleResult < KalibroClient::Entities::Processor::ModuleResult
2 -  
3 def metric_history(name) 2 def metric_history(name)
4 - history = self.processing.repository.module_result_history_of(self) 3 + history = KalibroClient::Entities::Processor::MetricResult.history_of(name, self.id, processing.repository_id)
5 grade_history = Hash.new 4 grade_history = Hash.new
6 5
7 - history.each { |date_module_result| grade_history[date_module_result.date] =  
8 - find_grade_by_metric_name(date_module_result.module_result.metric_results, name) } 6 + history.each { |date_metric_result| grade_history[date_metric_result.date] = date_metric_result.metric_result.value }
9 7
10 grade_history 8 grade_history
11 end 9 end
12 -  
13 - private  
14 -  
15 - def find_grade_by_metric_name(metric_results, name)  
16 - metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration.metric.name == name }  
17 - end  
18 end 10 end
spec/models/module_result_spec.rb
@@ -9,14 +9,11 @@ describe ModuleResult, :type =&gt; :model do @@ -9,14 +9,11 @@ describe ModuleResult, :type =&gt; :model do
9 let(:metric_configuration) { FactoryGirl.build(:another_metric_configuration_with_id) } 9 let(:metric_configuration) { FactoryGirl.build(:another_metric_configuration_with_id) }
10 let!(:metric_result) { FactoryGirl.build(:metric_result, metric_configuration: metric_configuration) } 10 let!(:metric_result) { FactoryGirl.build(:metric_result, metric_configuration: metric_configuration) }
11 let(:processing) {FactoryGirl.build(:processing)} 11 let(:processing) {FactoryGirl.build(:processing)}
12 - let(:repository) {FactoryGirl.build(:repository)}  
13 12
14 before :each do 13 before :each do
15 subject.expects(:processing).returns(processing) 14 subject.expects(:processing).returns(processing)
16 - metric_result.expects(:metric_configuration).returns(metric_configuration)  
17 - processing.expects(:repository).returns(repository)  
18 - repository.expects(:module_result_history_of).with(subject).returns([date_module_result])  
19 - ModuleResult.any_instance.expects(:metric_results).returns([metric_result]) 15 + date_module_result.expects(:metric_result).returns(metric_result)
  16 + KalibroClient::Entities::Processor::MetricResult.expects(:history_of).with(metric_configuration.metric.name, subject.id, processing.repository_id).returns([date_module_result])
20 end 17 end
21 18
22 it 'should return the history for the given metric name' do 19 it 'should return the history for the given metric name' do