Commit 4dfa52386a18d977b0b6ddd30da3ae2b3eb1f2f4
Exists in
colab
and in
4 other branches
Merge pull request #280 from mezuro/use_kalibro_client_ranges
Use kalibro client ranges
Showing
7 changed files
with
42 additions
and
24 deletions
Show diff stats
Gemfile
| @@ -28,7 +28,7 @@ gem 'jbuilder', '~> 2.0' | @@ -28,7 +28,7 @@ gem 'jbuilder', '~> 2.0' | ||
| 28 | gem 'devise', '~> 3.5.1' | 28 | gem 'devise', '~> 3.5.1' |
| 29 | 29 | ||
| 30 | # Kalibro integration | 30 | # Kalibro integration |
| 31 | -gem 'kalibro_client', '~> 1.3.0' | 31 | +gem 'kalibro_client', '~> 1.4' |
| 32 | 32 | ||
| 33 | # PostgreSQL integration | 33 | # PostgreSQL integration |
| 34 | gem "pg", "~> 0.18.1" | 34 | gem "pg", "~> 0.18.1" |
Gemfile.lock
| @@ -121,7 +121,7 @@ GEM | @@ -121,7 +121,7 @@ GEM | ||
| 121 | railties (>= 3.0.0) | 121 | railties (>= 3.0.0) |
| 122 | faraday (0.9.1) | 122 | faraday (0.9.1) |
| 123 | multipart-post (>= 1.2, < 3) | 123 | multipart-post (>= 1.2, < 3) |
| 124 | - faraday_middleware (0.9.2) | 124 | + faraday_middleware (0.10.0) |
| 125 | faraday (>= 0.7.4, < 0.10) | 125 | faraday (>= 0.7.4, < 0.10) |
| 126 | gherkin (2.12.2) | 126 | gherkin (2.12.2) |
| 127 | multi_json (~> 1.3) | 127 | multi_json (~> 1.3) |
| @@ -148,9 +148,9 @@ GEM | @@ -148,9 +148,9 @@ GEM | ||
| 148 | railties (>= 3.2) | 148 | railties (>= 3.2) |
| 149 | sprockets-rails | 149 | sprockets-rails |
| 150 | json (1.8.3) | 150 | json (1.8.3) |
| 151 | - kalibro_client (1.3.0) | 151 | + kalibro_client (1.4.0) |
| 152 | activesupport (>= 2.2.1) | 152 | activesupport (>= 2.2.1) |
| 153 | - faraday_middleware (~> 0.9.0) | 153 | + faraday_middleware (~> 0.10.0) |
| 154 | konacha (3.5.1) | 154 | konacha (3.5.1) |
| 155 | actionpack (>= 3.1, < 5) | 155 | actionpack (>= 3.1, < 5) |
| 156 | capybara | 156 | capybara |
| @@ -348,7 +348,7 @@ DEPENDENCIES | @@ -348,7 +348,7 @@ DEPENDENCIES | ||
| 348 | jquery-rails | 348 | jquery-rails |
| 349 | jquery-ui-rails (~> 5.0.0) | 349 | jquery-ui-rails (~> 5.0.0) |
| 350 | js-routes (~> 1.1.0) | 350 | js-routes (~> 1.1.0) |
| 351 | - kalibro_client (~> 1.3.0) | 351 | + kalibro_client (~> 1.4) |
| 352 | konacha | 352 | konacha |
| 353 | less-rails (~> 2.7.0) | 353 | less-rails (~> 2.7.0) |
| 354 | mocha | 354 | mocha |
app/controllers/kalibro_ranges_controller.rb
| @@ -46,7 +46,6 @@ class KalibroRangesController < ApplicationController | @@ -46,7 +46,6 @@ class KalibroRangesController < ApplicationController | ||
| 46 | private | 46 | private |
| 47 | 47 | ||
| 48 | def kalibro_range_params | 48 | def kalibro_range_params |
| 49 | - params[:kalibro_range][:beginning] = params[:kalibro_range][:beginning].to_f.to_s if numeric?(params[:kalibro_range][:beginning]) # this is necessary for the beginning validator | ||
| 50 | params[:kalibro_range] | 49 | params[:kalibro_range] |
| 51 | end | 50 | end |
| 52 | 51 | ||
| @@ -87,11 +86,6 @@ class KalibroRangesController < ApplicationController | @@ -87,11 +86,6 @@ class KalibroRangesController < ApplicationController | ||
| 87 | @metric_configuration_id = params[:metric_configuration_id].to_i | 86 | @metric_configuration_id = params[:metric_configuration_id].to_i |
| 88 | end | 87 | end |
| 89 | 88 | ||
| 90 | - # used on kalibro_range_params | ||
| 91 | - def numeric?(text) | ||
| 92 | - Float(text) != nil rescue false | ||
| 93 | - end | ||
| 94 | - | ||
| 95 | def set_kalibro_range | 89 | def set_kalibro_range |
| 96 | @kalibro_range = KalibroRange.find(params[:id].to_i) | 90 | @kalibro_range = KalibroRange.find(params[:id].to_i) |
| 97 | end | 91 | end |
app/helpers/kalibro_ranges_helper.rb
| @@ -2,4 +2,12 @@ module KalibroRangesHelper | @@ -2,4 +2,12 @@ module KalibroRangesHelper | ||
| 2 | def readings_options(readings) | 2 | def readings_options(readings) |
| 3 | readings.map { |reading| [reading.label, reading.id] } | 3 | readings.map { |reading| [reading.label, reading.id] } |
| 4 | end | 4 | end |
| 5 | + | ||
| 6 | + # FIXME: this is a workaround while kalibro_client does not handle Infinity text instead of INF | ||
| 7 | + # see: https://github.com/mezuro/kalibro_client/issues/73 | ||
| 8 | + def format_boundary(value) | ||
| 9 | + return "INF" if value == Float::INFINITY | ||
| 10 | + return "-INF" if value == -Float::INFINITY | ||
| 11 | + value | ||
| 12 | + end | ||
| 5 | end | 13 | end |
app/helpers/processings_helper.rb
| @@ -9,17 +9,7 @@ module ProcessingsHelper | @@ -9,17 +9,7 @@ module ProcessingsHelper | ||
| 9 | 9 | ||
| 10 | def find_range_snapshot(metric_result) | 10 | def find_range_snapshot(metric_result) |
| 11 | range_snapshots = metric_result.metric_configuration.kalibro_ranges | 11 | range_snapshots = metric_result.metric_configuration.kalibro_ranges |
| 12 | - | ||
| 13 | - range_snapshots.each do |range_snapshot| | ||
| 14 | - range = Range.new( | ||
| 15 | - range_snapshot.beginning == '-INF' ? -Float::INFINITY : range_snapshot.beginning.to_f, | ||
| 16 | - range_snapshot.end == 'INF' ? Float::INFINITY : range_snapshot.end.to_f, | ||
| 17 | - exclude_end: true | ||
| 18 | - ) | ||
| 19 | - return range_snapshot if range === metric_result.value | ||
| 20 | - end | ||
| 21 | - | ||
| 22 | - return nil | 12 | + range_snapshots.detect { |range_snapshot| range_snapshot.range === metric_result.value } |
| 23 | end | 13 | end |
| 24 | 14 | ||
| 25 | def format_module_name(module_name) | 15 | def format_module_name(module_name) |
app/views/metric_configurations/_ranges.html.erb
| @@ -5,8 +5,8 @@ | @@ -5,8 +5,8 @@ | ||
| 5 | <span style="color: #<%= kalibro_range.color %>"><%= kalibro_range.label %></span> | 5 | <span style="color: #<%= kalibro_range.color %>"><%= kalibro_range.label %></span> |
| 6 | </div> | 6 | </div> |
| 7 | </td> | 7 | </td> |
| 8 | - <td><%= kalibro_range.beginning %></td> | ||
| 9 | - <td><%= kalibro_range.end %></td> | 8 | + <td><%= format_boundary(kalibro_range.beginning) %></td> |
| 9 | + <td><%= format_boundary(kalibro_range.end) %></td> | ||
| 10 | <td> | 10 | <td> |
| 11 | <% if kalibro_configuration_owner? @metric_configuration.kalibro_configuration_id %> | 11 | <% if kalibro_configuration_owner? @metric_configuration.kalibro_configuration_id %> |
| 12 | <%= link_to t('edit'), edit_kalibro_configuration_metric_configuration_kalibro_range_path( | 12 | <%= link_to t('edit'), edit_kalibro_configuration_metric_configuration_kalibro_range_path( |
spec/helpers/kalibro_ranges_helper_spec.rb
| @@ -7,5 +7,31 @@ describe KalibroRangesHelper, :type => :helper do | @@ -7,5 +7,31 @@ describe KalibroRangesHelper, :type => :helper do | ||
| 7 | expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]] | 7 | expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]] |
| 8 | end | 8 | end |
| 9 | end | 9 | end |
| 10 | + | ||
| 11 | + describe 'format_boundary' do | ||
| 12 | + context 'with a finite value' do | ||
| 13 | + let(:value) { 10 } | ||
| 14 | + | ||
| 15 | + it 'is expected to return the value itself' do | ||
| 16 | + expect(helper.format_boundary(value)).to eq(value) | ||
| 17 | + end | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + context 'with positive infinity value' do | ||
| 21 | + let(:value) { Float::INFINITY } | ||
| 22 | + | ||
| 23 | + it 'is expected to return the string "INF"' do | ||
| 24 | + expect(helper.format_boundary(value)).to eq("INF") | ||
| 25 | + end | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + context 'with negative infinity value' do | ||
| 29 | + let(:value) { -Float::INFINITY } | ||
| 30 | + | ||
| 31 | + it 'is expected to return the string "-INF"' do | ||
| 32 | + expect(helper.format_boundary(value)).to eq("-INF") | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + end | ||
| 10 | end | 36 | end |
| 11 | 37 |