コード例 #1
0
 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)]);
 }
コード例 #2
0
ファイル: AppController.php プロジェクト: alxkolm/php-selftop
 /**
  * Expose data to Javascript
  * @throws \yii\base\InvalidConfigException
  */
 public function exposeData()
 {
     $searchModel = new WindowSearch();
     $searchModel->date = date('Y-m-d');
     $dataProvider = $searchModel->search(Yii::$app->request->post());
     // eagerly load process info
     $dataProvider->query->with('process');
     $from = strtotime('today', $searchModel->timestamp);
     $to = strtotime('tomorrow', $searchModel->timestamp);
     $processList = StatsHelper::getProcessList($from, $to);
     $this->exposeToJs('dashboardProcess', $processList);
     $timeline = StatsHelper::timeline($from, $to);
     $this->exposeToJs('dashboardTimeline', $timeline);
     //        $this->view->registerAssetBundle(ColorStripAsset::className());
     // Durations split by process
     $durations = StatsHelper::getProcessWindowHierarchy($from, $to);
     $this->exposeToJs('dashboardDurations', $durations);
     //        $this->view->registerAssetBundle(SunburstAsset::className());
     // Durations split by task
     $durations = StatsHelper::getTaskWindowHierarchy($from, $to);
     $this->exposeToJs('dashboardTaskDurations', $durations);
     // Keys
     $keysActivity = StatsHelper::keysActivity($from, $to);
     $this->exposeToJs('dashboardKeys', $keysActivity);
     $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->exposeToJs('dashboardTasks', $tasks);
     $this->view->registerAssetBundle(DashboardAsset::className());
     // Transition matrix
     $transitionMatrix = StatsHelper::transitionMatrix($from, $to, 30000);
     $windows = StatsHelper::windows($from, $to);
     $windowList = StatsHelper::windowsList($windows);
     $links = $transitionMatrix->flatten(Matrix::FLATTEN_MATRIX_BY_ID);
     $clusters = $transitionMatrix->clusterization()->mapToClusters(array_values(ArrayHelper::map($windowList, 'id', 'id')));
     foreach ($windowList as $key => &$w) {
         $w['cluster'] = (int) $clusters[$key];
     }
     $this->exposeToJs('dashboardWindows', $windowList);
     $this->exposeToJs('dashboardLinks', $links);
     $this->view->registerAssetBundle(D3TipAsset::className());
     //        $graphJson = AlchemyHelper::buildData($transitionMatrix, $windows, $winIdCluster);
     //
     //        $this->view->registerJs(
     //            'var dashboardGraphJson = ' . json_encode($graphJson),
     //            View::POS_HEAD);
 }