Compare commits
No commits in common. "4b94ef29c1ac0400c7a3a83f8d6322fd3378568e" and "38cc436f4d7353c74ce5494d57e5f6315ab1d6b1" have entirely different histories.
4b94ef29c1
...
38cc436f4d
@ -28,17 +28,13 @@ $router->post('/api/login', 'AuthApi@login');
|
|||||||
$router->post('/api/logout', 'AuthApi@logout');
|
$router->post('/api/logout', 'AuthApi@logout');
|
||||||
$router->get('/api/rooms', 'RoomsApi@default');
|
$router->get('/api/rooms', 'RoomsApi@default');
|
||||||
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
||||||
|
|
||||||
$router->get('/api/devices', 'DevicesApi@default');
|
$router->get('/api/devices', 'DevicesApi@default');
|
||||||
$router->get('/api/plugins', 'PluginsApi@default');
|
$router->get('/api/plugins', 'PluginsApi@default');
|
||||||
$router->get('/api/users', 'UsersApi@default');
|
$router->get('/api/users', 'UsersApi@default');
|
||||||
$router->get('/api/server', 'ServerApi@default');
|
$router->get('/api/server', 'ServerApi@default');
|
||||||
$router->get('/api/server/log', 'ServerApi@logStatus');
|
$router->get('/api/server/log', 'ServerApi@logStatus');
|
||||||
|
|
||||||
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
||||||
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
||||||
$router->get('/api/widgets/{widgetId}/detail/{period}', 'WidgetApi@detail');
|
|
||||||
|
|
||||||
|
|
||||||
//cron
|
//cron
|
||||||
$router->post('/cron/clean', 'CronApi@clean');
|
$router->post('/cron/clean', 'CronApi@clean');
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
class RoomsApi extends ApiController
|
class RoomsApi extends ApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function default()
|
public function
|
||||||
|
default()
|
||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = [];
|
$response = [];
|
||||||
|
@ -12,24 +12,16 @@ class ServerApi extends ApiController {
|
|||||||
return $meminfo;
|
return $meminfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProcessorUsage(){
|
|
||||||
$loads=sys_getloadavg();
|
|
||||||
$core_nums=trim(shell_exec("grep -P '^physical id' /proc/cpuinfo|wc -l"));
|
|
||||||
$load = round($loads[0]/($core_nums + 1)*100, 2);
|
|
||||||
return $load;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function default(){
|
public function default(){
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = [
|
$response = [
|
||||||
"cpu_load" => $this->getProcessorUsage(),
|
"cpu_load" => sys_getloadavg()[0],
|
||||||
"uptime" => shell_exec('uptime -p'),
|
"uptime" => shell_exec('uptime -p'),
|
||||||
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
||||||
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
||||||
"diskFree" => disk_free_space("/"),
|
"diskFree" => disk_free_space("/"),
|
||||||
"diskTotal" => disk_total_space("/"),
|
"diskTotal" => disk_total_space("/"),
|
||||||
"serverTime" => date('m. d. Y H:i:s'),
|
"serverTime" => date('m. d. Y H:i:s - e'),
|
||||||
"serverTimeZone" => date('e'),
|
|
||||||
];
|
];
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
@ -32,17 +32,9 @@ class WidgetApi extends ApiController
|
|||||||
$this->response(['value' => $response]);
|
$this->response(['value' => $response]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail($subDeviceId, $period = "day")
|
public function detail($subDeviceId)
|
||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
|
|
||||||
$groupBy = [
|
|
||||||
"year" => "month",
|
|
||||||
"month" => "day",
|
|
||||||
"day" => "hour",
|
|
||||||
"hout" => "minute",
|
|
||||||
];
|
|
||||||
|
|
||||||
$response = null;
|
$response = null;
|
||||||
$connectionError = true;
|
$connectionError = true;
|
||||||
|
|
||||||
@ -50,18 +42,11 @@ class WidgetApi extends ApiController
|
|||||||
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
||||||
|
|
||||||
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
||||||
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
$events = RecordManager::getAllRecordForGraph($subDeviceId);
|
||||||
if ( count($events) == 0){
|
if ( count($events) == 0){
|
||||||
throw new Exception("No Records", 404);
|
throw new Exception("No Records", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Striping executed value from dataset if pasiv device such as Senzor ETC
|
|
||||||
if ($subDeviceData['type'] != "on/off") {
|
|
||||||
foreach ($events as $key => $event) {
|
|
||||||
unset($events[$key]['execuded']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$LastRecordTime = new DateTime(reset($events)['time']);
|
$LastRecordTime = new DateTime(reset($events)['time']);
|
||||||
$niceTime = Utilities::ago($LastRecordTime);
|
$niceTime = Utilities::ago($LastRecordTime);
|
||||||
|
|
||||||
@ -130,7 +115,7 @@ class WidgetApi extends ApiController
|
|||||||
|
|
||||||
//TODO: Make Cleaner
|
//TODO: Make Cleaner
|
||||||
if (isset(RANGES[$subDeviceData['type']])){
|
if (isset(RANGES[$subDeviceData['type']])){
|
||||||
$response['graph']['options']['scales']['yAxes'] = [[
|
$response['graph']['options']['options']['scales']['yAxes'] = [[
|
||||||
'ticks' => [
|
'ticks' => [
|
||||||
'min' => RANGES[$subDeviceData['type']]['min'],
|
'min' => RANGES[$subDeviceData['type']]['min'],
|
||||||
'max' => RANGES[$subDeviceData['type']]['max'],
|
'max' => RANGES[$subDeviceData['type']]['max'],
|
||||||
|
@ -86,7 +86,7 @@ class RecordManager{
|
|||||||
$dateTime = $dateTime->modify($periodLocal);
|
$dateTime = $dateTime->modify($periodLocal);
|
||||||
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
||||||
$groupBy = strtoupper($groupBy).'(time)';
|
$groupBy = strtoupper($groupBy).'(time)';
|
||||||
$sql = 'SELECT value, time, execuded FROM records
|
$sql = 'SELECT value, time FROM records
|
||||||
WHERE
|
WHERE
|
||||||
subdevice_id = ?
|
subdevice_id = ?
|
||||||
AND
|
AND
|
||||||
|
@ -77,7 +77,7 @@ class SubDeviceManager
|
|||||||
|
|
||||||
//TODO: @Patrik Check line 89
|
//TODO: @Patrik Check line 89
|
||||||
$rows = Db::loadAll("
|
$rows = Db::loadAll("
|
||||||
SELECT d.room_id, sd.subdevice_id, sd.device_id, d.icon, d.name, sd.type, sd.unit, r.value FROM subdevices sd
|
SELECT d.room_id, sd.subdevice_id, sd.device_id, d.name, sd.type, sd.unit, r.value FROM subdevices sd
|
||||||
JOIN devices d ON sd.device_id = d.device_id
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
||||||
WHERE d.room_id IN (".str_repeat("?,", count($roomIds)-1)."?)
|
WHERE d.room_id IN (".str_repeat("?,", count($roomIds)-1)."?)
|
||||||
|
Loading…
Reference in New Issue
Block a user