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)]); }
/** * 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); }
<?php /* @var $this \yii\web\View */ /* @var $content string */ use yii\helpers\Html; use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\widgets\Breadcrumbs; use app\assets\DashboardAsset; use yii\helpers\Url; DashboardAsset::register($this); $this->beginPage(); ?> <!DOCTYPE html> <html class="no-js css-menubar" lang="en" lang="<?php echo Yii::$app->language; ?> "> <head> <meta charset="<?php echo Yii::$app->charset; ?> "> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui"> <?php echo Html::csrfMetaTags(); ?> <title><?php echo Html::encode($this->title); ?>