Added ARCHIVE LOG view.

Thu, 02 Apr 2015 22:08:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 02 Apr 2015 22:08:15 +0200
changeset 357
64cd9865bd11
parent 356
44bcfe087f9e
child 358
8b7ef338bf49

Added ARCHIVE LOG view.

www-thermferm/archives.php file | annotate | diff | comparison | revisions
www-thermferm/getalog.php file | annotate | diff | comparison | revisions
--- a/www-thermferm/archives.php	Thu Apr 02 21:53:28 2015 +0200
+++ b/www-thermferm/archives.php	Thu Apr 02 22:08:15 2015 +0200
@@ -22,6 +22,7 @@
  *****************************************************************************/
 
 require_once('utilities.php');
+$my_style = 'ui-redmond';
 
 if (isset($_GET['action'])) {
     switch ($_GET['action']) {
@@ -41,6 +42,183 @@
  *
  */
 
+/*
+ * View an archived file in graph format
+ */
+function archive_view() {
+
+    global	$my_style;
+
+    $name = urldecode($_GET['name']);
+
+    $answer = send_cmd('GLOBAL GET');
+    $arr = explode("\r\n", $answer);
+    $version = "?";
+
+    if (startsWith($arr[0], "213")) {
+	$j = 1;
+	while (1) {
+	    if (strcmp($arr[$j], ".") == 0)
+		break;
+	    $f = explode(",", $arr[$j]);
+
+	    if ($f[0] == "RELEASE")
+		$version = $f[1];
+	    $j++;
+	}
+    }
+
+    $outstr  = '<!DOCTYPE html>'.PHP_EOL;
+    $outstr .= '<html>'.PHP_EOL;
+    $outstr .= ' <head>'.PHP_EOL;
+    $outstr .= '  <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.PHP_EOL;
+    $outstr .= '  <title>Archive View '.$name.'</title>'.PHP_EOL;
+    $outstr .= '  <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />'.PHP_EOL;
+    $outstr .= '  <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" />'.PHP_EOL;
+    $outstr .= '  <link type="text/css" href="jqwidgets/styles/jqx.'.$my_style.'.css" rel="stylesheet" />'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxwindow.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxchart.core.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxdraw.js"></script>'.PHP_EOL;
+    $outstr .= '  <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>'.PHP_EOL;
+    $outstr .= ' </head>'.PHP_EOL;
+
+    $outstr .= ' <body class="default">'.PHP_EOL;
+    $outstr .= '  <div id="jqxWidget">'.PHP_EOL;
+    $outstr .= '   <div id="header">'.PHP_EOL;
+    $outstr .= '    <div id="title">'.PHP_EOL;
+    $outstr .= '     ThermFerm '.$version.PHP_EOL;
+    $outstr .= '    </div>'.PHP_EOL;
+    $outstr .= '    <form action="archives.php" style="margin:30px; float:right">'.PHP_EOL;
+    $outstr .= '     <input type="submit" id="archives" value="Archives directory" />'.PHP_EOL;
+    $outstr .= '    </form>'.PHP_EOL;
+    $outstr .= '   </div> <!-- header -->'.PHP_EOL;
+    $outstr .= '   <div id="content">'.PHP_EOL;
+
+    $outstr .= '    <script type="text/javascript">'.PHP_EOL;
+    $outstr .= '     $(document).ready(function () {'.PHP_EOL;
+
+    $outstr .= '       function getExportServer() {'.PHP_EOL;
+    $outstr .= '         return "http://www.jqwidgets.com/export_server/export.php";'.PHP_EOL;
+    $outstr .= '       }'.PHP_EOL;
+
+    $outstr .= '       var sourceA ='.PHP_EOL;
+    $outstr .= '       {'.PHP_EOL;
+    $outstr .= '          datatype: "json",'.PHP_EOL;
+    $outstr .= '          datafields: ['.PHP_EOL;
+    $outstr .= '             { name: "Date", type: "date", format: "yyyy-MM-ddTHH:mm" },'.PHP_EOL;
+    $outstr .= '             { name: "Mode" },'.PHP_EOL;
+    $outstr .= '             { name: "Air", type: "float" },'.PHP_EOL;
+    $outstr .= '             { name: "Beer", type: "float" },'.PHP_EOL;
+    $outstr .= '             { name: "Target", type: "float" },'.PHP_EOL;
+    $outstr .= '             { name: "Heater", type: "int" },'.PHP_EOL;
+    $outstr .= '             { name: "Cooler", type: "int" },'.PHP_EOL;
+    $outstr .= '             { name: "HeatUse", type: "int" },'.PHP_EOL;
+    $outstr .= '             { name: "CoolUse", type: "int" },'.PHP_EOL;
+    $outstr .= '             { name: "Room", type: "float" }'.PHP_EOL;
+    $outstr .= '          ],'.PHP_EOL;
+    $outstr .= '          url: \'getalog.php?name='.urlencode($name).'\''.PHP_EOL;
+    $outstr .= '       };'.PHP_EOL;
+
+    $outstr .= '       var dataAdapter = new $.jqx.dataAdapter(sourceA,'.PHP_EOL;
+    $outstr .= '       {'.PHP_EOL;
+    $outstr .= '          autoBind: true,'.PHP_EOL;
+    $outstr .= '          async: false,'.PHP_EOL;
+    $outstr .= '          downloadComplete: function () { },'.PHP_EOL;
+    $outstr .= '          loadComplete: function () { },'.PHP_EOL;
+    $outstr .= '          loadError: function () { }'.PHP_EOL;
+    $outstr .= '       });'.PHP_EOL;
+
+    $outstr .= '       var settings = {'.PHP_EOL;
+    $outstr .= '         title: "'.$name.'",'.PHP_EOL;
+    $outstr .= '         description: "",'.PHP_EOL;
+    $outstr .= '         padding: { left: 5, top: 5, right: 5, bottom: 5 },'.PHP_EOL;
+    $outstr .= '         titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },'.PHP_EOL;
+    $outstr .= '         source: dataAdapter,'.PHP_EOL;
+    $outstr .= '         categoryAxis:'.PHP_EOL;
+    $outstr .= '           {'.PHP_EOL;
+    $outstr .= '             dataField: \'Date\','.PHP_EOL;
+    $outstr .= '             textRotationAngle: 45,'.PHP_EOL;
+    $outstr .= '             showGridLines: false'.PHP_EOL;
+    $outstr .= '           },'.PHP_EOL;
+    $outstr .= '         colorScheme: \'scheme01\','.PHP_EOL;
+    $outstr .= '         seriesGroups:'.PHP_EOL;
+    $outstr .= '           [{'.PHP_EOL;
+    $outstr .= '             type: "line",'.PHP_EOL;
+    $outstr .= '             valueAxis:'.PHP_EOL;
+    $outstr .= '             {'.PHP_EOL;
+    $outstr .= '               minValue: 0,'.PHP_EOL;
+    $outstr .= '               maxValue: 100,'.PHP_EOL;
+    $outstr .= '               displayValueAxis: false,'.PHP_EOL;
+    $outstr .= '               description: "Heat/Cool %"'.PHP_EOL;
+    $outstr .= '             },'.PHP_EOL;
+    $outstr .= '             series: ['.PHP_EOL;
+    $outstr .= '               { dataField: "CoolUse", lineWidth: 1, displayText: "Cool %", opacity: 0.5 },'.PHP_EOL;
+    $outstr .= '               { dataField: "HeatUse", lineWidth: 1, displayText: "Heat %", opacity: 0.5 }'.PHP_EOL;
+    $outstr .= '             ]'.PHP_EOL;
+    $outstr .= '            },'.PHP_EOL;
+    $outstr .= '            {'.PHP_EOL;
+    $outstr .= '             type: \'spline\','.PHP_EOL;
+    $outstr .= '             valueAxis:'.PHP_EOL;
+    $outstr .= '             {'.PHP_EOL;
+    $outstr .= '               minValue: 0,'.PHP_EOL;
+    $outstr .= '               description: \'Degrees C\''.PHP_EOL;
+    $outstr .= '             },'.PHP_EOL;
+    $outstr .= '             series: ['.PHP_EOL;
+    $outstr .= '               { dataField: "Air", lineWidth: 1, displayText: "Air" },'.PHP_EOL;
+    $outstr .= '               { dataField: "Beer", lineWidth: 2, displayText: "Beer" },'.PHP_EOL;
+    $outstr .= '               { dataField: "Target", lineWidth: 1, displayText: "Target", opacity: 0.7 },'.PHP_EOL;
+    $outstr .= '               { dataField: "Room", lineWidth: 1, displayText: "Room", opacity: 0.5 }'.PHP_EOL;
+    $outstr .= '             ]'.PHP_EOL;
+    $outstr .= '           }]'.PHP_EOL;
+    $outstr .= '       };'.PHP_EOL;
+    /* Direct draw for the first time */
+    $outstr .= '       $("#fermentor_chart").jqxChart(settings);'.PHP_EOL;
+
+    $outstr .= '       $("#print").click(function () {'.PHP_EOL;
+    $outstr .= '         var content = $("#fermentor_chart")[0].outerHTML;'.PHP_EOL;
+    $outstr .= '         var newWindow = window.open("", "", "width=750, height=400"),'.PHP_EOL;
+    $outstr .= '         document = newWindow.document.open(),'.PHP_EOL;
+    $outstr .= '         pageContent ='.PHP_EOL;
+    $outstr .= '         \'<!DOCTYPE html>\' +'.PHP_EOL;
+    $outstr .= '         \'<html>\' +'.PHP_EOL;
+    $outstr .= '         \'<head>\' +'.PHP_EOL;
+    $outstr .= '         \'<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />\' +'.PHP_EOL;
+    $outstr .= '         \'<meta charset="utf-8" />\' +'.PHP_EOL;
+    $outstr .= '         \'<title>jQWidgets Chart</title>\' +'.PHP_EOL;
+    $outstr .= '         \'</head>\' +'.PHP_EOL;
+    $outstr .= '         \'<body>\' + content + \'</body></html>\';'.PHP_EOL;
+    $outstr .= '         document.write(pageContent);'.PHP_EOL;
+    $outstr .= '         document.close();'.PHP_EOL;
+    $outstr .= '         newWindow.print();'.PHP_EOL;
+    $outstr .= '       });'.PHP_EOL;
+    $outstr .= '       $("#print").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL;
+
+    $outstr .= '       $("#pngButton").click(function () {'.PHP_EOL;
+    $outstr .= '            $("#fermentor_chart").jqxChart("saveAsPNG", "Chart_'.$name.'.png", getExportServer());'.PHP_EOL;
+    $outstr .= '       });'.PHP_EOL;
+    $outstr .= '       $("#pngButton").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL;
+
+    $outstr .= '     });'.PHP_EOL;
+    $outstr .= '    </script>'.PHP_EOL;
+    $outstr .= '    <div id="fermentor">'.PHP_EOL;
+    $outstr .= '     <div id="fermentor_chart" style="width:720px; height:377px; float:left"></div>'.PHP_EOL;
+    $outstr .= '     <div style="margin-top: 2px; margin-left: 10px;">'.PHP_EOL;
+    $outstr .= '      <input style="float: left; margin-left: 15px;" id="print" type="button" value="Print Graph" />'.PHP_EOL;
+    $outstr .= '      <input style="float: left; margin-left: 15px;" id="pngButton" type="button" value="Save Graph" />'.PHP_EOL;
+    $outstr .= '     </div>'.PHP_EOL;
+    $outstr .= '    </div> <!-- fermentor -->'.PHP_EOL;
+
+    $outstr .= '    <script type="text/javascript">'.PHP_EOL;
+    $outstr .= '     $(document).ready(function () {'.PHP_EOL;
+    $outstr .= '      $("#archives").jqxButton({ width: 150, height: 25, theme: \'ui-redmond\' });'.PHP_EOL;
+    $outstr .= '     });'.PHP_EOL;
+    $outstr .= '    </script>'.PHP_EOL;
+    $outstr .= build_footer();
+    echo $outstr;
+}
 
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www-thermferm/getalog.php	Thu Apr 02 22:08:15 2015 +0200
@@ -0,0 +1,53 @@
+<?php
+/*****************************************************************************
+ * Copyright (C) 2015
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of ThermFerm
+ *
+ * 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.
+ *
+ * ThermFerm 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.
+ *****************************************************************************/
+
+require_once('utilities.php');
+
+
+$answer = send_cmd("ARCHIVE LOG ".$_GET["name"]);
+$arr = explode("\r\n", $answer);
+
+
+$row = '[';
+
+/* We don't use json_encode because it doesn't work for our purpose */
+if (startsWith($arr[0], "212")) {
+    $j = 1;
+    while (1) {
+	if (strcmp($arr[$j], ".") == 0)
+		break;
+	if ($j > 1)
+	    $row .= ',';
+	$f = explode(",", $arr[$j]);
+	$heater   = $f[5] / 100;
+	$cooler   = $f[6] / 100;
+	$row .= '{"Date":"'.$f[0].'","Mode":"'.$f[1].'","Air":"'.$f[2].'","Beer":"'.$f[3].'","Target":"'.$f[4].'",';
+        $row .= '"Heater":'.$heater.',"Cooler":'.$cooler.',"HeatUse":'.$f[7].',"CoolUse":"'.$f[8].'","Room":"'.$f[9].'"}';
+	$j++;
+    }
+}
+
+$row .= ']';
+echo $row;
+
+?>

mercurial