Better Graphs #4

This commit is contained in:
JonatanRek 2019-09-29 09:23:42 +02:00
parent 7e047ee0a3
commit fdf94f8b8d
3 changed files with 121 additions and 127 deletions

View File

@ -1,4 +1,10 @@
<?php
class ChartScale{
const HOUR = 'info';
const DAY = 'warning';
const MONTH = 'warning';
const YEAR = 'error';
}
class ChartManager{
function generateChart($data, $min = 0, $max = 100)
{

View File

@ -18,7 +18,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./app/templates/css/main.css">
<link rel="stylesheet" href="./app/templates/css/main.css?v2">
<link rel="stylesheet" href="./app/templates/css/font-awesome.min.css">
<link rel="stylesheet" href="./app/templates/css/modal.css">
<link rel="stylesheet" href="./app/templates/css/pre.css">

View File

@ -50,86 +50,45 @@ class Ajax extends Template
} else if (isset($_POST['subDevice']) && isset($_POST['action']) && $_POST['action'] == "chart") {
//TODO lepe rozstrukturovat
$subDeviceId = $_POST['subDevice'];
$period = $_POST['period'];
$groupBy = $_POST['group'];
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
$records = RecordManager::getAllRecordForGraph($subDeviceId);
$records = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy);
$array = array_column($records, 'value');
$arrayTime = array_column($records, 'time');
$output = [];
foreach ($array as $key => $value) {
/*if ($value == 1 || $value == 0)
{
$output[$key]['y'] = $value;
}
if ($subDevice['type'] == 'light'){
if ($value > 810){
$output[$key]['y'] = 1;
} else {
$output[$key]['y'] = 0;
}*/
$output[$key]['y'] = $value;
}
}
$timeStamp = new DateTime($arrayTime[$key]);
$output[$key]['t'] = $timeStamp->format("Y-m-d") . 'T' . $timeStamp->format("H:i:s") . 'Z';
}
}
$data = json_encode($output);
$data = json_encode($output);
$arrayTimeStamps = array_column($records, 'time');
foreach ($arrayTimeStamps as $key => $value) {
$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 = '{
"type": "line",
"data": {
"labels": ' . $data . ',
"datasets": [{
"data": ' . $data . ',
"backgroundColor": "#7522bf",
"lineTension": 0,
"radius": 5
}]
},
"options": {
"legend": {
"display": false
},
"scales": {
"xAxes": [{
"type": "time",
"time": {
"unit": "hour"
}
}],
"yAxes": [{
"ticks": {
"min": ' . $range['min'] . ',
"max": ' . $range['max'] . ',
"steps": ' . $range['scale'] . '
}
}]
},
"tooltips": {
"enabled": false
},
"hover": {
"mode": null
}
}
}';*/
$labels = json_encode($arrayTimeStamps);
$range = RANGES[$subDevice['type']];
$graphType = $range['graph'];
$JSON = '
{
"type": "bar",
header('Content-Type: application/json');
$JSON = '
{
"type": "' . $graphType . '",
"data": {
"datasets": [{
"data": ' . $data . '
@ -159,20 +118,10 @@ $JSON = '
"mode": true
}
}
}
';
/*
*/
echo $JSON;
die();
} 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 = [];
@ -213,16 +162,55 @@ die();
}
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();
/*$JSON = '{
"type": "line",
"data": {
"labels": ' . $data . ',
"datasets": [{
"data": ' . $data . ',
"backgroundColor": "#7522bf",
"lineTension": 0,
"radius": 5
}]
},
"options": {
"legend": {
"display": false
},
"scales": {
"xAxes": [{
"type": "time",
"time": {
"unit": "hour"
}
}],
"yAxes": [{
"ticks": {
"min": ' . $range['min'] . ',
"max": ' . $range['max'] . ',
"steps": ' . $range['scale'] . '
}
}]
},
"tooltips": {
"enabled": false
},
"hover": {
"mode": null
}
}
}';*/