Ajax Refactor/Oprimalization #2
This commit is contained in:
parent
4c69cf2f02
commit
b420ded943
@ -6,8 +6,7 @@ class ChartScale{
|
||||
const YEAR = 'error';
|
||||
}
|
||||
class ChartManager{
|
||||
function generateChart($data, $min = 0, $max = 100)
|
||||
{
|
||||
function generateChart($data, $min = 0, $max = 100) {
|
||||
|
||||
echo '<br>Aktuální Hodnota: '.$data[0]['value'];
|
||||
echo "<style>
|
||||
@ -88,5 +87,43 @@ class ChartManager{
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
|
||||
function generateChartData(int $subDeviceId, string $periode, string $groupBy) {
|
||||
$chartData = [];
|
||||
|
||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$records = RecordManager::getAllRecordForGraph($subDeviceId, $periode, $groupBy);
|
||||
|
||||
$array = array_column($records, 'value');
|
||||
$arrayTime = array_column($records, 'time');
|
||||
$output = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
$output[$key]['y'] = $value;
|
||||
if ($subDevice['type'] == 'light'){
|
||||
if ($value > 810){
|
||||
$output[$key]['y'] = 1;
|
||||
} else {
|
||||
$output[$key]['y'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$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 = $output;
|
||||
$arrayTimeStamps = array_column($records, 'time');
|
||||
foreach ($arrayTimeStamps as $key => $value) {
|
||||
$arrayTimeStamps[$key] = (new DateTime($value))->format(TIMEFORMAT);
|
||||
}
|
||||
|
||||
$chartData['graphRange'] = RANGES[$subDevice['type']];
|
||||
$chartData['graphType'] = RANGES[$subDevice['type']]['graph'];
|
||||
$chartData['graphData'] = $data;
|
||||
|
||||
return $chartData;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -51,7 +51,7 @@ function waitForExecution(params, elements, msg_state){
|
||||
url: 'ajax',
|
||||
type: 'POST',
|
||||
data: {
|
||||
lastRecord:'',
|
||||
action:'executed',
|
||||
subDevice_id : params['subDevice_id']
|
||||
},
|
||||
success: function(msg){
|
||||
|
@ -29,6 +29,7 @@ if ('serviceWorker' in navigator) {
|
||||
url: 'ajax',
|
||||
type: 'POST',
|
||||
data: {
|
||||
"notification" : '',
|
||||
"token": token
|
||||
},
|
||||
success: function(data){
|
||||
@ -179,7 +180,7 @@ function ajaxChart(id, period = 'day', group = 'hour'){
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
"subDevice": id,
|
||||
"subDevice_id": id,
|
||||
"action": 'chart',
|
||||
"period": period,
|
||||
"group": group
|
||||
|
Loading…
Reference in New Issue
Block a user