web: backport the handling of timezones for night.rrd to xmlrpc alpha API
This commit is contained in:
parent
2b9d98771e
commit
c9ab068642
|
@ -2,7 +2,7 @@
|
|||
|
||||
//
|
||||
// xmlrpc.inc : data and management plane xmlrpc methods for logging metering data
|
||||
// aplha version API
|
||||
// alpha version API
|
||||
//
|
||||
// Copyright (c) 2008-2009 jokamajo.org
|
||||
//
|
||||
|
@ -77,10 +77,10 @@ function _logger_measurement_add($logs) {
|
|||
}
|
||||
system($command, $return);
|
||||
if ($return == 0) {
|
||||
// update the night rrd every day at 6AM UTC
|
||||
// update the night rrd every day at 6AM local time
|
||||
if (time() > $meterdata->night) {
|
||||
$timestamp = floor(time()/86400)*86400;
|
||||
$start = $timestamp + 3600;
|
||||
$midnight = _logger_midnight(time(), $auth['device']);
|
||||
$start = $midnight + 7200; // 2AM local time
|
||||
$end = $start + 10800; // 3h time interval
|
||||
$command = $path->root ."/rrdtool fetch ". $path->base . $meter .".rrd AVERAGE -r 900 -s ". $start ." -e ". $end ." | tail -n 12 | awk -F': ' '{SUM += $2} END {print SUM/12}'";
|
||||
$night = (float)shell_exec($command); //test shell_exec iso system
|
||||
|
@ -92,7 +92,7 @@ function _logger_measurement_add($logs) {
|
|||
else {
|
||||
watchdog_xmlrpc('logger.measurementAdd', 'error updating night rrd: %command', array('%command' => $command), WATCHDOG_ERROR); //debugging
|
||||
}
|
||||
$meterdata->night = $timestamp + 104400; //add an offset of 29h, i.e. 5AM UTC next day
|
||||
$meterdata->night = $midnight + 108000; //add an offset of 30h = 6AM local time
|
||||
}
|
||||
// {logger_meters} is updated with the true metervalue $value, NOT $value*$meterdata->factor since we're not normalising this entry!
|
||||
db_query("UPDATE {logger_meters} SET access = %d, night = %d, value = %d WHERE meter = '%s'", time(), $meterdata->night, $value, $meter);
|
||||
|
@ -104,3 +104,15 @@ function _logger_measurement_add($logs) {
|
|||
}
|
||||
return $command; //using $command for testing purposes, replace by $info afterwards
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the most recent midnight for this device based on the user's timezone
|
||||
*/
|
||||
function _logger_midnight($timestamp, $device) {
|
||||
$timezone = db_result(db_query("SELECT u.timezone FROM {logger_devices} ld INNER JOIN {users} u ON ld.uid = u.uid WHERE ld.device = '%s'", $device));
|
||||
// add one day to make sure $midnight > $timestamp
|
||||
$midnight = floor($timestamp/86400 + 1)*86400 - $timezone;
|
||||
// search for first $midnight < $timestamp
|
||||
while ($midnight > $timestamp) $midnight -= 86400;
|
||||
return $midnight;
|
||||
}
|
|
@ -103,7 +103,7 @@ function _logger_measurement_add($auth, $logs) {
|
|||
system($command, $return);
|
||||
|
||||
if ($return == 0) {
|
||||
// update the night rrd every day at 6AM UTC
|
||||
// update the night rrd every day at 6AM local time
|
||||
if (time() > $meterdata->night) {
|
||||
$midnight = _logger_midnight(time(), $auth['device']);
|
||||
$start = $midnight + 7200; // 2AM local time
|
||||
|
|
Loading…
Reference in New Issue