Author Topic: User-defined fields to include in custom reports  (Read 2103 times)

Offline GigaFemto

  • BeerSmith Grandmaster Brewer
  • *****
  • Posts: 310
  • Muonic Matter Rocks!
User-defined fields to include in custom reports
« on: September 26, 2019, 03:30:03 PM »
There are some values that BeerSmith does not calculate that users would like to see in reports. There are also some people who would like to see the availability of simple math on tagged fields in custom report (e.g. estimated cooled post-boil volume = $DISPLAY_BATCH_SIZE+$TRUB_LOSS). It may be too much of a technical challenge to permit this, but I propose a workaround that might be good enough for most purposes. If BeerSmith had a set of user-defined fields that could be printed in custom reports with tags like $USER_DEFINED_1, then  users could fill those boxes with the desired numbers and have them print in the reports. Any math would still have to be done by hand, but it would make the reports cleaner. Right now I leave blank spots in my custom reports and fill them in by hand, which is a bit of a pain and seems rather retro for 2019.

--GF

Offline gizzygizmo

  • BeerSmith Brewer
  • ***
  • Posts: 25
  • BeerSmith Rocks!
Re: User-defined fields to include in custom reports
« Reply #1 on: January 12, 2020, 12:49:42 PM »
I would love VERY much to have this... also, more access to variables.  Even if it's just $VAR_XXX and a table that we can use to look them up.  Such things like total points (cooled preboil volume x preboil SG), or displaying post-boil volume as well as "cooled" post boil volume.   

These are things items i'm scribbling down by hand on my custom brewsheets that are very helpful during brew day when trying to calculate if i need to liquor up or if something is not on par with my usual recipe.

Offline gizzygizmo

  • BeerSmith Brewer
  • ***
  • Posts: 25
  • BeerSmith Rocks!
Re: User-defined fields to include in custom reports
« Reply #2 on: March 12, 2020, 11:45:17 AM »
Cross-posting this reply... i have found a way to get access to some variables for math functions.  I can't get any info that isn't passed, but we can use javascript to strip formatting off variables and use them with math functions to make our own variables:

I found a way around this for now... the Beersmith custom report generate uses a webkit which allows javascript to run.  That allow us to do some string manipulation and math to get things.

Here's a custom report example I have where I can get some items I wanted:
1) total points = show total gravity points at mash step in case my volumes are off, i can do quick math to figure out top up water or more aggresive boil off rates.
2) Removing " SG" from the gravity readings so they fit better on the sheet... i like to say "Est OG" which is implied SG... this allows fitting more items in a row
3) converting SG to Plato
4) shrinking the water volumes for better cals.  For example, endoing boil volume may be 6.5 at flame out but after chilling it should reduce by 4% shrinkage and be 6.25... i need to use 6.25 for math operations as well as confirmation to me that i'm spot on while draining to kettle
5) a function to show actual pre-boil OG.  Due to the issues above with how preboil OG is calculated i wrote another function... this one takes points based off "pre boil OG * pre boil volume" which appears correct.. then divides it by the "shrunk" pre-boil volume to get a correct room temp reading for Preboil SG

Place this in the "head" section of your custom report:
Code: [Select]
<script>
<script>
var og = '$EST_OG';
var fg = '$EST_FG ';
var pog = '$PRE_BOIL_OG';
var prevol = '$DISPLAY_BOIL_SIZE';
var postvol = '$POST_BOIL_VOLUME';

function remove_sg(item) {
  // function to remove " SG" from end of SG so math can be performed
  return item.slice(0, 5);
}

function total_points() {
  // function to calc total points for use in adhoc math dring brewday
  // Unable to use EST_OG here due to later added adjuncts and no ability
  // to seperate the PPG of Sugard, etc.
  var vol = prevol.split(" ")[0];
  var sg = pog.slice(2, 5);
  return (vol * sg).toFixed(1)
}

function sg_to_plato(gravity) {
  // convert SG to plato for display purposes
  // plato = (-1 * 616.868) + (1111.14 * sg) ? (630.272 * sg^2) + (135.997 * sg^3)
  var sg = gravity.slice(0, 5);
  var plato = (-1 * 616.868) + (1111.14 * sg) - (630.272 * Math.pow(sg, 2)) + (135.997 *  Math.pow(sg, 3));
  return plato.toFixed(1);
}

function vol_shrink(volume, shrinkage) {
  //  reduce the "volume" of liquid by the shrinkage amount... 
  var vol = volume.split(" ")[0]
  vol = vol / shrinkage; // take out the 4% that was added due to heat
  return vol.toFixed(2);
}

function actual_preog() {
  // function to back-calculate the correct preboil SG based
  // on total points and a "room temp" sample instead of "hot" sample
  var points = remove_sg(pog).slice(2, 5) * prevol.split(" ")[0];
  var actualPreOG = points / vol_shrink(prevol, 1.03);
  return (actualPreOG / 1000 + 1).toFixed(4);
}


function populate_custom_vars() {
  document.getElementById("estOG").innerHTML = remove_sg(og);
  document.getElementById("estFG").innerHTML = remove_sg(fg);

  document.getElementById("platoOG").innerHTML = sg_to_plato(og);
  document.getElementById("platoOG2").innerHTML = sg_to_plato(og);
  document.getElementById("platoFG").innerHTML = sg_to_plato(fg);
  document.getElementById("plato_preOG").innerHTML = sg_to_plato(actual_preog())

  document.getElementById("actual_preOG").innerHTML = actual_preog();
  document.getElementById("actual_preOG2").innerHTML =actual_preog();

  document.getElementById("preboil_vol_shrinked").innerHTML = vol_shrink(prevol, 1.03) + " gal";
  document.getElementById("postboil_vol_shrinked").innerHTML = vol_shrink(postvol, 1.04) + " gal";

  document.getElementById("total_points").innerHTML = total_points();
}
</script>

Then you can space the Element-id's around as such:
Code: [Select]
<div id="wrapper">
        <div id="header">
            <div class="logo">
               <h1>$NAME</h1>
               <h2>$STYLE_NAME ($STYLE_NUMBER $STYLE_LETTER)</h2>
            </div>
        </div>
        <table>
            <tr>
                <td width="25%">
                    <div class="col4">
                        <span class="item">Batch:</span> $DISPLAY_BATCH_SIZE<br>
                        <span class="item">SRM:</span> $EST_COLOR<br>
                        <span class="item">IBU:</span> $IBU<br>
                        <span class="item">Est ABV:</span>  $EST_ABV<br>
                    </div>
                </td>

                <td width="25%">
                    <div class="col4">
                        <span class="item">Packaged Vol:</span> $BOTTLING_VOLUME<br>
                        <span class="item">Est Mash Eff:</span> $EST_MASH_EFFICIENCY<br>
                        <span class="item">Est BH Eff:</span> $EFFICIENCY %<br>
                        <span class="item">Boil time:</span>  $BOIL_TIME min<br>
                    </div>
                </td>

                <td width="25%">
                    <div class="col4">
                        <span class="item">Est OG:</span> <span id="estOG"></span> (<span id="platoOG"></span> P)<br>
                        <span class="item">Est FG:</span> <span id="estFG"></span> (<span id="platoFG"></span> P)<br>
                        <span class="item">Preboil Vol:</span> $DISPLAY_BOIL_SIZE<br>
                        <span class="item">Preboil SG:</span> <span id="actual_preOG"></span> (<span id="plato_preOG"></span> P)<br>
                    </div>
                </td>

                <td width="25%">
                    <div class="col4">
                        <span class="item">Recipe Date:</span> $DATE<br>
                        <span class="item">Total Grain:</span> $TOTAL_GRAINS<br>
                        <span class="item">Brewing Date: _____________</span><br>
                        <span class="item">Packaging Date: ___________</span><br>
                    </div>
                </td>
            </tr>
        </table>
...

        <ul class="checklist">
            <li>Switch power off HLT and set BK ALM</li>
            <li>$SPARGE_STEPS (Total $SPARGE_VOLUME)</li>
            <li>Measure pre-boil gravity _________&nbsp;&nbsp; (target: $PRE_BOIL_OG, <span id="actual_preOG2"></span> SG, total points <span id="total_points"></span>)</li>
            <li>Measure pre-boil volume _________&nbsp;&nbsp; (target: $DISPLAY_BOIL_SIZE, <span id="preboil_vol_shrinked"></span>)</li>
            <li>Sanitize bucket, airlock, o2, all remaining cold side equipment</li>
        </ul>

...

This will hold  me over for now... i have the BS estimated preboil SG, the actual expected SG, the "expanded" or "hot" volume of preboil water as well as the "cooled" volume if i need to do any quick math (SG * cooled volume = total points, divide by expected volume to get new OG... etc).

This produces outputs like this:
Code: [Select]
Batch: 6.25 gal     Packaged Vol: 5.00 gal  Est OG: 1.056 (13.8 P)          Recipe Date: 03/12/20
SRM: 7.0 SRM        Est Mash Eff: 80.0 %    Est FG: 1.015 (3.8 P)           Total Grain: 12.04 lb
IBU: 40.4 IBUs      Est BH Eff: 80.00 %     Preboil Vol: 8.01 gal           Brewing Date: _____________
Est ABV: 5.3 %      Boil time: 60 min       Preboil SG: 1.0443 (11.0 P)     Packaging Date: ___________

*** NOTE, i've chosen to include an extra decimal place in pre-boil OG because that rounding error can be important when using that for math later.

Offline GigaFemto

  • BeerSmith Grandmaster Brewer
  • *****
  • Posts: 310
  • Muonic Matter Rocks!
Re: User-defined fields to include in custom reports
« Reply #3 on: March 13, 2020, 01:14:12 PM »
gizzygizmo,
  I got all excited when I saw this, but i can't get it to work for me. Something is missing and I just get no output from the <span id="actual_preOG"></span> and other references to ids. I even tried a simple var water = "$TOTAL_WATER" in the header and then later <span id="water"></span> in the body (i.e. no use of the functions at all) and it still didn't work. Can  you post your entire custom report so can I try to figure out what I am missing?

Also, what version of BeerSmith are you using?

--GF

Update - after hours of experimenting I have something working. I had to organize things very differently from you to get it to work, but just knowing that script could be used gave me enough motivation to persist.
« Last Edit: March 14, 2020, 09:42:41 AM by GigaFemto »