Before the death of my drives I had a flexible Measurement class written up. As most of you know brewing involves all kinds of measurement – hop weights, boil volume, bitterness, etc. The class served as a base that more specific classes would inherit and provided the framework for converting between different measurement systems. For example, the SpecificGravity class would inherit Measurement and provide the conversion code to switch between SG and Plato.
The database would save the scalar and units and instantiate an aggregation of these two pieces. When the units changed, back into the database it went with the new values. It was very easy to work with, but took me quite a bit of time to write.
“Why not use one of the libraries already available?” you might ask. The short answer is that they do not fit my needs. Firstly, none of them produced objects that I could stuff in the database as a aggregation – most are intended as great extensions to various number classes. Secondly, and most importantly, none of them dealt with Bitterness, Color or Specific Gravity, which is really why I need a measurement class. Lastly, most of them only handled linear transformations:
m2 = a * m1 + b
To convert from SG to Plato you need to use a cubic polynomial, ugh.
So I wrote my own, then re-wrote it, and it was beautiful. Now I am re-engineering the whole thing. In addition, I’ll have to figure out where I got the Plato to SG reverse conversion. I remember trying to solve the cubic equation, then finding something that actually worked.
It is a little faster-going because I wrote it all before, but I had some tr1cky 31337 code in there that I will have to figure out again.
Always make sure your backups are working and current.
–Dean
Quick update.
The Measurement class is going well – it should be ready much sooner than the three weeks it took me last time.
Measurement: working, may need some tweaks as I go along
Temperature: done – Fahrenheit, Celsius and Kelvin supported
Weight, Volume: done US and metric supported, but I may need to add a few more unit types
Still to come:
Bitterness, SpecificGravity, Color and maybe Time
I’m pleased because this will free me up to do the interesting development work.