Skip to content

Instantly share code, notes, and snippets.

@renenw
Created October 17, 2019 18:24
Show Gist options
  • Save renenw/907b1d3b2a291c373587abe40693d3ae to your computer and use it in GitHub Desktop.
Save renenw/907b1d3b2a291c373587abe40693d3ae to your computer and use it in GitHub Desktop.
for review
def self.liquid_voltage_lookup(beer_voltage, battery_voltage)
# solve for rt in kilos: vo = vbat * (Rt/(Rt+R1))
# vbat = battery_voltage
# vo = beer_voltage
# r1 = 100
temperature = nil
rt = BigDecimal(beer_voltage,6) * BigDecimal(100,6) / ( BigDecimal(battery_voltage,6) - BigDecimal(beer_voltage,6) ) if battery_voltage!=beer_voltage
if rt
if rt >= 222.6075
temperature = -6.0
elsif rt <= 40.2726
temperature = 31.0
else
values = nil
values = { t: 30.0, start: 40.2726, end: 42.0331 } if rt > 40.2726
values = { t: 29.0, start: 42.0331, end: 43.8811 } if rt > 42.0331
values = { t: 28.0, start: 43.8811, end: 45.8214 } if rt > 43.8811
values = { t: 27.0, start: 45.8214, end: 47.8592 } if rt > 45.8214
values = { t: 26.0, start: 47.8592, end: 50.0000 } if rt > 47.8592
values = { t: 25.0, start: 50.0000, end: 52.2496 } if rt > 50.000
values = { t: 24.0, start: 52.2496, end: 54.6141 } if rt > 52.2496
values = { t: 23.0, start: 54.6141, end: 57.1002 } if rt > 54.6141
values = { t: 22.0, start: 57.1002, end: 59.7148 } if rt > 57.1002
values = { t: 21.0, start: 59.7148, end: 62.4653 } if rt > 59.7148
values = { t: 20.0, start: 62.4653, end: 65.3595 } if rt > 62.4653
values = { t: 19.0, start: 65.3595, end: 68.4060 } if rt > 65.3595
values = { t: 18.0, start: 68.4060, end: 71.6135 } if rt > 68.4060
values = { t: 17.0, start: 71.6135, end: 74.9916 } if rt > 71.6135
values = { t: 16.0, start: 74.9916, end: 78.5505 } if rt > 74.9916
values = { t: 15.0, start: 78.5505, end: 82.3008 } if rt > 78.5505
values = { t: 14.0, start: 82.3008, end: 86.2542 } if rt > 82.3008
values = { t: 13.0, start: 86.2542, end: 90.4228 } if rt > 86.2542
values = { t: 12.0, start: 90.4228, end: 94.8197 } if rt > 90.4228
values = { t: 11.0, start: 94.8197, end: 99.4589 } if rt > 94.8197
values = { t: 10.0, start: 99.4589, end: 104.3552 } if rt > 99.4589
values = { t: 9.0, start: 104.3552, end: 109.5245 } if rt > 104.3552
values = { t: 8.0, start: 109.5245, end: 114.9837 } if rt > 109.5245
values = { t: 7.0, start: 114.9837, end: 120.7510 } if rt > 114.9837
values = { t: 6.0, start: 120.7510, end: 126.8458 } if rt > 120.7510
values = { t: 5.0, start: 126.8458, end: 133.2887 } if rt > 126.8458
values = { t: 4.0, start: 133.2887, end: 140.1019 } if rt > 133.2887
values = { t: 3.0, start: 140.1019, end: 147.3091 } if rt > 140.1019
values = { t: 2.0, start: 147.3091, end: 154.9356 } if rt > 147.3091
values = { t: 1.0, start: 154.9356, end: 163.0086 } if rt > 154.9356
values = { t: 0.0, start: 163.0086, end: 171.5571 } if rt > 163.0086
values = { t: -1.0, start: 171.5571, end: 180.6125 } if rt > 171.5571
values = { t: -2.0, start: 180.6125, end: 190.2080 } if rt > 180.6125
values = { t: -3.0, start: 190.2080, end: 200.3796 } if rt > 190.2080
values = { t: -4.0, start: 200.3796, end: 211.1656 } if rt > 200.3796
values = { t: -5.0, start: 211.1656, end: 222.6075 } if rt > 211.1656
temperature = (values[:t] - 1) + (values[:end] - rt)/(values[:end]-values[:start])
end
end
temperature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment