public function actionRemoveDevice()
 {
     while (1) {
         $deviceModel = Devices::find()->all();
         foreach ($deviceModel as $device) {
             $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
             if (empty($deviceLogs)) {
                 $device->status = 0;
                 $device->server_id = NULL;
                 if ($device->save()) {
                     echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                 } else {
                     print_r($device);
                 }
             } else {
                 $deviceTime = date("Y-m-d H:i:s", strtotime($deviceLogs->created . " +1 minute"));
                 if (strtotime($deviceTime) < strtotime(date("Y-m-d H:i:s"))) {
                     $device->status = 0;
                     $device->server_id = NULL;
                     if ($device->save()) {
                         echo date("Y-m-d H:i:s", strtotime($deviceTime)) . " = " . date("Y-m-d H:i:s") . "\n";
                         echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                     } else {
                         print_r($device->getErrors());
                     }
                 } else {
                     echo "Device with id " . $device->controller_id . " is Online. \n";
                 }
             }
         }
         sleep(10);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Devices::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'region_id' => $this->region_id, 'controller_id' => $this->controller_id, 'type' => $this->type, 'created' => $this->created]);
     $query->andFilterWhere(['like', 'latitude', $this->latitude])->andFilterWhere(['like', 'longitude', $this->longitude])->andFilterWhere(['like', 'sim_number', $this->sim_number])->andFilterWhere(['like', 'imei_number', $this->imei_number])->andFilterWhere(['like', 'contact_1_name', $this->contact_1_name])->andFilterWhere(['like', 'contact__1_phone', $this->contact__1_phone])->andFilterWhere(['like', 'contact_1_email', $this->contact_1_email])->andFilterWhere(['like', 'contact_2_name', $this->contact_2_name])->andFilterWhere(['like', 'contact_2_phone', $this->contact_2_phone])->andFilterWhere(['like', 'contact_2_email', $this->contact_2_email]);
     return $dataProvider;
 }
 /**
  *
  * @return string
  */
 public function actionAindex()
 {
     $count = Devices::find()->count();
     //        $query = (new Query())
     //            ->select('title, type_id, COUNT(devices.id) as count')
     //            ->from('device_type, devices')
     //            ->where('type_id = device_type.id')
     //            ->groupBy('type_id, title')
     //            ->orderBy('title');
     //
     //        $dp = new ActiveDataProvider([
     //            'query' => $query,
     //        ]);
     $searchModel = new ReportsSearch();
     $dp = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('a_index', ['count' => $count, 'sm' => $searchModel, 'dp' => $dp]);
 }
Exemple #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id_wp = 0, $id = 0)
 {
     if ($id > 0) {
         $query = Devices::find()->where(['parent_device_id' => $id]);
     } elseif ($id_wp > 0) {
         $query = Devices::find()->where(['workplace_id' => $id_wp]);
     } else {
         $query = Devices::find()->select(['id' => 'd.id', 'dt_title' => 'device_type.title', 'dev_comp' => 'device_type.comp', 'brand' => 'd.brand', 'model' => 'd.model', 'sn' => 'd.sn', 'specification' => 'd.specification', 'imei1' => 'd.imei1', 'parent_device_id' => 'd.parent_device_id', 'device_note' => 'd.device_note', 'workplace_id' => 'd.workplace_id', 'wp_title' => 'workplaces.workplaces_title', 'snp' => 'MAX(employees.snp)'])->from(['d' => 'devices'])->leftJoin('workplaces', 'workplaces.id = workplace_id')->leftJoin('device_type', 'device_type.id = type_id')->leftJoin('wp_owners', 'wp_owners.workplace_id = d.workplace_id')->leftJoin('employees', 'employees.id = wp_owners.employee_id')->groupBy('d.id, device_type.title, device_type.comp,	d.brand,' . 'd.model,	d.sn,	d.specification,	d.imei1,' . 'd.parent_device_id,	d.workplace_id,	workplaces.workplaces_title')->orderBy(['d.id' => SORT_DESC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => false]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //$query->joinWith('deviceType');
     $query->andFilterWhere(['d.id' => $this->id, 'd.workplace_id' => $this->workplace_id, 'device_type.comp' => $this->dev_comp]);
     $query->andFilterWhere(['like', 'LOWER(device_note)', mb_strtolower($this->device_note)])->andFilterWhere(['like', 'LOWER(device_type.title)', mb_strtolower($this->dt_title)])->andFilterWhere(['like', 'LOWER(brand)', mb_strtolower($this->brand)])->andFilterWhere(['like', 'LOWER(model)', mb_strtolower($this->model)])->andFilterWhere(['like', 'LOWER(sn)', mb_strtolower($this->sn)])->andFilterWhere(['like', 'LOWER(specification)', mb_strtolower($this->specification)])->andFilterWhere(['like', 'LOWER(imei1)', mb_strtolower($this->imei1)]);
     return $dataProvider;
 }
Exemple #5
0
 public static function arraySpecifications()
 {
     return Devices::find()->select('specification as value, specification as label, count(*) as count')->where("specification > ''")->groupBy('specification')->orderBy('count DESC')->asArray()->all();
 }
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\Devices;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$this->title = 'Device Junk Data';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="container-fluid">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title"><?php 
echo Html::encode($this->title);
?>
</h3>
        </div>
        <div class="panel-body pd-0" id="device-overview-container">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'layout' => "{items}\n{pager}", 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'device_id', 'label' => 'Controller ID', 'value' => function ($row) {
    return Devices::find()->where(['id' => $row->device_id])->one()->controller_id;
}], ['attribute' => 'device_data', 'label' => 'Device Data'], ['attribute' => 'created', 'label' => 'Logging Time']]]);
?>
        </div>
    </div>
</div>
 public function actionDeviceOverview()
 {
     $deviceModel = Devices::find()->all();
     $this->layout = "dashboard";
     $response = array();
     foreach ($deviceModel as $device) {
         $temp = array();
         $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
         $temp['id'] = $device->id;
         $temp['controller_id'] = $device->controller_id;
         $temp['sim_number'] = $device->sim_number;
         $temp['status'] = $device->status == 1 ? "Online" : "Offline";
         if (!empty($deviceLogs)) {
             $temp['current_voltage'] = $deviceLogs->current_voltage;
             $temp['current_load'] = isset($deviceLogs->current_load) ? $deviceLogs->current_load / 10 : $deviceLogs->current_load;
             $temp['voltage_status'] = Helper::voltageStatus($deviceLogs->voltage_status);
             $temp['light_status'] = Helper::lightStatus($deviceLogs->light_status);
             $temp['overload_status'] = Helper::overloadStatus($deviceLogs->overload_status);
             $temp['created'] = date("d-M-Y H:i:s", strtotime($deviceLogs->created));
         }
         $response[] = $temp;
     }
     $dataProvider = new ArrayDataProvider(['key' => 'id', 'allModels' => $response]);
     return $this->render('deviceOverview', ['dataProvider' => $dataProvider]);
 }
 public function decodeCommand($deviceId, $data)
 {
     $command_id = substr($data, 6, 2);
     $deviceModel = Devices::find()->where(['id' => $deviceId])->one();
     switch ($command_id) {
         case "01":
             break;
         case "03":
             break;
         case "02":
             $v1 = hexdec(substr($data, 8, 2));
             $v2 = hexdec(substr($data, 10, 2));
             $voltage = $v1 * 256 + $v2;
             $l1 = hexdec(substr($data, 14, 2));
             $l2 = hexdec(substr($data, 16, 2));
             $load = $l1 * 256 + $l2;
             $status = str_pad(base_convert(substr($data, 18, 2), 16, 2), 8, "0", STR_PAD_LEFT);
             $voltage_status = base_convert(substr($status, 0, 2), 2, 10);
             $light_status = base_convert(substr($status, 2, 2), 2, 10);
             $overload_staus = base_convert(substr($status, 4, 2), 2, 10);
             $deviceLogs = new DeviceLogs();
             $deviceLogs->region_id = $deviceModel->region_id;
             $deviceLogs->device_id = $deviceModel->id;
             $deviceLogs->current_voltage = $voltage;
             $deviceLogs->current_load = $load;
             $deviceLogs->voltage_status = $voltage_status;
             $deviceLogs->light_status = $light_status;
             $deviceLogs->overload_status = $overload_staus;
             if ($deviceLogs->save()) {
                 return true;
             } else {
                 echo "<pre>";
                 print_r($deviceLogs->getErrors());
                 return false;
             }
             break;
         case "04":
             break;
     }
 }
 /**
  * Автоматически добавляем комплектующие
  */
 public function actionAutocomp()
 {
     $models = Devices::findAll(['type_id' => 1]);
     $arr = [373, 363, 262, 202, 146];
     $valid = false;
     $i = 0;
     $v = 0;
     $n = 0;
     foreach ($models as $model) {
         if (in_array($model->id, $arr)) {
             continue;
         }
         $count_comp = Devices::find()->where(['parent_device_id' => $model->id])->count();
         //echo $model->id . ' ' . $count_comp . '<br>';
         if ($count_comp > 0) {
             continue;
         }
         //отсеяли лишние системники, создаем комплектующие
         $i++;
         $comp = new Devices();
         $comp->type_id = 18;
         $comp->device_note = 'Блок питания';
         $comp->workplace_id = 119;
         $comp->parent_device_id = $model->id;
         if ($comp->validate()) {
             $comp->save();
             $valid = true;
             $v++;
         }
         $comp = new Devices();
         $comp->type_id = 25;
         $comp->device_note = 'Материнская плата';
         $comp->workplace_id = 119;
         $comp->parent_device_id = $model->id;
         if ($comp->validate()) {
             $v++;
             if ($comp->save()) {
                 $net = new Netints();
                 //создаем сетевой интефейс со значениями по умолчанию
                 $net->device_id = $comp->id;
                 if ($net->validate()) {
                     $n++;
                     $net->save();
                 }
             }
         }
         $comp = new Devices();
         $comp->type_id = 28;
         $comp->device_note = 'Процессор';
         $comp->workplace_id = 119;
         $comp->parent_device_id = $model->id;
         if ($comp->validate()) {
             $comp->save();
             $v++;
         }
         $comp = new Devices();
         $comp->type_id = 29;
         $comp->device_note = 'DDR';
         $comp->workplace_id = 119;
         $comp->parent_device_id = $model->id;
         if ($comp->validate()) {
             $comp->save();
             $v++;
         }
         $comp = new Devices();
         $comp->type_id = 30;
         $comp->device_note = 'SSD';
         $comp->workplace_id = 119;
         $comp->parent_device_id = $model->id;
         if ($comp->validate()) {
             $comp->save();
             $v++;
         }
         $comp = null;
     }
     if ($valid) {
         Yii::$app->session->setFlash('success', 'Обработка прошла успешно! Добавлено ' . $v . ' устройств. ' . $n . ' сетевых интерфейсов для ' . $i . 'устройств');
     }
     return $this->redirect(['index']);
 }