public function actionDashboard()
 {
     $searchModel = new WindowSearch();
     $searchModel->dateFrom = date('Y-m-d');
     $searchModel->dateTo = date('Y-m-d');
     $dataProvider = $searchModel->search(Yii::$app->request->post());
     // eagerly load process info
     $dataProvider->query->with('process');
     $from = strtotime('today', $searchModel->timestampFrom);
     $to = strtotime('tomorrow', $searchModel->timestampTo);
     $processList = StatsHelper::getProcessList($from, $to);
     $this->view->registerJs('var dashboardProcess = ' . json_encode($processList), View::POS_HEAD);
     $timeline = StatsHelper::timeline($from, $to);
     $this->view->registerJs('var dashboardTimeline = ' . json_encode($timeline), View::POS_HEAD);
     $this->view->registerAssetBundle(ColorStripAsset::className());
     // Durations split by process
     $durations = StatsHelper::getProcessWindowHierarchy($from, $to);
     $this->view->registerJs('var dashboardDurations = ' . json_encode($durations), View::POS_HEAD);
     $this->view->registerAssetBundle(SunburstAsset::className());
     // Durations split by task
     $durations = StatsHelper::getTaskWindowHierarchy($from, $to);
     $this->view->registerJs('var dashboardTaskDurations = ' . json_encode($durations), View::POS_HEAD);
     // Keys
     $keysActivity = StatsHelper::keysActivity($from, $to);
     $this->view->registerJs('var dashboardKeys = ' . json_encode($keysActivity), View::POS_HEAD);
     $this->view->registerAssetBundle(KeysAsset::className());
     $this->view->registerAssetBundle(KeysAreaAsset::className());
     $this->clusterChart($searchModel);
     $tasks = array_map(function ($task) {
         return ['id' => $task->id, 'name' => $task->name];
     }, Task::find()->all());
     $this->view->registerJs('var dashboardTasks = ' . json_encode($tasks), View::POS_HEAD);
     $this->view->registerAssetBundle(DashboardAsset::className());
     return $this->render('dashboard', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'totalActivity' => StatsHelper::totalActivity($from, $to)]);
 }
Example #2
0
 /**
  * Action for data
  * @param array $fields
  * @return array
  * @throws BadRequestHttpException
  */
 public function actionData($fields = [])
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $filter = new DateFilterForm();
     $reply = [];
     if (Yii::$app->request->isPost && $filter->load(Yii::$app->request->bodyParams, '') && $filter->validate()) {
         $from = strtotime('today', $filter->date ? $filter->date : time());
         $to = strtotime('tomorrow', $filter->date ? $filter->date : time());
         $reply = ['processList' => StatsHelper::getProcessList($from, $to)];
         if (empty($fields) || in_array('timeLine', $fields)) {
             $reply['timeLine'] = StatsHelper::timeline($from, $to);
         }
         if (empty($fields) || in_array('durationProcess', $fields)) {
             $reply['durationProcess'] = StatsHelper::getProcessWindowHierarchy($from, $to);
         }
         if (empty($fields) || in_array('durationTask', $fields)) {
             $reply['durationTask'] = StatsHelper::getTaskWindowHierarchy($from, $to);
         }
         if (empty($fields) || in_array('keys', $fields)) {
             $reply['keys'] = StatsHelper::keysActivity($from, $to);
         }
         if (empty($fields) || in_array('durationCluster', $fields)) {
             $clusterData = $this->clusterData($from, $to);
             $reply['clusterList'] = $clusterData['clusters'];
             $reply['durationCluster'] = $clusterData['durations'];
         }
     } else {
         throw new BadRequestHttpException();
     }
     return $reply;
 }