예제 #1
0
 public function actionIndex()
 {
     $role = new Role();
     $position = $role->getPosition();
     if (Yii::$app->user->isGuest) {
         $this->doLogin();
     }
     // search model
     $searchModel = new StationSearch();
     $parseData['searchModel'] = $searchModel;
     // get latest warning
     if ($position != Role::POSITION_ADMINISTRATOR) {
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         $condition = ['in', 'station_id', $stationIds];
         $parseData['warnings'] = Warning::getWarning('warning_time DESC', 100, [$condition]);
     } else {
         $parseData['warnings'] = Warning::getWarning('warning_time DESC', 100, []);
     }
     // get stations
     if ($position != Role::POSITION_ADMINISTRATOR) {
         $sCondition = ['in', 'id', $stationIds];
     } else {
         $sCondition = [];
     }
     // data provider
     $data = $searchModel->search(Yii::$app->request->queryParams, $sCondition);
     $parseData['stationProvider'] = $data['provider'];
     // write station locator for map
     $this->_writeStationLocator($data['query']);
     return $this->render('index', $parseData);
 }
예제 #2
0
 public function actionIndex()
 {
     // get station ids by role
     $permCondition = [];
     $role = new Role();
     if (!$role->isAdministrator) {
         $stationIds = Station::getByRole($role->getPosition(), Yii::$app->user->id);
         $permCondition['s.id'] = $stationIds;
     }
     // default time points
     $timePoints = Convert::currentTimePoints();
     // get post form data
     $get = Yii::$app->request->get('get_by');
     if ($get == 'today') {
         $timePoints = Convert::currentTimePoints();
     } else {
         if ($get == 'week') {
             $timePoints = Convert::currentWeekTimePoints();
         } else {
             if ($get == 'month') {
                 $timePoints = Convert::currentMonthTimePoints();
             }
         }
     }
     $andWhere = ['>=', 'w.warning_time', $timePoints['start']];
     $andWhere1 = ['<=', 'w.warning_time', $timePoints['end']];
     // get data
     $query = new Query();
     $warnings = $query->select('w.warning_time, s.area_id')->from('warning w')->innerJoin('station s', 'w.station_id = s.id')->where($permCondition)->andWhere($andWhere)->andWhere($andWhere1)->all();
     // data
     $parseData = [];
     $data = [];
     // get areas
     $areaQuery = new Query();
     $areas = $areaQuery->select('a.*')->from('area a')->innerJoin('station s', 's.area_id = a.id')->where($permCondition)->groupBy('a.id')->all();
     $parseData['areas'] = $areas;
     if (!empty($areas)) {
         foreach ($areas as $area) {
             $data[$area['id']]['number'] = 0;
             $data[$area['id']]['start'] = 0;
             $data[$area['id']]['end'] = 0;
             if (!empty($warnings)) {
                 $no = 1;
                 foreach ($warnings as $w) {
                     if ($w['area_id'] == $area['id']) {
                         $data[$area['id']]['number']++;
                         if ($no == 1) {
                             $data[$area['id']]['start'] = $w['warning_time'];
                             $data[$area['id']]['end'] = $w['warning_time'];
                         } else {
                             if ($w['warning_time'] < $data[$area['id']]['start']) {
                                 $data[$area['id']]['start'] = $w['warning_time'];
                             }
                             if ($w['warning_time'] > $data[$area['id']]['end']) {
                                 $data[$area['id']]['end'] = $w['warning_time'];
                             }
                         }
                         $no++;
                     }
                 }
             }
         }
     }
     $parseData['data'] = $data;
     return $this->render('warning', $parseData);
 }
예제 #3
0
 protected function findModel($id)
 {
     // session
     $role = new Role();
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         if (!empty($stationIds) && !in_array($id, $stationIds)) {
             $this->permissionDeny();
         }
     }
     if (($model = Station::findOne($id)) !== null) {
         // find area & center
         $model->area = Area::findOne($model->area_id);
         $model->center = Center::findOne($model->center_id);
         // get equipment
         $equipments = EquipmentStatus::findAll(['station_id' => $id]);
         if (!empty($equipments)) {
             foreach ($equipments as $equipment) {
                 $model->equipment[] = $equipment->equipment_id;
             }
         }
         // get power equipment
         $powerEquipments = PowerStatus::findAll(['station_id' => $id]);
         if (!empty($powerEquipments)) {
             foreach ($powerEquipments as $equipment) {
                 $model->power_equipment[] = $equipment->item_id;
             }
         }
         // get dc
         $dcEquips = DcEquipmentStatus::findByStation($id);
         if (!empty($dcEquips)) {
             foreach ($dcEquips as $dcEquip) {
                 $model->dc_equip_ids[] = $dcEquip['equipment_id'];
                 $model->dc_equip_status[] = ['equipment_id' => $dcEquip['equipment_id'], 'name' => $dcEquip['name'], 'amperage' => $dcEquip['amperage'], 'voltage' => $dcEquip['voltage'], 'unit_voltage' => $dcEquip['unit_voltage'], 'temperature' => $dcEquip['temperature'], 'unit_amperage' => $dcEquip['unit_amperage'], 'status' => $dcEquip['status']];
             }
         }
         // get sensor status
         $query = new Query();
         $sensorStatus = $query->select('sst.*, s.type, s.unit_type, s.name')->from('sensor_status sst')->leftJoin('sensor s', 's.id = sst.sensor_id')->where(['sst.station_id' => $id])->andWhere(['s.active' => Sensor::STATUS_ACTIVE])->all();
         if (!empty($sensorStatus)) {
             foreach ($sensorStatus as $sst) {
                 $model->sensor_status[] = ['type' => $sst['type'], 'sensor_id' => $sst['sensor_id'], 'name' => $sst['name'], 'unit' => $sst['unit_type'], 'value' => $sst['value'], 'status' => $sst['status']];
             }
         }
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 public function actionCronUnread()
 {
     $html = '';
     $count = 0;
     $post = Yii::$app->request->post();
     // permission
     $role = new Role();
     $condition = [];
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         $condition[] = ['in', 'station_id', $stationIds];
     }
     $condition[] = ['=', 'read', Warning::STATUS_UNREAD];
     $warnings = Warning::getWarning('warning_time DESC', 0, $condition);
     if (!empty($warnings)) {
         $count = count($warnings);
         $html = Show::warningsTable($warnings);
     }
     $data['html'] = $html;
     $data['count'] = $count;
     print json_encode($data);
 }
예제 #5
0
 public function actionIndex()
 {
     // default time duration
     $timePoints = Convert::currentTimePoints();
     $getBy = Yii::$app->request->get('get_by');
     if ($getBy == 'week') {
         $timePoints = Convert::currentWeekTimePoints();
     } else {
         if ($getBy == 'month') {
             $timePoints = Convert::currentMonthTimePoints();
         }
     }
     $whereClause = ['sst.sensor_id' => Sensor::ID_SECURITY];
     // get station ids by role
     $role = new Role();
     if (!$role->isAdministrator) {
         $position = $role->getPosition();
         $stationIds = Station::getByRole($position, Yii::$app->user->id);
         $whereClause['s.id'] = $stationIds;
     }
     // get data
     $query = new Query();
     $stations = $query->select('s.area_id, s.status AS station_status, sst.value AS sensor_value, count(w.id) AS total_warning, max(w.warning_time) AS last_warning_time')->from('station s')->leftJoin('sensor_status sst', 'sst.station_id = s.id')->leftJoin('warning w', 'w.station_id = s.id')->where($whereClause)->groupBy('s.id')->all();
     // data
     $parseData = [];
     $data = [];
     // get areas
     $areas = Area::find()->all();
     $parseData['areas'] = $areas;
     if (!empty($areas)) {
         $notHave = [];
         foreach ($areas as $area) {
             $have = 0;
             $data[$area['id']]['has_warning'] = 0;
             $data[$area['id']]['no_warning'] = 0;
             $data[$area['id']]['security_on'] = 0;
             $data[$area['id']]['security_off'] = 0;
             $data[$area['id']]['connected'] = 0;
             $data[$area['id']]['lost_connect'] = 0;
             $data[$area['id']]['last_warning_time'] = 0;
             // security and connect stations
             if (!empty($stations)) {
                 foreach ($stations as $station) {
                     if ($station['area_id'] == $area['id']) {
                         $have = 1;
                         // warnings
                         if ($station['total_warning'] > 0 && $station['last_warning_time'] >= $timePoints['start'] && $station['last_warning_time'] <= $timePoints['end']) {
                             $data[$area['id']]['has_warning']++;
                             $data[$area['id']]['last_warning_time'] = $station['last_warning_time'] > $data[$area['id']]['last_warning_time'] ? $station['last_warning_time'] : $data[$area['id']]['last_warning_time'];
                         } else {
                             $data[$area['id']]['no_warning']++;
                         }
                         // status
                         if ($station['station_status'] == Station::STATUS_CONNECTED) {
                             $data[$area['id']]['connected']++;
                         } else {
                             if ($station['station_status'] == Station::STATUS_LOST) {
                                 $data[$area['id']]['lost_connect']++;
                             }
                         }
                         // security mode
                         if ($station['sensor_value'] == Sensor::SECURITY_ON) {
                             $data[$area['id']]['security_on']++;
                         } else {
                             if ($station['sensor_value'] == Sensor::SECURITY_OFF) {
                                 $data[$area['id']]['security_off']++;
                             }
                         }
                     }
                 }
             }
             if ($have == 0) {
                 $notHave[] = $area['id'];
             }
         }
         if (!empty($notHave)) {
             foreach ($notHave as $not) {
                 unset($data[$not]);
             }
         }
     }
     $parseData['data'] = $data;
     return $this->render('station', $parseData);
 }