Skip to content

Commit

Permalink
Merge branch 'release/2.15.0'
Browse files Browse the repository at this point in the history
* release/2.15.0:
  Bumped version to 2.15.0
  Add databse patch level in initial SQL
  Adjust body output size
  Fix open_basedir restriction error
  Rework database default values
  Add pause function also to cron script
  Adjust label position in chart
  Fix wrong variable references
  Add example injecting system load into output
  Add splitter for chart resizing
  Fix layout
  Minor fixes in channel logic
  Add scatter plot
  Make settings multi language
  Add new date selection for charts
  • Loading branch information
K-Ko committed Oct 16, 2016
2 parents 4ff6e74 + 95efdf5 commit e4d0321
Show file tree
Hide file tree
Showing 120 changed files with 6,186 additions and 2,743 deletions.
4 changes: 2 additions & 2 deletions .version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.14.0
2016-08-24
2.15.0
2016-10-16
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#### Current

* [`03fee92`](../../commit/03fee92) Add database patch level in initial SQL (Knut Kohl)
* [`287084e`](../../commit/287084e) Adjust body output size (Knut Kohl)
* [`7cc6d5b`](../../commit/7cc6d5b) Fix open_basedir restriction error (Knut Kohl)
* [`cd3081f`](../../commit/cd3081f) Rework database default values (Knut Kohl)
* [`374ad24`](../../commit/374ad24) Add pause function also to cron script (Knut Kohl)
* [`c96fef5`](../../commit/c96fef5) Adjust label position in chart (Knut Kohl)
* [`02bb574`](../../commit/02bb574) Fix wrong variable references (Knut Kohl)
* [`a0a7fce`](../../commit/a0a7fce) Add example injecting system load into output (Knut Kohl)
* [`cda16bb`](../../commit/cda16bb) Add splitter for chart resizing (Knut Kohl)
* [`a50f2de`](../../commit/a50f2de) Add scatter plot (Knut Kohl)
* [`696285e`](../../commit/696285e) Make settings multi language (Knut Kohl)
* [`0f0eb15`](../../commit/0f0eb15) Add new date selection for charts (Knut Kohl)
* [`71d8d3e`](../../commit/71d8d3e) Merge tag 'v2.14.0' into develop (Knut Kohl)

#### v2.14.0

* [`1fb8953`](../../commit/1fb8953) Change chart zoom to mouse scroll (Knut Kohl)
* [`5dac0c3`](../../commit/5dac0c3) Upgrade PNotify to 3.0.0 (Knut Kohl)
* [`a887632`](../../commit/a887632) Merge tag 'v2.13.2' into develop (Knut Kohl)
Expand Down
72 changes: 44 additions & 28 deletions api/r6/app/API.php → api/r6/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license MIT License (MIT) http://opensource.org/licenses/MIT
* @version 1.0.0
*/
class API extends Slim\Slim
class Api extends Slim\Slim
{

/**
Expand Down Expand Up @@ -46,7 +46,10 @@ public function stopAPI($message, $code=400)
{
$this->status($code);
$this->response()->header('X-Status-Reason', $message);
$this->render(array( 'status'=>$code<400?'success':'error', 'message'=>$message ));
$this->render(array(
'status' => $code<400 ? 'success' : 'error',
'message' => $message
));
$this->stop();
}

Expand Down Expand Up @@ -93,32 +96,45 @@ public function readData($guid, $request)
$result->write($attr);
}

// optimized flow 1st "if" then "loop"...
if ($full and $short) {
// passthrough all values as numeric based array
foreach ($buffer as $row) {
$result->write(array_values($row));
}
} elseif ($full) {
// do nothing, use as is
$result->append($buffer);
} elseif ($short) {
// default mobile result: only timestamp and data
foreach ($buffer as $row) {
$result->write(array(
/* 0 */ $row['timestamp'],
/* 1 */ $row['data']
));
}
} else {
// default result: only timestamp and data
foreach ($buffer as $row) {
$result->write(array(
'timestamp' => $row['timestamp'],
'data' => $row['data']
));
}
}
// Optimized flow, 1st "if" then "loop" ...
switch (true) {

// Passthrough all values as numeric based array
case $full && $short:
foreach ($buffer as $row) {
if (!$channel->meter) unset($row['consumption']);
$result->write(array_values($row));
}
break;

// Do nothing, use as is
case $full:
foreach ($buffer as $row) {
if (!$channel->meter) unset($row['consumption']);
$result->write($row);
}
break;

// Default mobile result: only timestamp and data
case $short:
foreach ($buffer as $row) {
$result->write(array(
/* 0 */ $row['timestamp'],
/* 1 */ $row['data']
));
}
break;

// Default result: only timestamp and data
default:
foreach ($buffer as $row) {
$result->write(array(
'timestamp' => $row['timestamp'],
'data' => $row['data']
));
}

} // switch

return $result;
}
Expand Down
File renamed without changes.
13 changes: 6 additions & 7 deletions api/r6/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @version 1.0.0
*/

set_time_limit(0);

define('DEVELOP', (isset($_SERVER['HTTP_X_DEBUG']) AND $_SERVER['HTTP_X_DEBUG']));

if (DEVELOP) {
Expand All @@ -24,9 +26,8 @@
* Directories
*/
define('DS', DIRECTORY_SEPARATOR);
define('BASE_DIR', dirname(__FILE__));
define('ROOT_DIR', dirname(dirname(BASE_DIR)));
define('APP_DIR', BASE_DIR . DS . 'app');
define('BASE_DIR', __DIR__);
define('ROOT_DIR', dirname(dirname(__DIR__)));
define('CONF_DIR', ROOT_DIR . DS . 'config');
define('CORE_DIR', ROOT_DIR . DS . 'core');
define('LIB_DIR', ROOT_DIR . DS . 'lib');
Expand All @@ -49,11 +50,11 @@
* Initialize Loader
*/
$loader = require_once ROOT_DIR . DS . 'vendor' . DS . 'autoload.php';
$loader->addPsr4('', array(CORE_DIR, LIB_DIR, APP_DIR));
$loader->addPsr4('', array(CORE_DIR, LIB_DIR, BASE_DIR));

Loader::register($loader, TEMP_DIR);

$api = new API(array(
$api = new Api(array(
'mode' => DEVELOP ? 'development' : 'production',
'log.level' => DEVELOP ? Slim\Log::INFO : Slim\Log::ALERT,
'debug' => FALSE, // No debug mode at all
Expand Down Expand Up @@ -102,8 +103,6 @@

slimMVC\ORM::setDatabase($api->db);

Channel::setCache($api->cache);

foreach ((new ORM\SettingsKeys)->find() as $setting) {
$api->config->set($setting->getKey(), $setting->getValue());
}
Expand Down
8 changes: 6 additions & 2 deletions api/r6/routes/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function($guid) use ($api)
try {
$cnt = Channel::byGUID($guid)->write($request, $timestamp);
} catch (Exception $e) {
$api->stopAPI($e->getMessage(), 400);
$api->stopAPI($e->getMessage(), $e->getCode() ?: 400);
}

if ($cnt) $api->stopAPI($cnt.' reading(s) added', 201);
Expand Down Expand Up @@ -106,7 +106,9 @@ function($period, $guid) use ($api)

$result = $api->readData($guid, $request);
$api->response->headers->set('X-Data-Rows', count($result));
$api->response->headers->set('X-Data-Size', $result->size() . ' Bytes');
if (is_object($result) && method_exists($result, 'size')) {
$api->response->headers->set('X-Data-Size', $result->size() . ' Bytes');
}
$api->render($result);
})->name('GET /data/:period/:guid')->help = array(
'since' => 'r6',
Expand Down Expand Up @@ -308,6 +310,8 @@ function() use ($api)
$api->db->truncate($table);
}

$this->db->query('UPDATE `pvlng_channel` SET `offset` = 0 WHERE `adjust`');

\ORM\Settings::setCoreValue(null, 'EmptyDatabaseAllowed', 0);

$api->stopAPI('All data deleted', 200);
Expand Down
65 changes: 65 additions & 0 deletions api/r6/routes/scatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
*
*
* @author Knut Kohl <[email protected]>
* @copyright 2012-2014 Knut Kohl
* @license MIT License (MIT) http://opensource.org/licenses/MIT
* @version 1.0.0
*/

/**
*
*/
$api->get(
'/data/scatter/:GUIDx/:GUIDy',
$APIkeyRequired,
function($GUIDx, $GUIDy) use ($api)
{
$request = $api->request->get();

Channel::calcStartEnd($request);

$xChannel = Channel::ByGUID($GUIDx);
$yChannel = Channel::ByGUID($GUIDy);

$buffer = new Buffer;

if ($api->request->get('attributes')) {
$buffer->write($xChannel->getAttributes());
$buffer->write($yChannel->getAttributes());
}

$sql = $api->db->sql(
'CALL `pvlng_scatter`({1}, {2}, {3}, {4})',
$xChannel->entity, $yChannel->entity,
$request['start'], $request['end']
);

if ($api->request->get('sql')) {
$api->response()->header(
'X-SQL',
str_replace(array("\n", "\r"), array(' ', ''), $sql)
);
}

$cnt = 0;

$api->db->setBuffered();

if ($res = $api->db->query($sql)) {
while ($row = $res->fetch_row()) {
$cnt++;
$buffer->write(array_values($row));
}
$res->close();
}

$api->response()->header('X-Rows', $cnt);

$api->render($buffer);
})->name('GET /data/scatter/:x/:y')->help = array(
'since' => 'r6',
'description' => 'Fetch data for scatter plot',
'apikey' => true,
);
38 changes: 20 additions & 18 deletions api/r6/routes/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
/**
*
*/
$api->get('/status', $APIkeyRequired, function() use ($api) {

$api->get(
'/status',
$APIkeyRequired,
function() use ($api)
{
$result = array(
'version' => exec('cat /proc/version')
);
Expand All @@ -22,7 +25,7 @@
// as well as the amount of time since then that the system has been idle.
// Both are given as floating-point values, in seconds.
$res = explode(' ', exec('cat /proc/uptime'));
if (!empty($res)) {
if (!empty($res)) {
$result['uptime'] = array(
'overall' => +$res[0],
'overall_minutes' => $res[0]/60,
Expand All @@ -41,8 +44,7 @@
// Total: 3676 1721 1955
exec('free -mto', $res);

if (preg_match_all('~^(\w+): +(\S+) +(\S+) +(\S+)~m',
implode("\n", $res), $args, PREG_SET_ORDER)) {
if (preg_match_all('~^(\w+): +(\S+) +(\S+) +(\S+)~m', implode("\n", $res), $args, PREG_SET_ORDER)) {
foreach ($args as $arg) {
$result['memory'][$arg[1]] = array(
'total_mb' => +$arg[2],
Expand All @@ -59,24 +61,24 @@
// These values represent the average system load in the last 1, 5 and 15 minutes,
// the number of active and total scheduling entities (tasks) and
// the PID of the last created process in the system.
$res = exec('cat /proc/loadavg');
if (preg_match('~([0-9.]+) ([0-9.]+) ([0-9.]+) (\d+)/(\d+)~', $res, $args)) {
$result['load'] = array(
'miutes_1' => +$args[1],
'miutes_5' => +$args[2],
'miutes_15' => +$args[3],
'active' => +$args[4],
'total' => +$args[5]
$res = exec('cat /proc/loadavg');
if (preg_match('~([0-9.]+) ([0-9.]+) ([0-9.]+) (\d+)/(\d+)~', $res, $args)) {
$result['load'] = array(
'minutes_1' => +$args[1],
'minutes_5' => +$args[2],
'minutes_15' => +$args[3],
'active' => +$args[4],
'total' => +$args[5]
);
}

exec('cat /proc/cpuinfo', $res);
if (preg_match_all('~^([^\t]+)\s*:\s*(.+)$~m',
implode("\n", $res), $args, PREG_SET_ORDER)) {
foreach ($args as $arg) {
$result['cpuinfo'][str_replace(' ', '_', $arg[1])] =

if (preg_match_all('~^([^\t]+)\s*:\s*(.+)$~m', implode("\n", $res), $args, PREG_SET_ORDER)) {
foreach ($args as $arg) {
$result['cpuinfo'][str_replace(' ', '_', $arg[1])] =
(string) +$arg[2] == $arg[2] ? +$arg[2] : $arg[2];
}
}
}

$api->response->headers->set('Content-Type', 'application/json');
Expand Down
Loading

0 comments on commit e4d0321

Please sign in to comment.