Tue, 31 Aug 2021 20:48:37 +0200
Split batch, adjust mash step volume. In the duplicated log_brew handle the missing values. In save product, round the mash step sg to 4 decimals. In prod_edit, ingredients are stored as strings, not arrays. This triggered a memory corruption that only happened in rare circumstances. Don't fix mash step fields in the javascript, it is already done during load from the database. Calculation of the mash volume is rounded to 6 decimals. Enter mash step Brix/Plato value, the SG result is rounded to 4 decimals.
--- a/.hgignore Sat Aug 21 16:14:44 2021 +0200 +++ b/.hgignore Tue Aug 31 20:48:37 2021 +0200 @@ -17,5 +17,6 @@ *.o */filelist icons/* +bin/* www/log/* Makefile.bak
--- a/www/includes/db_divides.php Sat Aug 21 16:14:44 2021 +0200 +++ b/www/includes/db_divides.php Tue Aug 31 20:48:37 2021 +0200 @@ -354,6 +354,7 @@ $mashs = json_decode($row['json_mashs'], true); for ($i = 0; $i < count($mashs); $i++) { + $mashs[$i]['step_volume'] = sprintf("%.5f", $mashs[$i]['step_volume'] * $factor); $mashs[$i]['step_infuse_amount'] = sprintf("%.5f", $mashs[$i]['step_infuse_amount'] * $factor); } // syslog(LOG_NOTICE, "db_divide: " . str_replace($rescapers,$rreplacements,json_encode($mashs, JSON_UNESCAPED_UNICODE))); @@ -394,12 +395,16 @@ $sql3 .= "', code='" . mysqli_real_escape_string($link, $split['code']); $sql3 .= "', name='" . mysqli_real_escape_string($link, $split['name']); $sql3 .= "', pv_mlt='" . $row3['pv_mlt']; - $sql3 .= "', pv_hlt='" . $row3['pv_hlt']; - $sql3 .= "', pv_room='" . $row3['pv_room']; + if (strlen($row3['pv_hlt'])) + $sql3 .= "', pv_hlt='" . $row3['pv_hlt']; + if (strlen($row3['pv_room'])) + $sql3 .= "', pv_room='" . $row3['pv_room']; $sql3 .= "', sp_mlt='" . $row3['sp_mlt']; - $sql3 .= "', sp_hlt='" . $row3['sp_hlt']; + if (strlen($row3['sp_hlt'])) + $sql3 .= "', sp_hlt='" . $row3['sp_hlt']; $sql3 .= "', pwm_mlt='" . $row3['pwm_mlt']; - $sql3 .= "', pwm_hlt='" . $row3['pwm_hlt']; + if (strlen($row3['pwm_hlt'])) + $sql3 .= "', pwm_hlt='" . $row3['pwm_hlt']; $sql3 .= "', event='" . $row3['event'] . "';"; $result4 = mysqli_query($link, $sql3); if (! $result4) {
--- a/www/includes/db_product.php Sat Aug 21 16:14:44 2021 +0200 +++ b/www/includes/db_product.php Tue Aug 31 20:48:37 2021 +0200 @@ -501,7 +501,7 @@ else $mash .= ',"step_ph":0.0'; if (isset($item['step_sg']) && $item['step_sg'] != "") - $mash .= ',"step_sg":' . $item['step_sg']; + $mash .= ',"step_sg":' . sprintf("%.4f", $item['step_sg']); else $mash .= ',"step_sg":0.0'; $mash .= '}';
--- a/www/js/prod_edit.js Sat Aug 21 16:14:44 2021 +0200 +++ b/www/js/prod_edit.js Tue Aug 31 20:48:37 2021 +0200 @@ -512,11 +512,11 @@ { name: 'divide_factor', type: 'float' }, { name: 'divide_parts', type: 'int' }, { name: 'divide_part', type: 'int' }, - { name: 'fermentables', type: 'array' }, - { name: 'hops', type: 'array' }, - { name: 'miscs', type: 'array' }, - { name: 'yeasts', type: 'array' }, - { name: 'mashs', type: 'array' } + { name: 'fermentables', type: 'string' }, + { name: 'hops', type: 'string' }, + { name: 'miscs', type: 'string' }, + { name: 'yeasts', type: 'string' }, + { name: 'mashs', type: 'string' } ], id: 'record', url: url + '?record=' + my_record @@ -1666,19 +1666,8 @@ addrow: function(rowid, rowdata, position, commit) { commit(true); }, deleterow: function(rowid, commit) { commit(true); } }, - mashAdapter = new $.jqx.dataAdapter(mashSource, { - beforeLoadComplete: function(records) { - mash_infuse = 0; - var i, row, data = new Array(); - for (i = 0; i < records.length; i++) { - row = records[i]; - if (row.step_type == 0) // Infusion - mash_infuse += parseFloat(row.step_infuse_amount); - row.step_wg_ratio = 0; // Init this field. - data.push(row); - } - }, - }); + mashAdapter = new $.jqx.dataAdapter(mashSource); + $('#mashGrid').jqxGrid({ width: 1240, height: 400, @@ -1892,10 +1881,8 @@ function infusionVol(step_infused, step_mashkg, infuse_temp, step_temp, last_temp) { var a = last_temp * (dataRecord.eq_tun_weight * dataRecord.eq_tun_specific_heat + step_infused * SpecificHeatWater + step_mashkg * SpecificHeatMalt); var b = step_temp * (dataRecord.eq_tun_weight * dataRecord.eq_tun_specific_heat + step_infused * SpecificHeatWater + step_mashkg * SpecificHeatMalt); - //console.log('b - a: ' + (b - a) + ' t: ' + ((infuse_temp - step_temp) * SpecificHeatWater)); - //console.log('res: ' + ((b - a) / ((infuse_temp - step_temp) * SpecificHeatWater))); var vol = Round(((b - a) / ((infuse_temp - step_temp) * SpecificHeatWater)), 2); - console.log('infusionVol(' + step_infused + ', ' + step_mashkg + ', ' + infuse_temp + ', ' + step_temp + ', ' + last_temp + '): ' + vol); + //console.log('infusionVol(' + step_infused + ', ' + step_mashkg + ', ' + infuse_temp + ', ' + step_temp + ', ' + last_temp + '): ' + vol); return vol; } @@ -2303,9 +2290,9 @@ } else { // Calculate amount of infusion water. row.step_infuse_amount = infusionVol(infused, mashkg, row.step_infuse_temp, row.step_temp, lasttemp); - console.log('vol: ' + row.step_infuse_amount + ' temp: ' + row.step_infuse_temp); + //console.log('vol: ' + row.step_infuse_amount + ' temp: ' + row.step_infuse_temp); } - infused += row.step_infuse_amount; + infused += parseFloat(row.step_infuse_amount); } else if (row.step_type == 1) { // Temperature if (i > 0) row.step_infuse_amount = 0; @@ -2322,7 +2309,7 @@ $('#mashGrid').jqxGrid('updaterow', i, row); } } - mashvol = mashkg * MaltVolume + infused; + mashvol = Round(mashkg * MaltVolume + infused, 6); $('#est_mashvol').val(mashvol); h = Math.floor(mashtime / 60); m = Math.floor(mashtime - (h * 60)); @@ -5829,13 +5816,14 @@ $('#wstep_brix').jqxNumberInput(Spin1dec); $('#wstep_brix').on('change', function(event) { /* Use plato_to_sg at this stage */ - var sg = plato_to_sg(parseFloat(event.args.value)); + var sg = Round(plato_to_sg(parseFloat(event.args.value)), 4); console.log('brix: ' + parseFloat(event.args.value) + ' sg: ' + sg); - if (sg > 1.005) { - var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow); - rowdata.step_sg = sg; - $('#wstep_sg').val(sg); + var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow); + if (sg <= 1.005) { + sg = 0.0; } + rowdata.step_sg = sg; + $('#wstep_sg').val(sg); }); $('#wramp_time').on('change', function(event) { var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);