Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.

Mon, 25 Feb 2019 22:49:22 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 25 Feb 2019 22:49:22 +0100
changeset 294
1e09d1d102a8
parent 293
db898ec73277
child 295
cbace196bdbf

Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.

README.design file | annotate | diff | comparison | revisions
www/Makefile file | annotate | diff | comparison | revisions
www/crontasks.php file | annotate | diff | comparison | revisions
www/getbrewlog.php file | annotate | diff | comparison | revisions
www/js/log_brew.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/log_brew.php file | annotate | diff | comparison | revisions
--- a/README.design	Mon Feb 25 17:29:35 2019 +0100
+++ b/README.design	Mon Feb 25 22:49:22 2019 +0100
@@ -142,7 +142,6 @@
 TODO:
 
 Copieren recepten tussen products en recipes, maar ook dupliceren. Import.
-Menu voor archive products.
 Cron uitbreiden met test op nieuw verschenen logfiles. Of nog slimmer, zet de
 logfile aan zodra een product in een gistkast geladen is.
 Download gist temperatuur grenzen naar thermferm zodat die opgevraagd kunnen
--- a/www/Makefile	Mon Feb 25 17:29:35 2019 +0100
+++ b/www/Makefile	Mon Feb 25 22:49:22 2019 +0100
@@ -8,7 +8,7 @@
 		  getfermenter.php getfermentlog.php gethopsources.php getmiscsources.php \
 		  getnode.php getwatersources.php getyeastsources.php index.php \
 		  inv_equipments.php inv_fermentables.php inv_hops.php inv_instock.php \
-		  inv_miscs.php inv_suppliers.php inv_waters.php inv_yeasts.php \
+		  inv_miscs.php inv_suppliers.php inv_waters.php inv_yeasts.php log_brew.php \
 		  log_fermentation.php mon_brewer.php mon_fermenter.php mon_node.php \
 		  prod_archive_code.php prod_archive_date.php prod_archive_name.php \
 		  prod_edit.php prod_export.php prod_inprod.php prod_new.php prod_print.php \
--- a/www/crontasks.php	Mon Feb 25 17:29:35 2019 +0100
+++ b/www/crontasks.php	Mon Feb 25 22:49:22 2019 +0100
@@ -2,13 +2,50 @@
 
 require_once('config.php');
 
-$mysqli = new mysqli(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
+$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
+$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
+
+$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $connect) {
+	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
+}
+mysqli_set_charset($connect, "utf8" );
+syslog(LOG_NOTICE, "crontasks.php started");
+
 $query = "UPDATE products SET stage=7 WHERE stage = 6 AND DATEDIFF(CURDATE(), package_date) > 0";
-$result = $mysqli->query($query);
+$result = mysqli_query($connect, $query);
+$changed = mysqli_affected_rows($connect);
+if ($changed > 0) {
+	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 7");
+}
 
 $query = "UPDATE products SET stage=8 WHERE stage = 7 AND DATEDIFF(CURDATE(), package_date) > 13";
-$result = $mysqli->query($query);
+$result = mysqli_query($connect, $query);
+$changed = mysqli_affected_rows($connect);
+if ($changed > 0) {
+	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 8");
+}
 
 $query = "UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41";
-$result = $mysqli->query($query);
+$result = mysqli_query($connect, $query);
+$changed = mysqli_affected_rows($connect);
+if ($changed > 0) {
+	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 9");
+}
+
 
+$query = "SELECT record,code,name,log_brew,log_fermentation FROM products;";
+$result = mysqli_query($connect, $query);
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+	$logfile = "log/fermentation/" . $row['code'] . " " . $row['name'] . ".log";
+	if (file_exists($logfile))
+		$ok = 1;
+	else
+		$ok = 0;
+	if ($ok != $row['log_fermentation']) {
+		$query = "UPDATE products SET log_fermentation='" . $ok . "' WHERE record='" . $row['record'] . "';";
+		syslog(LOG_NOTICE, $query);
+		$result1 = mysqli_query($connect, $query);
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/getbrewlog.php	Mon Feb 25 22:49:22 2019 +0100
@@ -0,0 +1,36 @@
+<?php
+
+require_once('config.php');
+
+if (isset($_GET["code"]))
+	$code = $_GET["code"];
+else
+	$code = "CB0011";
+
+$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
+if (! $connect) {
+	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
+}
+mysqli_set_charset($connect, "utf8" );
+
+$query = "SELECT * FROM log_brews WHERE product_code='".$code."' ORDER BY datetime;";
+$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
+while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+	$lines[] = array(
+		'record' => $row['record'],
+		'date' => substr($row['datetime'],0,16),
+		'version' => $row['version'],
+		'code' => $row['product_code'],
+		'name' => $row['product_name'],
+		'pv_mlt' => $row['temperature_mlt'],
+		'pv_bk' => $row['temperature_bk'],
+		'pv_hlt' => $row['temperature_hlt'],
+		'pv_room' => $row['temperature_room'],
+		'sp_mlt' => $row['setpoint_mlt'],
+		'sp_bk' => $row['setpoint_bk'],
+		'sp_hlt' => $row['setpoint_hlt'],
+		'event' => $row['event']
+	);
+}
+
+echo json_encode($lines);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/js/log_brew.js	Mon Feb 25 22:49:22 2019 +0100
@@ -0,0 +1,142 @@
+/*****************************************************************************
+ * Copyright (C) 2019
+ *
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of BMS
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * Brewery Managment System  is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+
+$(document).ready(function () {
+
+	$("#jqxLoader").jqxLoader({
+		width: 250,
+		height: 150,
+		isModal: true,
+		text: "Opmaken grafiek ...",
+		theme: theme
+	});
+	$('#jqxLoader').jqxLoader('open');
+
+	function getExportServer() {
+		return "https://www.jqwidgets.com/export_server/export.php";
+	}
+
+	var sourceA = {
+		datatype: "json",
+		datafields: [
+			{ name: "date", type: "date", format: "yyyy-MM-dd HH:mm" },
+			{ name: "version", type: "int" },
+			{ name: "code", type: "string" },
+			{ name: "name", type: "string" },
+			{ name: "pv_mlt", type: "float" },
+			{ name: "pv_bk", type: "float" },
+			{ name: "pv_hlt", type: "float" },
+			{ name: "pv_room", type: "float" },
+			{ name: "sp_mlt", type: "float" },
+			{ name: "sp_bk", type: "float" },
+			{ name: "sp_hlt", type: "float" },
+			{ name: "event", type: "string" }
+		],
+		url: 'getbrewlog.php?code=' + my_code
+	};
+	var dataAdapter = new $.jqx.dataAdapter(sourceA, {
+		autoBind: true,
+		async: false,
+		loadComplete: function () {
+			$('#jqxLoader').jqxLoader('close');
+		},
+		loadError: function (jqXHR, status, error) {
+		}
+	});
+
+	var settings = {
+		 title: my_code + ' "' + my_name + '"',
+		 description: "",
+		 source: dataAdapter,
+		 xAxis: {
+			dataField: 'date',
+			type: 'date',
+			formatFunction: function (value) {
+				return value.getHours() + ':' + value.getMinutes();
+			},
+			toolTipFormatFunction: function (value) {
+				var h = value.getHours();
+				var m = value.getMinutes();
+				return value.getDate() + '-' + (value.getMonth() + 1) + '-' + value.getFullYear()
+					 + ' ' + (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m);
+			},
+			textRotationAngle: 300,
+		 },
+		 colorScheme: 'scheme01',
+		 seriesGroups: [
+			{
+				type: 'spline',
+				valueAxis: {
+					minValue: 0,
+					description: 'Graden C'
+				},
+				series: [
+					{ dataField: "pv_mlt", lineWidth: 2, displayText: "MLT" },
+					{ dataField: "sp_mlt", lineWidth: 1, displayText: "mlt", opacity: 0.7 },
+					{ dataField: "pv_bk", lineWidth: 2, displayText: "BK" },
+					{ dataField: "sp_bk", lineWidth: 1, displayText: "bk", opacity: 0.7 },
+					{ dataField: "pv_hlt", lineWidth: 1, displayText: "HLT" },
+					{ dataField: "sp_hlt", lineWidth: 1, displayText: "hlt", opacity: 0.7 },
+					{ dataField: "pv_room", lineWidth: 1, displayText: "Room", opacity: 0.5 }
+				]
+			}
+		 ]
+	};
+	$("#brew_chart").jqxChart(settings);
+
+	$("#print").click(function () {
+		var content = $("#brew_chart")[0].outerHTML;
+		var newWindow = window.open("", "", "width=865, height=425"),
+		document = newWindow.document.open(),
+		pageContent =
+			'<!DOCTYPE html>' +
+			'<html>' +
+			'<head>' +
+			'<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />' +
+			'<meta charset="utf-8" />' +
+			'<title>jQWidgets Chart</title>' +
+			'</head>' +
+			'<body>' + content + '</body></html>';
+		document.write(pageContent);
+		document.close();
+		newWindow.print();
+	});
+	$("#print").jqxButton({ template: "primary", width: 125, theme: theme });
+
+
+	$("#pdfButton").click(function () {
+		$("#brew_chart").jqxChart("saveAsPDF", "brouw_"+my_code+".pdf", getExportServer());
+	});
+	$("#pdfButton").jqxButton({ template: "primary", width: 125, theme: theme });
+
+	$("#pngButton").click(function () {
+		$("#brew_chart").jqxChart("saveAsPNG", "brouw_"+my_code+".png", getExportServer());
+	});
+	$("#pngButton").jqxButton({ template: "primary", width: 125, theme: theme });
+
+	$("#Close").jqxButton({ template: "success", width: 125, theme: theme });
+	$("#Close").click(function () {
+		window.close();
+	});
+});
+
--- a/www/js/prod_edit.js	Mon Feb 25 17:29:35 2019 +0100
+++ b/www/js/prod_edit.js	Mon Feb 25 22:49:22 2019 +0100
@@ -5173,7 +5173,7 @@
 	$("#BLog").jqxButton({ template: "info", width: '150px', theme: theme });
 	$("#BLog").click(function () {
 		// Open log in a new tab.
-		var url="log_brew.php?code=" + dataRecord.code;
+		var url="log_brew.php?code=" + dataRecord.code + "&name=" + dataRecord.name;
 		window.open(url);
 	});
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/log_brew.php	Mon Feb 25 22:49:22 2019 +0100
@@ -0,0 +1,19 @@
+<?php
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
+page_header('Brouw sessie grafiek', "log_brew");
+?>
+
+   <div id="MainPanel">
+    <div id="ContentPanel"></div>
+    <div id="brew_chart" style="width:1130px; height:610px; float:left; margin-left: 10px; margin-top: 10px;"></div>
+    <div style="margin-top: 10px; margin-left: 10px;">
+     <input style="float: left; margin-left: 10px;" id="print" type="button" value="Print grafiek" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="pdfButton" type="button" value="Maak PDF" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="pngButton" type="button" value="Maak PNG" />
+     <input style="float: left; margin-left: 10px; margin-top: 10px;" id="Close" type="button" value="Sluiten" />
+    </div>
+   </div>
+
+<?php
+page_footer();
+?>

mercurial