5

Is anyone aware of a good script or library free/Open Source that can be used on a web page to calculate ABV, I'm not looking for a sites that will do the calculation for you, I want to add the javascript to my site to do the calculation.

I wrote a simple javascript but wasn't able to figure out the calculation that factored in temperature from the time it was measured. I was going to post my Javascript and html here but I cant figure out how to post my html so i'll just give the javascript below.

Also if someones know the mathematical equations to get ABV factoring in temperature I could write the JavaScript

function calcAbv() {
  var og = document.frm.og.value;
  var fg = document.frm.fg.value;
  document.frm.oneabv.value = Math.round((og - fg) * 131.25,2);
  document.frm.onealtabv.value = Math.round((76.08 * (og - fg) / (1.775 - og)) * (fg / 0.794),2);
  document.frm.twoabv.value = Math.round((1.05/0.79) * (( og- fg )/fg) * 100,2);
  document.frm.twobasabv.value = Math.round((og - fg) * 131,2);
  document.frm.threeabv.value = Math.round(((76.08 * (og - fg) / (1.775 - og)) * (fg / 0.794)),2);
  document.frm.threebasoneabv.value = Math.round(((og - fg) / .75) * 100,2);
  document.frm.threebastwoabv.value = Math.round((og - fg) * 131,2);
  document.frm.fourabv.value = Math.round((og - fg) * 131,2);
}
3
  • bunch of formulas: homebrewtalk.com/wiki/index.php/Beer_math Why does temperature matter for ABV calc? Sure you don't mean hydrometer adjustment?
    – Tom McCann
    Commented Jul 30, 2013 at 21:56
  • 1
    @TomMcCann The temperature can affect the reading from the hydrometer because the buoyancy is different at different temperatures. I found this [Hydrometer Temp Correction] (homebrewtalk.com/wiki/index.php/…) formula at site you provided. Thanks a lot!
    – rcasady616
    Commented Jul 31, 2013 at 5:47
  • To post code, there's a button with curly braces: "{}" That will indent the code by four spaces, indicating that it should render as a code block using mono-space font.
    – Scott
    Commented Jul 31, 2013 at 18:43

5 Answers 5

8

There is brauhaus - a javascript library for homebrew beer calculations, both in the browser and on the server

I have not used it - the homepage says features include:

  • Support for multiple Javascript runtimes Node.js 0.6.x, 0.8.x, 0.10.x Chrome, Firefox, Internet Explorer 9+, Safari, Opera, etc
  • Calculate estimated OG, FG, IBU, ABV, SRM color, calories, and more
  • Tinseth and Rager IBU calculation formula support Pellets vs. whole hops support
  • Late addition boil support
  • Dry hopping support
  • Built-in unit conversions (kg <-> lb/oz, liter <-> gallon, temps, etc)
  • Color in °SRM to name, °EBC, °Lovibond, RGB conversions, CSS color, etc
  • Plugin support to add additional features
  • Lightweight - about 28kb when minified

It can be used as a client javascript library - the homepage lists examples of doing calculations. The main interface to the calculations is via a recipe - since you want direct calculation of ABV from the OG/FG, you may need to look through the code to find that specific calculation. The alternative is to build a dummy recipe and add ingredients, or try setting the recipe's OG and FG values directly.

1
  • Thx @mdma this looks like a great library to get me started, and its open source so I'm happy
    – rcasady616
    Commented Aug 7, 2013 at 20:26
3

There was a discussion on HBT about this. If you measure in Fahrenheit, the formula is as follows:

C = ((1.313454 - (0.132674*F) + (0.00205779 * F^2) - (0.000002627634 * F^2)))

Where C is the correction, and F is degrees Fahrenheit of the liquid being measured with the hydrometer. This assumes the hydrometer is calibrated for 59 degrees Fahrenheit. If you measure the degrees in Celsius, the following formula will accomplish the same, assuming (again) that the hydrometer is calibrated at an equivalent 15 degrees Celsius (changing F to DC as to not confuse with correction C):

C = ((1.313454 - (0.132674 * ((DC * 1.8) + 32)) + (0.00205779 * (((DC * 1.8) + 32))^2)) - (0.111112627634 * (((DC * 1.8) + 32))^3)))

Therefor, if you want to adjust your two variables up-front, replacing the unadjusted variables, you would do the following (assuming the temperature is variable name document.frm.og.temp and is measured in degrees Fahrenheit):

function calcAbv() {
  var og = ((1.313454 - (0.132674*document.frm.og.temp) + (0.00205779 * Math.pow(document.frm.og.temp, 2)) - (0.000002627634 * Math.pow(document.frm.og.temp, 2)))) + (document.frm.og.value * 0.001),
      fg = ((1.313454 - (0.132674*document.frm.fg.temp) + (0.00205779 * Math.pow(document.frm.fg.temp, 2)) - (0.000002627634 * Math.pow(document.frm.fg.temp, 2)))) + (document.frm.fg.value * 0.001);

  // Rest of the function
}

Otherwise, if it is measured in degrees Celsius, the following would work just as well:

function calcAbv() {
  var og = ((1.313454 - (0.132674 * ((document.frm.og.temp * 1.8) + 32)) + (0.00205779 * Math.pow((((document.frm.og.temp * 1.8) + 32)), 2))) - (0.111112627634 * Math.pow((((document.frm.og.temp * 1.8) + 32)), 3)))) + (document.frm.og.value * 0.001),
      fg = ((1.313454 - (0.132674 * ((document.frm.fg.temp * 1.8) + 32)) + (0.00205779 * Math.pow((((document.frm.fg.temp * 1.8) + 32)), 2))) - (0.111112627634 * Math.pow((((document.frm.fg.temp * 1.8) + 32)), 3)))) + (document.frm.fg.value * 0.001);

  // Rest of the function
}
3
  • It's correct, but not the nicest code I've seen! :) You should pull the temperature and gravity readings out from the DOM to a local variable, then do conversion (C to F if needed), then apply temp correction and finally calculate the abv. The code will be much clearer rather than trying to compound all of these steps (with inherent repetition) into the ABV calculation.
    – mdma
    Commented Jul 31, 2013 at 18:23
  • I agree, but as I don't know the context of his DOM, I merely plugged in the formula given the Javascript provided. If he were to post the entire code, we could bump it over to Stack Exchange and assist in cleaning it up.
    – Scott
    Commented Jul 31, 2013 at 18:37
  • Yes, I was thinking this was off-topic for this site, and a better fit for SO/Programming.
    – mdma
    Commented Jul 31, 2013 at 18:45
2

I use Brewtarget. It's a java open source utility that does all you need for brewing beer, including equipment calculations, mash/ sparge temps, estimates pre boil, post boil and finishing volumes and gravity, IBU, SRM and has some nice recipe and brewday instruction printouts.

1
0

Bunch of good libraries from Brewerwall. Heard about this on the homebrewchat slack channel, you should join :)

-1

can you check below url , it has 5 calculators php,js https://github.com/coolfuturefbiagent/calculators

3
  • I tried all of the calculators, and none ever got past 'Loading...' Commented Dec 16, 2015 at 15:15
  • Seems to be working for me...
    – Philippe
    Commented Dec 17, 2015 at 1:39
  • @FranklinPCombs , did you run it in your local server ? Commented Apr 19, 2016 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.