Created
February 26, 2020 13:33
-
-
Save cpoo22/f7f10239e0063fb80c08e19d84be731c to your computer and use it in GitHub Desktop.
Simple hack to extract all the excesses from our models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To use, put this somewhere on the load path in Chopin OR add its directory to the load path eg. $: << (path to this file) | |
# require 'excess_extractor' | |
# | |
# Then ExcessExtractor.new.show and you will get your out put. | |
class ExcessExtractor | |
def show | |
X_Rated::Rating::Repository.load_all_models | |
chopin_models = X_Rated::Rating::Repository.rating_models.rating_models['Chopin'] | |
chopin_models.each do |vertical_name, vertical| | |
vertical.each do |product_name, product| | |
product.each do |insurer_name, insurer| | |
insurer.each do |cp_name, model_containter| | |
puts "#{vertical_name} #{product_name} #{insurer_name} #{cp_name}" | |
show_excesses(model_containter.model) | |
end | |
end | |
end | |
end | |
nil | |
end | |
def show_excesses(model) | |
model_level_specific_excesses = model.instance_variable_get(:@specific_excesses_hash) | |
puts "\tModel level specific excesses" | |
model_level_specific_excesses.each do |k, v| | |
puts "\t\t#{k} #{v.value}" | |
end | |
model.covers.each do |cover| | |
puts "\tCover level main excesses: #{cover.name}" | |
show_main_excess(cover.instance_variable_get(:@excess)) | |
specific_excesses = cover.instance_variable_get(:@specific_excesses_hash) | |
puts "\tCover level specific excesses" unless specific_excesses.empty? | |
specific_excesses.each do |k, v| | |
puts "\t\t#{k} #{v.value}" | |
end | |
end | |
nil | |
end | |
def show_main_excess(excess) | |
if excess.send(:lookup_object_exists?) | |
options = excess.send(:lookup_object).instance_variable_get(:@actual_lookup).options | |
options.each do |option| | |
option.matchers.each do |matcher| | |
puts "\t\tLookup key:#{matcher.key} expected_value:#{matcher.expected_value} result:#{option.result}" | |
end | |
end | |
else | |
puts "\t\tSimple #{excess.value}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment