Last active
July 27, 2019 21:46
-
-
Save MatthewRDodds/04b388e63befc1454161999f1f9e514e to your computer and use it in GitHub Desktop.
valve_calculator.rb
This file contains hidden or 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
require 'json' | |
require 'pry' | |
class ValveLifterPositionCalculator | |
LIFTER_MEASUREMENT_FOR_GAP_MEASURE = 0.2090 | |
LIFTERS = [ | |
{ id: 29, inches: 0.2090, mm: 5.30680 }, | |
{ id: 32, inches: 0.2106, mm: 5.34924 }, | |
{ id: 32, inches: 0.2103, mm: 5.34162 }, | |
{ id: 34, inches: 0.2107, mm: 5.35178 }, | |
{ id: 34, inches: 0.2113, mm: 5.36702 }, | |
{ id: 35, inches: 0.2113, mm: 5.36702 }, | |
{ id: 36, inches: 0.2144, mm: 5.44576 }, | |
{ id: 36, inches: 0.2120, mm: 5.38480 }, | |
{ id: 39, inches: 0.2146, mm: 5.45084 }, | |
{ id: 39, inches: 0.2143, mm: 5.44322 }, | |
{ id: 39, inches: 0.2138, mm: 5.43052 }, | |
{ id: 39, inches: 0.2139, mm: 5.43306 }, | |
{ id: 41, inches: 0.2150, mm: 5.46100 }, | |
{ id: 41, inches: 0.2151, mm: 5.46354 }, | |
{ id: 42, inches: 0.2157, mm: 5.47878 }, | |
{ id: 43, inches: 0.2152, mm: 5.46608 } | |
] | |
GAP_MEASURESMENTS = [ | |
{ location: :intake, position: '2A', mm: 0.18, inches: 0.008 }, | |
{ location: :intake, position: '2B', mm: 0.18, inches: 0.007 }, | |
{ location: :intake, position: '3B', mm: 0.20, inches: 0.008 }, | |
{ location: :intake, position: '4B', mm: 0.20, inches: 0.009 }, | |
{ location: :intake, position: '4A', mm: 0.23, inches: 0.013 }, | |
{ location: :intake, position: '1B', mm: 0.25, inches: 0.011 }, | |
{ location: :intake, position: '3A', mm: 0.28, inches: 0.013 }, | |
{ location: :exhaust, position: '5B', mm: 0.30, inches: 0.012 }, | |
{ location: :exhaust, position: '7B', mm: 0.30, inches: 0.014 }, | |
{ location: :intake, position: '1A', mm: 0.33, inches: 0.013 }, | |
{ location: :exhaust, position: '6A', mm: 0.33, inches: 0.013 }, | |
{ location: :exhaust, position: '8A', mm: 0.35, inches: 0.016 }, | |
{ location: :exhaust, position: '5A', mm: 0.35, inches: 0.013 }, | |
{ location: :exhaust, position: '8B', mm: 0.38, inches: 0.016 }, | |
{ location: :exhaust, position: '7A', mm: 0.40, inches: 0.017 }, | |
{ location: :exhaust, position: '6B', mm: 0.40, inches: 0.017 } | |
] | |
INTAKE_GAP_ALLOWANCE_MIN = 0.008 # inches | |
INTAKE_GAP_ALLOWANCE_MAX = 0.011 # inches | |
EXHAUST_GAP_ALLOWANCE_MIN = 0.012 # inches | |
EXHAUST_GAP_ALLOWANCE_MAX = 0.016 # inches | |
def calculate | |
calculations = {} | |
GAP_MEASURESMENTS.each do |gap_measurement| | |
position = gap_measurement[:position] | |
calculations[position] = matches_in_spec(gap_measurement) | |
end | |
calculations.each { |position, matches| puts "#{position}: #{matches.join(',')}" } | |
end | |
def matches_in_spec(gap_measurement) | |
LIFTERS.map do |lifter| | |
total_gap = gap_measurement[:inches] + LIFTER_MEASUREMENT_FOR_GAP_MEASURE | |
gap_after_lifter_used = total_gap - lifter[:inches] | |
lifter[:id] if in_spec?(gap_measurement, gap_after_lifter_used) | |
end.compact | |
end | |
def in_spec?(gap_measurement, gap_after_lifter_used) | |
if gap_measurement[:location] == :exhaust | |
gap_after_lifter_used >= EXHAUST_GAP_ALLOWANCE_MIN && | |
gap_after_lifter_used <= EXHAUST_GAP_ALLOWANCE_MAX | |
elsif gap_measurement[:location] == :intake | |
gap_after_lifter_used >= INTAKE_GAP_ALLOWANCE_MIN && | |
gap_after_lifter_used <= INTAKE_GAP_ALLOWANCE_MAX | |
end | |
end | |
end | |
ValveLifterPositionCalculator.new.calculate | |
# 2A: 29 | |
# 2B: | |
# 3B: 29 | |
# 4B: 29 | |
# 4A: 34,35,36,39,39 | |
# 1B: 32,32,34,34,35,36 | |
# 3A: 34,35,36,39,39 | |
# 5B: 29 | |
# 7B: 29,32,32,34 | |
# 1A: 34,35,36,39,39 | |
# 6A: 29 | |
# 8A: 29,32,32,34,34,35,36 | |
# 5A: 29 | |
# 8B: 29,32,32,34,34,35,36 | |
# 7A: 32,32,34,34,35,36,39,39 | |
# 6B: 32,32,34,34,35,36,39,39 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment