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');
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');

View File

@ -48,32 +48,36 @@ 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);
$data = json_encode($output);
$arrayTimeStamps = array_column($records, 'time');
foreach ($arrayTimeStamps as $key => $value) {
@ -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": {
@ -117,6 +131,7 @@ class Ajax extends Template
}';
echo $JSON;
die();
} else if (isset($_POST['action']) && $_POST['action'] == "getState") {
//State Update
$roomsData = RoomManager::getAllRooms();