debug\ncode optimization
This commit is contained in:
29
class/db.php
29
class/db.php
@ -26,9 +26,9 @@ class db extends mysqli
|
||||
|
||||
function logProperty($device, $propertyTree, $value, $oldValue = 0)
|
||||
{
|
||||
global $mohaDB, $properties2log;
|
||||
global $mohaDB, $properties2log, $testMode;
|
||||
$precision = 0;
|
||||
echo "############## logProperty ################\nproperty => " . $propertyTree .EOL;
|
||||
//echo "############## logProperty ################\nproperty => " . $propertyTree .EOL;
|
||||
if (array_key_exists($propertyTree, $properties2log))
|
||||
{
|
||||
//echo "logging in database";
|
||||
@ -37,22 +37,35 @@ class db extends mysqli
|
||||
$query = "INSERT INTO logs (device, property, value) VALUES('" . $this->protect($ieeeAddress) . "', '" . $this->protect($propertyTree) . "', '" . $this->protect($value) . "')";
|
||||
if (is_numeric($value) and !empty($properties2log[$propertyTree]))
|
||||
{
|
||||
$minMax = (float)$value * (float)$properties2log[$propertyTree] / 100;
|
||||
//echo "minMax = " .$minMax . EOL;
|
||||
// calculate a min/max value for storing data
|
||||
$var = $properties2log[$propertyTree];
|
||||
if (!is_numeric($var))
|
||||
{
|
||||
$minMax = (float)$value * (float)$var / 100;
|
||||
}else
|
||||
{
|
||||
$minMax = $var;
|
||||
}
|
||||
echo "minMax = " .$minMax . EOL;
|
||||
//echo "oldValue = " . $oldValue . EOL;
|
||||
//echo "Value = " . $value . EOL;
|
||||
|
||||
if ($value >= $oldValue - $minMax and $value <= $oldValue + $minMax)
|
||||
{
|
||||
//echo "========>>>>>>>>>not changed" . EOL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(!$this->result = $this->query($query))
|
||||
if ($testMode)
|
||||
{
|
||||
logger(ERROR, _("mysql query errror: ") . $this->error);
|
||||
logger(INFO, _("Test mode on: not storing in DB "));
|
||||
}else
|
||||
{
|
||||
if(!$this->result = $this->query($query))
|
||||
{
|
||||
logger(ERROR, _("mysql query errror: ") . $this->error);
|
||||
}
|
||||
}
|
||||
logger(INFO, sprintf(_("New value of property: %s of device: %s stored in database"), $propertyTree, $device->friendlyName, $value));
|
||||
logger(INFO, sprintf(_("New value of property: '%s' of device: %s stored in database"), $propertyTree, $device->friendlyName, $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class topic {
|
||||
|
||||
class device
|
||||
{
|
||||
public $method; //auto or manual
|
||||
public $method; //0 = auto or 1 = manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $ieeeAddress;
|
||||
@ -31,16 +31,23 @@ class device
|
||||
public $description;
|
||||
public $functions;
|
||||
public $payload;
|
||||
public $availability = array();
|
||||
public $availability;
|
||||
|
||||
public function set($event)
|
||||
private function __construct()
|
||||
{
|
||||
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set", $event);
|
||||
$this->availability = array("value" => null, "functions" => array());
|
||||
var_dump($this->availability);
|
||||
}
|
||||
|
||||
public function set($method=0) //, $event = null)
|
||||
{
|
||||
$this->method = $method;
|
||||
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set"); //, $event);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
publish($this->topic . "/" . $this->friendlyNames, $this->payload, "get", $event);
|
||||
publish($this->topic . "/" . $this->friendlyNames, $this->payload, "get"); //, $event);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user