/**
  * Updates an existing TaskDefined model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelDevice = new Device();
     $modelAction = new Action();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['view', 'id' => $model->id]);
         return $this->redirect(['task/index']);
     } else {
         return $this->render('update', ['model' => $model, 'from_device_ids' => ArrayHelper::map($modelDevice->getDeviceMaster(), 'id', 'name'), 'to_device_ids' => ArrayHelper::map($modelDevice->getDeviceAll(), 'id', 'name'), 'action_ids' => ArrayHelper::map($modelAction->getActionAll(), 'id', 'name')]);
     }
 }
 public function getChartData()
 {
     /*echo('getChartDateFromTo<pre>');
     		print_r($this->getChartDateFromTo());
     		echo('</pre>');
     		echo('$this->device_id: ' . $this->device_id) . '<br/>' . PHP_EOL;
     		echo('$this->action_id: ' . $this->action_id) . '<br/>' . PHP_EOL;
     		echo('$this->getChartIntervalGroupBy(): ' . $this->getChartIntervalGroupBy()) . '<br/>' . PHP_EOL;*/
     /*$tasks = Task::find()
     		->select([
     			'id',
     			'from_device_id',
     			'to_device_id',
     			'action_id',
     			'data',
     			'created_at',
     			"SUBSTRING_INDEX(data, ';', 1) AS temp",
     			"SUBSTRING_INDEX(SUBSTRING_INDEX(data, ';', 2), ';', -1) AS hum",
     			"AVG(SUBSTRING_INDEX(data, ';', 1)) AS avgTemp",
     			"AVG(SUBSTRING_INDEX(SUBSTRING_INDEX(data, ';', 2), ';', -1)) AS avgHum",
     		])
     		->where([
     			'from_device_id' => '1',
     			'to_device_id' => $this->device_id,
     			'action_id' => $this->action_id,
     		])
     		->andwhere(['between', 'created_at', $this->getChartDateFromTo()['from'], $this->getChartDateFromTo()['to']])
     		->groupBy($this->getChartIntervalGroupBy())
     		->orderBy('created_at')
     		->asArray()
     		->all();*/
     $taskmodel = new Task();
     $devicemodel = new Device();
     $tasks = $taskmodel->getTaskBetweenDate($this->getChartDateFromTo(), $devicemodel->getDeviceMaster()[0]['id'], $this->device_id, $this->action_id);
     /*echo('$tasks: <pre>');
     		print_r($tasks);
     		echo('</pre>');*/
     //echo('date(Y-m-d 00:00:00);: ' . date('Y-m-d')) . '<br/>' . PHP_EOL;
     /*echo('$this->getChartDateFromTo():<pre>');
     		print_r($this->getChartDateFromTo());
     		echo('</pre>');*/
     //SUBSTRING_INDEX(`data`, `;`, 1) as temp)
     /*echo('$tasks<pre>');
     		print_r($tasks);
     		echo('</pre>');*/
     /*
     * chart: {
                 type: 'line'
             },
             title: {
                 text: 'Fruit Consumption'
             },
             xAxis: {
                 categories: ['Apples', 'Bananas', 'Oranges']
             },
             yAxis: {
                 title: {
                     text: 'Fruit eaten'
                 }
             },
             series: [{
                 name: 'Jane',
                 data: [1, 0, 4]
             }, {
                 name: 'John',
                 data: [5, 7, 3]
             }]
     */
     $chart = ['chart' => ['type' => $this->chart_type], 'title' => ['text' => 'Temperature / Humidity ' . $this->getChartDate()[$this->chart_date]]];
     $xAxis = [];
     $yAxis = [['title' => ['text' => 'Temperature'], 'labels' => ['format' => '{value}']], ['title' => ['text' => 'Humidity'], 'labels' => ['format' => '{value}'], 'opposite' => true]];
     /*echo('$yAxis<pre>');
     		print_r($yAxis);
     		echo('</pre>');*/
     $series = [];
     //$series[] = ['name' => 'Temperature', 'data' => []];
     //$series[] = ['name' => 'Humidity', 'data' => []];
     $series = [['yAxis' => 0, 'name' => 'Temperature', 'data' => array()], ['yAxis' => 1, 'name' => 'Humidity', 'data' => array()]];
     foreach ($tasks as $key => $task) {
         $xAxis['categories'][] = date('H', strtotime($task['created_at']));
         //$series[0]['data'][] = $task['avgTemp'];
         $series[0]['data'][] = number_format((double) $task['data']['t'], 2, '.', '');
         //$series[1]['data'][] = $task['avgHum'];
         $series[1]['data'][] = number_format((double) $task['data']['h'], 2, '.', '');
     }
     // create from the data a string (for highcharts to read the values good, its a javascript thing)
     //$series[0]['data'] = '[' . implode(',', $series[0]['data']) . ']';
     //$series[1]['data'] = '[' . implode(',', $series[1]['data']) . ']';
     /*echo('$xAxis<pre>');
     		print_r($xAxis);
     		echo('</pre>');*/
     /*echo('$series<pre>');
     		print_r($series);
     		echo('</pre>');*/
     /*$options = array_merge($chart, array('xAxis' => $xAxis), array('yAxis' => $yAxis), array('series' => $series));
     		echo('$options<pre>');
     		print_r($options);
     		echo('</pre>');*/
     return [$chart, $xAxis, $yAxis, $series];
 }