From 5a6c191b5d0eb9615cf5b1ce5d44fe87e82d32c1 Mon Sep 17 00:00:00 2001 From: pjaspers Date: Thu, 30 Apr 2020 15:44:53 +0200 Subject: [PATCH 1/3] Update Dentaku to latest version --- lib/orbf/rules_engine/builders/calculator_factory.rb | 7 +++++++ orbf-rules_engine.gemspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/orbf/rules_engine/builders/calculator_factory.rb b/lib/orbf/rules_engine/builders/calculator_factory.rb index f616901..54250b7 100644 --- a/lib/orbf/rules_engine/builders/calculator_factory.rb +++ b/lib/orbf/rules_engine/builders/calculator_factory.rb @@ -88,6 +88,13 @@ def self.build(options = { nested_data_support: false, case_sensitive: true }) calculator.add_function(:between, :logical, BETWEEN) calculator.add_function(:abs, :number, ->(number) { number.abs }) calculator.add_function(:score_table, :numeric, SCORE_TABLE) + # Dentaku now has AVG and SUM builtin, as well as ROUNDDOWN and ROUNDUP + # Their behavior is slightly different. + # AVG(1,3,9) => In our function: 4,333333 + # In Dentaku: 4.0 (if one of the elements is a float, it does work the same) + # + # Since we're mostly using our go-hesabu library, I'm just keeping these as is and ignoring the + # builtin functions. calculator.add_function(:avg, :numeric, AVG) calculator.add_function(:sum, :numeric, SUM) calculator.add_function(:safe_div, :numeric, SAFE_DIV) diff --git a/orbf-rules_engine.gemspec b/orbf-rules_engine.gemspec index 52cd038..9c6fd1a 100644 --- a/orbf-rules_engine.gemspec +++ b/orbf-rules_engine.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |spec| spec.add_dependency "activesupport" spec.add_dependency "colorize" spec.add_dependency "hesabu" - spec.add_dependency "dentaku", "3.1.0" + spec.add_dependency "dentaku", "~> 3.3" spec.add_dependency "dhis2", "2.3.8" spec.add_dependency "descriptive_statistics" From 0256e84d85d1ce2a87257ba768aed8149c21f161 Mon Sep 17 00:00:00 2001 From: pjaspers Date: Thu, 30 Apr 2020 15:53:22 +0200 Subject: [PATCH 2/3] Fix deprecation warnings in > 2.5 This is mostly to do with the keyword arguments being more strict. Where we used to be able to just throw a hash to a method, we now need to explicitly tell ruby to treat the hash as keyword arguments. This fixes these calls. We have a couple of places in our used gems where this still pops up: /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dentaku-3.3.4/lib/dentaku/exceptions.rb:95: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dentaku-3.3.4/lib/dentaku/exceptions.rb:78: warning: The called method `initialize' is defined here And /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dhis2-2.3.8/lib/dhis2/collection_wrapper.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/pjaspers/development/blsq/orbf-rules_engine/vendor/ruby/2.7.0/gems/dhis2-2.3.8/lib/dhis2/api/analytic.rb:7: warning: The called method `list' is defined here --- .../rules_engine/services/fetch_and_solve.rb | 2 +- lib/orbf/rules_engine/value_object.rb | 2 +- .../printers/dhis2_values_printer_spec.rb | 22 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/orbf/rules_engine/services/fetch_and_solve.rb b/lib/orbf/rules_engine/services/fetch_and_solve.rb index b0726ff..c46a1ac 100644 --- a/lib/orbf/rules_engine/services/fetch_and_solve.rb +++ b/lib/orbf/rules_engine/services/fetch_and_solve.rb @@ -25,7 +25,7 @@ def call @exported_values = RulesEngine::Dhis2ValuesPrinter.new( solver.variables, solver.solution, - project.default_combos_ext_ids + **project.default_combos_ext_ids ).print exported_values diff --git a/lib/orbf/rules_engine/value_object.rb b/lib/orbf/rules_engine/value_object.rb index 8be420d..1c421e5 100644 --- a/lib/orbf/rules_engine/value_object.rb +++ b/lib/orbf/rules_engine/value_object.rb @@ -70,7 +70,7 @@ def attribute(attr) end def with(hash) - new(hash) + new(**hash) end end end diff --git a/spec/lib/orbf/rules_engine/printers/dhis2_values_printer_spec.rb b/spec/lib/orbf/rules_engine/printers/dhis2_values_printer_spec.rb index ad2510a..695d638 100644 --- a/spec/lib/orbf/rules_engine/printers/dhis2_values_printer_spec.rb +++ b/spec/lib/orbf/rules_engine/printers/dhis2_values_printer_spec.rb @@ -37,7 +37,7 @@ it "export no values" do result_values = described_class.new( [variable_without_mapping], - variable_without_mapping.key => 1.5 + { variable_without_mapping.key => 1.5 } ).print expect(result_values).to eq([]) @@ -52,7 +52,7 @@ it "export values " do result_values = described_class.new( [variable_with_mapping], - variable_with_mapping.key => 1.5 + { variable_with_mapping.key => 1.5 } ).print expect(result_values).to eq( @@ -153,7 +153,7 @@ def build_package(single_mapping) it "export no values" do result_values = described_class.new( [activity_variable_without_mapping], - activity_variable_without_mapping.key => 1.5 + { activity_variable_without_mapping.key => 1.5 } ).print expect(result_values).to eq([]) end @@ -191,7 +191,7 @@ def build_package(single_mapping) it "export decimal that are actually integer as integer" do result_values = described_class.new( [var1, var2], - var1.key => 15, var2.key => 15 + {var1.key => 15, var2.key => 15} ).print expect(result_values).to eq( [ @@ -218,8 +218,8 @@ def build_package(single_mapping) result_values = described_class.new( variables, - activity_variable_with_exportable_formula_code.key => 15.0, - exportable_variable.key => false + { activity_variable_with_exportable_formula_code.key => 15.0, + exportable_variable.key => false } ).print expect(result_values).to eq( @@ -239,8 +239,8 @@ def build_package(single_mapping) result_values = described_class.new( variables, - activity_variable_with_exportable_formula_code.key => 15.0, - exportable_variable.key => true + { activity_variable_with_exportable_formula_code.key => 15.0, + exportable_variable.key => true } ).print expect(result_values).to eq( @@ -300,7 +300,7 @@ def build_package(options) formulas: [ Orbf::RulesEngine::Formula.new( "quality_score", "31", "", - options + **options ), Orbf::RulesEngine::Formula.new( "exportable", "1 == 1", "" @@ -367,7 +367,7 @@ def build_package(options) def expect_exported_value(variable, solution_value, expected_value, period) result_values = described_class.new( [variable], - variable.key => solution_value + { variable.key => solution_value } ).print expect(result_values).to eq( [ @@ -411,7 +411,7 @@ def build_package(options) formulas: [ Orbf::RulesEngine::Formula.new( "quality_score", "31", "", - options + **options ) ] ) From 487063c85337d273d0e78ef1810bf305b8596ef3 Mon Sep 17 00:00:00 2001 From: pjaspers Date: Thu, 30 Apr 2020 15:59:06 +0200 Subject: [PATCH 3/3] Test against multiple rubies Explicitly install newer bundler (travis defaults to 1.x bundler), on ruby 2.7 this step isn't needed, but the other ones do need it. Since the bundler will be cached after the first install let's keep it like this. --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2aebeec..b609751 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,11 @@ sudo: false language: ruby cache: bundler rvm: -- 2.5.1 + - 2.5 + - 2.6 + - 2.7 before_install: - - gem uninstall -i /home/travis/.rvm/gems/ruby-2.5.1@global bundler -x - - gem install bundler -v 2.1.4 + - gem install bundler before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter