# HG changeset patch # User Michiel Broek # Date 1546861587 -3600 # Node ID 8adaeecd9dc8a9177bcebeb94ae20e448bda9daf # Parent dbb74e0b8067a2ff140371c09e93523d66049725 Fixed the fermentation chart to be just like the thermferm chart. diff -r dbb74e0b8067 -r 8adaeecd9dc8 www/getfermentlog.php --- a/www/getfermentlog.php Sun Jan 06 23:30:53 2019 +0100 +++ b/www/getfermentlog.php Mon Jan 07 12:46:27 2019 +0100 @@ -5,26 +5,55 @@ if (isset($_GET["code"])) $code = $_GET["code"]; else - $code = "CB0068"; + $code = "TB0015"; -$query = "SELECT datetime,temperature_air,temperature_beer,temperature_chiller,temperature_room,target_low,target_high,heater_power,cooler_power FROM log_fermentation WHERE product_code='".$code."'"; +$query = "SELECT datetime,temperature_air,temperature_beer,temperature_chiller,temperature_room,target_low,target_high,heater_usage,cooler_usage FROM log_fermentation WHERE product_code='".$code."'"; $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); if (! $connect) { echo "[]"; return; } +$step = 600; // Must be a multiple of 300 +$ld = 0; +$lh = 0; +$ch = 0; +$lc = 0; +$cc = 0; $result = mysqli_query($connect, $query); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { - $logs[] = array( - 'date' => $row['datetime'], - 'air' => $row['temperature_air'], - 'beer' => $row['temperature_beer'], - 'chiller' => $row['temperature_chiller'], - 'room' => $row['temperature_room'], - 'tlo' => $row['target_low'], - 'thi' => $row['target_high'], - 'heater' => $row['heater_power'], - 'cooler' => $row['cooler_power'] - ); + + $dt = new DateTime($row['datetime'], new DateTimeZone('Europe/Amsterdam')); + $ts = $dt->getTimestamp(); + $diff = $ts - $ld; + + if ($diff < $step) { + // Read on + } else if ($diff > $step) { + // Reset, out of sync. + $ld = $ts; + $lh = $ch = $row['heater_usage']; + $lc = $cc = $row['cooler_usage']; + } else { + // This is a valid timeframe. + $ch = $row['heater_usage']; + $cc = $row['cooler_usage']; + $heat = round(($ch - $lh) / ($step / 100)); + $cool = round(($cc - $lc) / ($step / 100)); +// echo $heat . ' ' . $cool . PHP_EOL; + $logs[] = array( + 'date' => $row['datetime'], + 'air' => $row['temperature_air'], + 'beer' => $row['temperature_beer'], + 'chiller' => $row['temperature_chiller'], + 'room' => $row['temperature_room'], + 'tlo' => $row['target_low'], + 'thi' => $row['target_high'], + 'heater' => $heat, + 'cooler' => $cool + ); + $ld = $ts; + $lh = $ch; + $lc = $cc; + } } echo json_encode($logs); diff -r dbb74e0b8067 -r 8adaeecd9dc8 www/js/log_fermentation.js --- a/www/js/log_fermentation.js Sun Jan 06 23:30:53 2019 +0100 +++ b/www/js/log_fermentation.js Mon Jan 07 12:46:27 2019 +0100 @@ -89,7 +89,7 @@ colorScheme: 'scheme01', seriesGroups: [ { - type: "line", + type: "spline", valueAxis: { minValue: 0, maxValue: 100,