Some Graph fixes

This commit is contained in:
JonatanRek 2019-09-26 15:53:45 +02:00
parent e74d2095c6
commit 776a9e2d38
2 changed files with 124 additions and 111 deletions

View File

@ -192,7 +192,6 @@ $( '[name="room"]' ).change(function (e) {
} }
}); });
var windowLoc = $(location).attr('pathname'); var windowLoc = $(location).attr('pathname');
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/")); windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
console.log(); console.log();
@ -227,11 +226,10 @@ if (windowLoc == "/") {
} }
}); });
} }
},2000); },4000);
} }
//Graphs //Graphs
$('.graph-period').on('click', function (e) { $('.graph-period').on('click', function (e) {
var subId = $(this).attr('data-sub-device-id'); var subId = $(this).attr('data-sub-device-id');

View File

@ -48,42 +48,46 @@ class Ajax extends Template
AutomationManager::deactive($automationId); AutomationManager::deactive($automationId);
} }
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") { } else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
die();
//TODO lepe rozstrukturovat //TODO lepe rozstrukturovat
$subDeviceId = $_POST['subDevice']; $subDeviceId = $_POST['subDevice'];
$period = $_POST['period'];
$groupBy = $_POST['group'];
$subDevice = SubDeviceManager::getSubDevice($subDeviceId); $subDevice = SubDeviceManager::getSubDevice($subDeviceId);
$records = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy); $records = RecordManager::getAllRecordForGraph($subDeviceId);
$array = array_column($records, 'value'); $array = array_column($records, 'value');
$arrayTime = array_column($records, 'time');
$output = [];
if ($subDevice['type'] == 'light'){
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if ($value == 1 || $value == 0) /*if ($value == 1 || $value == 0)
{ {
return; $output[$key]['y'] = $value;
} }
if ($value > 810){ if ($value > 810){
$array[$key] = 1; $output[$key]['y'] = 1;
} else { } else {
$array[$key] = 0; $output[$key]['y'] = 0;
} }*/
} $output[$key]['y'] = $value;
} $output[$key]['t'] = (new DateTime($arrayTime[$key]))->format("hA");
}
$data = json_encode($array);
$arrayTimeStamps = array_column($records, 'time');
foreach ($arrayTimeStamps as $key => $value) { $data = json_encode($output);
$arrayTimeStamps = array_column($records, 'time');
foreach ($arrayTimeStamps as $key => $value) {
$arrayTimeStamps[$key] = (new DateTime($value))->format(TIMEFORMAT); $arrayTimeStamps[$key] = (new DateTime($value))->format(TIMEFORMAT);
} }
$labels = json_encode($arrayTimeStamps); $labels = json_encode($arrayTimeStamps);
$range = RANGES[$subDevice['type']]; $range = RANGES[$subDevice['type']];
header('Content-Type: application/json'); header('Content-Type: application/json');
$JSON = '{ $JSON = '{
"type": "line", "type": "line",
"data": { "data": {
"labels": ' . $labels . ', "labels": ' . $labels . ',
@ -99,12 +103,22 @@ class Ajax extends Template
"display": false "display": false
}, },
"scales": { "scales": {
xAxes: [{
type: "time",
time: {
unit: "hour"
}
}],
"yAxes": [{ "yAxes": [{
"ticks": { "ticks": {
"min": ' . $range['min'] . ', "min": ' . $range['min'] . ',
"max": ' . $range['max'] . ', "max": ' . $range['max'] . ',
"steps": ' . $range['scale'] . ' "steps": ' . $range['scale'] . '
} }
}],
xAxes: [{
type: "time",
distribution: "linear"
}] }]
}, },
"tooltips": { "tooltips": {
@ -114,10 +128,11 @@ class Ajax extends Template
"mode": null "mode": null
} }
} }
}'; }';
echo $JSON; echo $JSON;
} else if (isset($_POST['action']) && $_POST['action'] == "getState") { die();
} else if (isset($_POST['action']) && $_POST['action'] == "getState") {
//State Update //State Update
$roomsData = RoomManager::getAllRooms(); $roomsData = RoomManager::getAllRooms();
$subDevices = []; $subDevices = [];
@ -158,16 +173,16 @@ class Ajax extends Template
} }
echo json_encode($subDevices); echo json_encode($subDevices);
die(); die();
} else if (isset($_POST['scene_id'])) { } else if (isset($_POST['scene_id'])) {
$sceneId = $_POST['scene_id']; $sceneId = $_POST['scene_id'];
if (isset($_POST['action']) && $_POST['action'] == 'delete') { if (isset($_POST['action']) && $_POST['action'] == 'delete') {
SceneManager::delete($sceneId); SceneManager::delete($sceneId);
}else { }else {
echo SceneManager::execScene($sceneId); echo SceneManager::execScene($sceneId);
} }
} }
die(); die();
} }
} }