use new rrd class for pvoutput.php
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
require_once 'functions.php';
|
||||
require_once 'rrd.php';
|
||||
|
||||
define('RRD_FILE', 'data/inverter_%s_today.rrd');
|
||||
define('RRD_FETCH', 'rrdtool fetch %s AVERAGE -r %d -s %d -e %d');
|
||||
define('PVOUTPUT_URL', 'http://pvoutput.org/service/r1/addstatus.jsp');
|
||||
define('TODAY_FILE', 'data/today_%s.csv');
|
||||
define('FIELD', 'PAC');
|
||||
@@ -48,11 +48,7 @@ $iLast = $aToday[2];
|
||||
|
||||
/* Extract fields */
|
||||
$iTime = time();
|
||||
$sData = command(sprintf(RRD_FETCH, sprintf(RRD_FILE, $sSerial), RESOLUTION, $iLast, $iTime));
|
||||
$aData = explode("\n", trim($sData));
|
||||
$aFields = preg_split("~[\s]+~", array_shift($aData));
|
||||
array_shift($aData);
|
||||
$aFields = array_flip($aFields);
|
||||
list($aFields, $aData) = RRD::fetch(sprintf(RRD_FILE, $sSerial), RESOLUTION, $iLast, $iTime, 'AVERAGE');
|
||||
|
||||
/* Process data */
|
||||
$bFirst = true;
|
||||
@@ -60,8 +56,7 @@ $fEnergy = 0;
|
||||
if (isset($aFields[FIELD])) {
|
||||
$iField = $aFields[FIELD] + 1;
|
||||
array_shift($aData);
|
||||
foreach ($aData as $sRow) {
|
||||
$aRow = explode(' ', $sRow);
|
||||
foreach ($aData as $aRow) {
|
||||
$iDate = substr($aRow[0], 0, -1);
|
||||
$iInterval = $bFirst ? (($bFirst = false) || RESOLUTION) : $iDate - $iLast; // s
|
||||
if (($fValue = floatval($aRow[$iField])) > 0) { // W
|
||||
|
||||
@@ -9,7 +9,7 @@ class RRD {
|
||||
protected static $aPipes = array();
|
||||
|
||||
protected function __construct() {
|
||||
self::$rProcess= proc_open('rrdtool -', array(
|
||||
self::$rProcess = proc_open('rrdtool -', array(
|
||||
0 => array('pipe', 'r'),
|
||||
1 => array('pipe', 'w')), self::$aPipes);
|
||||
stream_set_blocking(self::$aPipes[1], false);
|
||||
@@ -19,7 +19,7 @@ class RRD {
|
||||
if (!isset(self::$rProcess)) {
|
||||
self::$oInstance = new self();
|
||||
}
|
||||
var_dump($sCommand);
|
||||
//echo $sCommand . "\n";
|
||||
fwrite(self::$aPipes[0], $sCommand . PHP_EOL);
|
||||
$nNull = null;
|
||||
$aRead = array(self::$aPipes[1]);
|
||||
@@ -45,14 +45,17 @@ class RRD {
|
||||
$aFields = array_flip($aFields);
|
||||
array_shift($aData);
|
||||
array_pop($aData);
|
||||
foreach ($aData as $iKey => $sRow) {
|
||||
$aValues = array();
|
||||
foreach ($aData as $sRow) {
|
||||
$aRow = explode(':', $sRow);
|
||||
$iTime = current($aRow);
|
||||
$mValue = trim(next($aRow));
|
||||
if ($mValue != '-nan') {
|
||||
$aValues[$iTime] = floatval($mValue);
|
||||
$aRow = explode(' ', trim(next($aRow)));
|
||||
foreach ($aRow as $iKey => $mValue) {
|
||||
if (strpos($mValue, 'nan') !== false) {
|
||||
$aRow[$iKey] = null;
|
||||
}
|
||||
}
|
||||
//$aValues[$iTime] = $fValue == 0 ? null : $fValue;
|
||||
$aValues[$iTime] = $aRow;
|
||||
}
|
||||
return array($aFields, $aValues);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user