Add license and minor tuning
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
require_once 'rrd.php';
|
||||
|
||||
$sDataDirectory = 'data';
|
||||
$aRRDCreate = array(
|
||||
'inverter.rrd' => 'create %s
|
||||
--step 5
|
||||
--start %d
|
||||
$aRRDFiles = array(
|
||||
'inverter.rrd' => array(5, '
|
||||
DS:TEMP:GAUGE:120:U:U
|
||||
DS:VPV:GAUGE:120:U:U
|
||||
DS:IAC:GAUGE:120:U:U
|
||||
@@ -27,17 +27,12 @@ $aRRDCreate = array(
|
||||
RRA:AVERAGE:0.5:17:1017
|
||||
RRA:AVERAGE:0.5:120:1008
|
||||
RRA:AVERAGE:0.5:535:1002
|
||||
RRA:AVERAGE:0.5:6324:1001',
|
||||
'today.rrd' => 'create %s
|
||||
--step 5
|
||||
--start %d
|
||||
RRA:AVERAGE:0.5:6324:1001'),
|
||||
'today.rrd' => array(5, '
|
||||
DS:PAC:GAUGE:120:0:U
|
||||
DS:ETODAY:GAUGE:120:0:U
|
||||
RRA:AVERAGE:0.5:1:17280');
|
||||
$aRRDFiles = array_keys($aRRDCreate);
|
||||
RRA:AVERAGE:0.5:1:17280'));
|
||||
|
||||
/* Spawn process that accepts commands from STDIN */
|
||||
$rHandle = popen('rrdtool - > /dev/null', 'w');
|
||||
$bFirst = true;
|
||||
$aRRDKeys = array();
|
||||
$i = 0;
|
||||
@@ -45,39 +40,39 @@ foreach (glob($sDataDirectory . '/*.csv') as $sFile) {
|
||||
/* Extract header from csv file */
|
||||
$aData = explode("\n", trim(file_get_contents($sFile)));
|
||||
$sHeader = array_shift($aData);
|
||||
|
||||
|
||||
if ($bFirst) {
|
||||
$aHeader = array_flip(explode(',', $sHeader));
|
||||
foreach ($aRRDCreate as $sRRDFile => $sRRDCreate) {
|
||||
foreach ($aRRDFiles as $sFile => $aRRD) {
|
||||
/* Determine fields to update in RRD database */
|
||||
preg_match_all('~DS:([^:]+):~', $sRRDCreate, $aMatches);
|
||||
$sContents = $aRRD[1];
|
||||
preg_match_all('~DS:([^:]+):~', $sContents, $aMatches);
|
||||
$aKeys = array();
|
||||
foreach ($aMatches[1] as $sField) {
|
||||
$aKeys[] = $aHeader[$sField] - 1;
|
||||
}
|
||||
$aRRDKeys[$sRRDFile] = array_flip($aKeys);
|
||||
$aRRDKeys[$sFile] = array_flip($aKeys);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($aData as $sEntry) {
|
||||
$aValues = array_slice(explode(',', $sEntry), 1, 12);
|
||||
$iTime = $aValues[0];
|
||||
if ($bFirst) {
|
||||
foreach ($aRRDCreate as $sRRDFile => $sRRDCreate) {
|
||||
foreach ($aRRDFiles as $sFile => $aRRD) {
|
||||
/* Create RRD database */
|
||||
$sCommand = str_replace("\n", ' ', sprintf($sRRDCreate, $sRRDFile, $aValues[0] - 1)) . "\n";
|
||||
fwrite($rHandle, $sCommand);
|
||||
$iStep = $aRRD[0];
|
||||
$iStart = $iTime - 1;
|
||||
$sContents = $aRRD[1];
|
||||
RRD::create($sFile, $iStep, $iStart, $sContents);
|
||||
}
|
||||
$bFirst = false;
|
||||
}
|
||||
++$i;
|
||||
foreach ($aRRDFiles as $sRRDFile) {
|
||||
foreach ($aRRDFiles as $sFile => $aRRD) {
|
||||
/* Update relevant fields in RRD database */
|
||||
$aRRDValues = array_intersect_key($aValues, $aRRDKeys[$sRRDFile]);
|
||||
$sCommand = sprintf("update %s %d:%s\n", $sRRDFile, $aValues[0], implode(':', $aRRDValues));
|
||||
//printf('[%d] %s', $i, $sCommand);
|
||||
fwrite($rHandle, $sCommand);
|
||||
$aValues = array_intersect_key($aValues, $aRRDKeys[$sFile]);
|
||||
RRD::update($sFile, $iTime, $aValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
fwrite($rHandle, "quit\n");
|
||||
pclose($rHandle);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ function getTwilight($iYear, $iDay) {
|
||||
|
||||
function getWake(&$aTwilight = null) {
|
||||
if (!isset($aTwilight)) {
|
||||
$aTwilight = getTwilight(date('Y'), date('z'));
|
||||
$aTwilight = getTwilight(date('Y'), date('z') + 1);
|
||||
}
|
||||
return strtotime($sWake = isset($aTwilight) ? $aTwilight[1] : DEFAULT_WAKE);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ define('PVOUTPUT_URL', 'http://pvoutput.org/service/r1/addstatus.jsp');
|
||||
define('TODAY_FILE', 'data/today_%s.csv');
|
||||
define('FIELD', 'PAC');
|
||||
define('RESOLUTION', 5);
|
||||
define('TRESHOLD_CORRECT', 1);
|
||||
define('MARGIN_ENERGY', 0.5);
|
||||
define('TRESHOLD_CORRECT', 3); // h
|
||||
define('MARGIN_ENERGY', 0.2);
|
||||
define('MARGIN_TEMPERATURE', 0.4);
|
||||
|
||||
$aSystems = array(
|
||||
|
||||
Reference in New Issue
Block a user