Page 1 of 1

Cloud base Graph

Posted: Sat 14 Feb 2015 5:26 am
by K8POS
Not sure if I should direct this one to Steve or Mark.
I am using the SS Gauges in my web pages, when you hover over the cloud base gauge, a graph pops up giving the cloud base, but the scale shows Pressure, not feet/meters.
Also notice that this graph is not shown in the trends page of graphs.

Bob

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 8:53 am
by water01
Quite correct. That is what it shows. And there is no trends graph for Cloud base.

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 9:26 am
by mcrossley
Correct, no cloud base graph in Cumulus, so you can either remove the graph altogether, or create your own as I have with jpgraphs in PHP, but that does require you to log your real time data.

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 9:27 am
by laulau

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 10:22 am
by water01
Laurent is this produced as part of Mark's JSON MX Graphs because I cannot see it in the source files, or did you produce it using Mark's code as a base?

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 10:33 am
by laulau
mcrossley wrote:
laulau wrote:Hi Mark,
I guess it's possible to get the data to feed jpgraphs with realtimeLogSql.php script ?
Guess how I do mine :lol: I don't have MX uploading the json files, just my tag files, so yes I just query my real time MySQL table.
It's based on Mark's code but the data are extracted from my SQL table !

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 11:46 am
by water01
Care to share?

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 11:49 am
by mcrossley
Image

All my 'mx' graphs come from a MySQL dB too, I had to adapt the MySQL code to use the MX JSON files. The only real change is in graphSettings.php to the get_data() function to query the dB rather than reformat the MX JSON data.

You can then create whatever graph you want - I also separate out the UV from Solar.

Image

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 12:55 pm
by laulau
graphSettings.php (modifs) :

.......................

Code: Select all

function reorg_data1($dat) {
	$keyname = array(
		"press" => "Pressure",
		"rfall" => "Rain today",
		"rrate" => "Rain rate",
		"hum" => "Outdoor humidity",
		"inhum" => "Indoor humidity",
		"temp" => "Temperature",
		"intemp" => "Indoor",
		"dew" => "Dew point",
		"apptemp" => "Apparent temp",
		"wchill" => "Wind chill",
		"bearing" => "Direction",
		"avgbearing" => "Average direction",
		"wspeed" => "Wind speed",
		"wgust" => "Wind gust",
		"cloudbasevalue" => "Cloudbase",
		);	
	$keys = array_keys($dat);
	$retVal = array();
	
 
    for ($i = 0; $i < count($keys); $i++) {
        
		$key = $keys[$i];
		
        for ($j = 0; $j < count($dat[$key]); $j++) {
            if ($i === 0) {
                // JavaScript time in msecs, convert to secs
                $retVal['time'][] = $dat[$key][$j][0] / 1000;
            }
            $retVal[$keyname[$key]][] = $dat[$key][$j][1];
        }
    }
	
    return $retVal;	
}

function get_data($type) {
    global $GRAPH;

    // get the units
    $units = json_decode(file_get_contents($GRAPH['jsonloc'] . 'units.json'), true);

    // get the data
	// realtimeLogSql.php?recordAge=24&recordUnit=hour&nth=5&rfall
	// http://www.laurentmey.fr/test/mx-jpgraphs/graphTempOut.php
    switch ($type) {
    case 'temp':
        //$data = reorg_data(json_decode(file_get_contents($GRAPH['jsonloc'] . 'tempdatad3.json'), true));
		$data = reorg_data1(json_decode(file_get_contents('http://$path/realtimeLogSql.php?recordAge=24&recordUnit=hour&nth=10&temp&intemp&dew&apptemp&wchill'), true));
        $data['units'] = $units['temp'];
        break;
.....case ETC....
realtimeLogSql.php based on Mark's code ;) :

Code: Select all

<?php
//-----------------------------------------------------------------
// Query a Cumulus realtime MySQL table and return the requested fields
// along with the time stamps in a JSON format suitable for use with
// the Highcharts graphing package.
// Author: Mark Crossley
//
// Version 0.2 - 18 Dec 2012
//
// Call this script as e.g. ...
//         realtimeLogSql.php?recordAge=NNN&recordUnit=XXX&nth=NNN&temp&press
//         realtimeLogSql.php?recordAge=6&recordUnit=hour&nth=5&temp&press
//  Where:
//    recordAge=NNN
//		Returns records newer than NNN recordUnits, 6 hours in this example
//    recordUnit=XXX
//		The units to use for recordAge (second,minute,hour,day,week,month,quarter,year)
//    nth=NNN [OPTIONAL parameter]
//		If supplied the script will only return every n'th row from the realtime table, otherwise all
//      rows within the time range are returned. Useful for reducing large data sets for presentation.
//      This example will return every 5th row from the table
//    &temp&press
//		Returns the temperature and pressure data - concatenate as many record types as you wish.
//
//  The data arrays are returned in an object with the key name equal to
//  the param name supplied in the URL. In the example above the returned
//  object will be: {"temp": [[t0,v0],[t1,v1],...],
//                   "press": [[t0,v0],[t1,v1],...]}
//-----------------------------------------------------------------

// EDIT THIS NEXT SECTION CAREFULLY
// ----------------------------------------------------------------
// The server host name or number running your MySQL database
// usually 127.0.0.1 or localhost will suffice
$dbhost = ' ';
//
// The username used to log-in to your database server
$dbuser = ' ';
//
// The password used to log-in to your database server
$dbpassword = ' ';
//
// The name of the MySQL database we will store the tables in
$database = ' ';
//
// A better way of entering your login details is to put them in a separate script
// and include this here. This script should be placed in an area accessible to PHP
// but not web users. Your login details will not then beexposed by crashing this
// script.
// e.g. ...
include ('../forbidden/db_ro_details.php');

// The name of your realtime log table
$logtable = 'Realtime';

//-----------------------------------------------------------------

// Acceptable recordUnit parameter values
$validunits = array('second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year');

// Columns of realtime log table
// Use the same names as the corresponding web tags
$rfields = array(
    'datetime','temp','hum','dew','wspeed','wlatest','bearing',
    'rrate','rfall','press','currentwdir','beaufortnumber',
    'windunit','tempunitnodeg','pressunit','rainunit',
    'windrun','presstrendval','rmonth','ryear','rfallY','intemp','inhum','wchill',
    'temptrend','tempTH','TtempTH','tempTL','TtempTL',
    'windTM','TwindTM','wgustTM','TwgustTM',
    'pressTH','TpressTH','pressTL','TpressTL',
    'version','build','wgust','heatindex','humidex','UV','ET','SolarRad',
    'avgbearing','rhour', 'forecastnumber', 'isdaylight', 'SensorContactLost',
    'wdir','cloudbasevalue','cloudbaseunit','apptemp','SunshineHours','CurrentSolarMax','IsSunny');



// ============= Start it off... ============


// check parameters (just presence, no value checking)
if (array_key_exists('recordAge', $_GET)) {
	$recordAge = $_GET['recordAge'];
} else {
	die('You must supply a "recordAge" parameter');
}

if (array_key_exists('recordUnit', $_GET)) {
	$recordUnit = strtolower($_GET['recordUnit']);
	if (!in_array($recordUnit, $validunits)) {
		die("invalid 'recordUnit' supplied - '$recordUnit'");
	}
} else {
		die('You must supply a "recordVal" parameter');
}

if (array_key_exists('nth', $_GET)) {
	$nth = $_GET['nth'];
} else {
	$nth = '';
}

// Process the script value arguments
$dataTypes = array();
foreach($_GET as $key => $value) {
    if (in_array($key, $rfields)) {
        $dataTypes[] = $key;
    }
}

// Did we get any valid parameters?
if (count($dataTypes) == 0) {
    die('No valid return data types supplied');
}

// Connect to the datbase
$con = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$con) {
	die('Failed to connect to the database server');
}

if (!mysql_select_db($database, $con)) {
	die('Failed to connect to the database on the server');
}

$result = mysql_query('SET time_zone="+0:00"');
if (!$result) {
	die('ERROR - TZ Statement');
}

// Was the 'nth' parameter supplied? If not, do a standard query, else, only return every nth row from the table
if ($nth === '') {

	// Start of query string, then...
	$query = 'SELECT UNIX_TIMESTAMP(LogDateTime)';

	// add query data columns, then..
	foreach($dataTypes as $key) {
		$query .= ', ' . $key;
	}

	// end of query string.
	$query .= " FROM $logtable WHERE LogDateTime > DATE_SUB(NOW(), INTERVAL $recordAge $recordUnit) ORDER BY LogDateTime ASC";

} else {  // Only return every nth row

	// Start of query string, then...
	$query = 'SELECT ts';

	// add query data columns, then..
	foreach($dataTypes as $key) {
		$query .= ', ' . $key;
	}
	$query .= ' FROM ( SELECT @row := @row +1 AS rownum, UNIX_TIMESTAMP(LogDateTime) AS ts';

	// add query data columns, then..
	foreach($dataTypes as $key) {
		$query .= ', ' . $key;
	}
	// end of query string.
	$query .= " FROM $logtable WHERE LogDateTime > DATE_SUB(NOW(), INTERVAL $recordAge $recordUnit) ORDER BY LogDateTime ASC) as DT WHERE MOD(rownum,$nth)=0";

	// initialise the row counter
	$result = mysql_query('SET @row := 0;');
	if (!$result) {
		die("ERROR - Bad SQL Statement: $query");
	}
}

// Perform query
$result = mysql_query($query);
if (!$result) {
	die("ERROR - Bad Select Statement: $query");
}

// for each of the returned rows, put the data into a series of arrays...
while($row = mysql_fetch_row($result)) {
	$tim = $row[0] * 1000;
	$i = 1;
	foreach($dataTypes as $key) {
        ${"arr_$key"}[]  = array($tim, (float)$row[$i++]);
    }
}

// build the return array
foreach($dataTypes as $key) {
    $return[$key] = ${'arr_' . $key};
}

header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: text/json  charset=UTF-8');

// encode the result and echo it back to the client
echo json_encode($return);

// ========== End of Module ===========
?>

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 5:13 pm
by K8POS
Just when I thought it was going to be easy! :bash:

Re: Cloud base Graph

Posted: Sat 14 Feb 2015 5:21 pm
by mcrossley
I'll post a SQL version in the MX forum soon...

Re: Cloud base Graph

Posted: Mon 16 Feb 2015 10:25 am
by OliII
Hi ! I'll be interessed too for these graphs. But, i don't have access to the mxforum. Could you post these here ?
Thx.