Minor Tweeks
This commit is contained in:
@@ -2,19 +2,18 @@
|
||||
|
||||
class RoomsApi extends ApiController
|
||||
{
|
||||
|
||||
public function
|
||||
default()
|
||||
|
||||
public function default()
|
||||
{
|
||||
//$this->requireAuth();
|
||||
$response = [];
|
||||
$roomIds = [];
|
||||
$roomsData = RoomManager::getRoomsDefault();
|
||||
|
||||
|
||||
foreach ($roomsData as $roomKey => $room) {
|
||||
$roomIds[] = $room['room_id'];
|
||||
}
|
||||
|
||||
|
||||
//Translation Of Numeric Walues
|
||||
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
||||
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
||||
@@ -27,7 +26,7 @@ class RoomsApi extends ApiController
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$cammelCaseClass = "";
|
||||
foreach (explode('-', $type) as $word) {
|
||||
$cammelCaseClass .= ucfirst($word);
|
||||
@@ -42,7 +41,7 @@ class RoomsApi extends ApiController
|
||||
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($roomsData as $roomKey => $roomData) {
|
||||
if ($roomData['device_count'] == 0) continue;
|
||||
$response[] = [
|
||||
@@ -53,11 +52,11 @@ class RoomsApi extends ApiController
|
||||
}
|
||||
$this->response($response);
|
||||
}
|
||||
|
||||
|
||||
public function update($roomId)
|
||||
{
|
||||
//$this->requireAuth();
|
||||
|
||||
|
||||
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]);
|
||||
$this->response($subDevicesData);
|
||||
}
|
||||
|
@@ -12,16 +12,24 @@ class ServerApi extends ApiController {
|
||||
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(){
|
||||
//$this->requireAuth();
|
||||
$response = [
|
||||
"cpu_load" => sys_getloadavg()[0],
|
||||
"cpu_load" => $this->getProcessorUsage(),
|
||||
"uptime" => shell_exec('uptime -p'),
|
||||
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
||||
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
||||
"diskFree" => disk_free_space("/"),
|
||||
"diskTotal" => disk_total_space("/"),
|
||||
"serverTime" => date('m. d. Y H:i:s - e'),
|
||||
"serverTime" => date('m. d. Y H:i:s'),
|
||||
"serverTimeZone" => date('e'),
|
||||
];
|
||||
$this->response($response);
|
||||
}
|
||||
|
@@ -32,9 +32,17 @@ class WidgetApi extends ApiController
|
||||
$this->response(['value' => $response]);
|
||||
}
|
||||
|
||||
public function detail($subDeviceId)
|
||||
public function detail($subDeviceId, $period = "day")
|
||||
{
|
||||
//$this->requireAuth();
|
||||
|
||||
$groupBy = [
|
||||
"year" => "month",
|
||||
"month" => "day",
|
||||
"day" => "hour",
|
||||
"hout" => "minute",
|
||||
];
|
||||
|
||||
$response = null;
|
||||
$connectionError = true;
|
||||
|
||||
@@ -42,11 +50,18 @@ class WidgetApi extends ApiController
|
||||
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
||||
|
||||
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
||||
$events = RecordManager::getAllRecordForGraph($subDeviceId);
|
||||
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
||||
if ( count($events) == 0){
|
||||
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']);
|
||||
$niceTime = Utilities::ago($LastRecordTime);
|
||||
|
||||
@@ -115,7 +130,7 @@ class WidgetApi extends ApiController
|
||||
|
||||
//TODO: Make Cleaner
|
||||
if (isset(RANGES[$subDeviceData['type']])){
|
||||
$response['graph']['options']['options']['scales']['yAxes'] = [[
|
||||
$response['graph']['options']['scales']['yAxes'] = [[
|
||||
'ticks' => [
|
||||
'min' => RANGES[$subDeviceData['type']]['min'],
|
||||
'max' => RANGES[$subDeviceData['type']]['max'],
|
||||
|
Reference in New Issue
Block a user