12 Nov 2019
A selection of methods for calculating alcohol levels for homebrewers.
Alcohol calculators are kind of like a game of darts for homebrewers. We measure a starting
gravity before initiating fermentation by looking at the liquid line on a floating measurement,
squinting a bit and declaring it some nice round number. Then we do the same thing again after
fermentation is done. Then we plug those into our favorite ABV Calculator and see what it says.
And if we don’t like that number, we plug it into another one. Each calculator gives a different number, so we kind of squint and settle on some number that seems reasonable and is somewhat near what most of the calculators we consulted told us.
It’s a mess, really. But it’s just an estimate. And it allows us to get an ABV for our homebrews without spending the time and money to get a lab analysis done.
This little project was pretty much just a way for me to play around. It involved several steps:
Find formulas for calculating alcohol by volume given starting and ending gravity. Most of the calculators out there don’t want to share their magic. So this ended up being an adventure in trawling brewing forums for folks who have talked about their formulas. I ended up with 4 distinct formulas I could work with, and gave them names to tell them apart.
Write the code to do the calculations. I, of course, wanted to write something that followed decent coding practices and was reasonably flexible. I ended up with a simple interface-implementation pattern for the calculators themselves, paired with a factory for instantiating each one.
Write the UI to handle the inputting of the starting and ending gravities, and to spew out the results of the calculators. I don’t really write UIs, so this was pushing me out of my comfort zone. And that’s good. I decided to use React so that I had the option to throw it into an Android app right along-side the web view I was planning. And also because it has material-ui which makes things look nice even if they’re written by an old-school style-blind engineer like me.
Write a WordPress plug-in to get this onto the Labs web-site. This was, again, pushing me out
of my comfort zone. It could be argued that nobody should be comfortable working with PHP. It was
a useful tool for certain situations at a time when it was needed. But since I have the desire to
post such things as this on my Labs web-site, it’s something I needed to learn. (The Labs
web site is no longer powered by WordPress.)
Write this post. Really, this is it. The show off step.
Copyright © 1998-2021 by Topher ZiCornell · All rights reserved