Some Graph fixes
This commit is contained in:
parent
e74d2095c6
commit
776a9e2d38
@ -192,7 +192,6 @@ $( '[name="room"]' ).change(function (e) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log();
|
||||
@ -227,11 +226,10 @@ if (windowLoc == "/") {
|
||||
}
|
||||
});
|
||||
}
|
||||
},2000);
|
||||
},4000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Graphs
|
||||
$('.graph-period').on('click', function (e) {
|
||||
var subId = $(this).attr('data-sub-device-id');
|
||||
|
@ -48,42 +48,46 @@ class Ajax extends Template
|
||||
AutomationManager::deactive($automationId);
|
||||
}
|
||||
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
|
||||
die();
|
||||
//TODO lepe rozstrukturovat
|
||||
$subDeviceId = $_POST['subDevice'];
|
||||
$period = $_POST['period'];
|
||||
$groupBy = $_POST['group'];
|
||||
|
||||
|
||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$records = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy);
|
||||
$records = RecordManager::getAllRecordForGraph($subDeviceId);
|
||||
|
||||
|
||||
$array = array_column($records, 'value');
|
||||
$arrayTime = array_column($records, 'time');
|
||||
$output = [];
|
||||
|
||||
|
||||
if ($subDevice['type'] == 'light'){
|
||||
foreach ($array as $key => $value) {
|
||||
if ($value == 1 || $value == 0)
|
||||
/*if ($value == 1 || $value == 0)
|
||||
{
|
||||
return;
|
||||
$output[$key]['y'] = $value;
|
||||
}
|
||||
if ($value > 810){
|
||||
$array[$key] = 1;
|
||||
$output[$key]['y'] = 1;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
$labels = json_encode($arrayTimeStamps);
|
||||
$range = RANGES[$subDevice['type']];
|
||||
header('Content-Type: application/json');
|
||||
$JSON = '{
|
||||
$labels = json_encode($arrayTimeStamps);
|
||||
$range = RANGES[$subDevice['type']];
|
||||
header('Content-Type: application/json');
|
||||
$JSON = '{
|
||||
"type": "line",
|
||||
"data": {
|
||||
"labels": ' . $labels . ',
|
||||
@ -99,12 +103,22 @@ class Ajax extends Template
|
||||
"display": false
|
||||
},
|
||||
"scales": {
|
||||
xAxes: [{
|
||||
type: "time",
|
||||
time: {
|
||||
unit: "hour"
|
||||
}
|
||||
}],
|
||||
"yAxes": [{
|
||||
"ticks": {
|
||||
"min": ' . $range['min'] . ',
|
||||
"max": ' . $range['max'] . ',
|
||||
"steps": ' . $range['scale'] . '
|
||||
}
|
||||
}],
|
||||
xAxes: [{
|
||||
type: "time",
|
||||
distribution: "linear"
|
||||
}]
|
||||
},
|
||||
"tooltips": {
|
||||
@ -114,10 +128,11 @@ class Ajax extends Template
|
||||
"mode": null
|
||||
}
|
||||
}
|
||||
}';
|
||||
}';
|
||||
|
||||
echo $JSON;
|
||||
} else if (isset($_POST['action']) && $_POST['action'] == "getState") {
|
||||
echo $JSON;
|
||||
die();
|
||||
} else if (isset($_POST['action']) && $_POST['action'] == "getState") {
|
||||
//State Update
|
||||
$roomsData = RoomManager::getAllRooms();
|
||||
$subDevices = [];
|
||||
@ -158,16 +173,16 @@ class Ajax extends Template
|
||||
}
|
||||
echo json_encode($subDevices);
|
||||
die();
|
||||
} else if (isset($_POST['scene_id'])) {
|
||||
} else if (isset($_POST['scene_id'])) {
|
||||
$sceneId = $_POST['scene_id'];
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'delete') {
|
||||
SceneManager::delete($sceneId);
|
||||
}else {
|
||||
echo SceneManager::execScene($sceneId);
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user