diff options
Diffstat (limited to 'app/Analytic')
-rw-r--r-- | app/Analytic/EstimatedTimeComparisonAnalytic.php | 50 | ||||
-rw-r--r-- | app/Analytic/TaskDistributionAnalytic.php | 48 | ||||
-rw-r--r-- | app/Analytic/UserDistributionAnalytic.php | 56 |
3 files changed, 154 insertions, 0 deletions
diff --git a/app/Analytic/EstimatedTimeComparisonAnalytic.php b/app/Analytic/EstimatedTimeComparisonAnalytic.php new file mode 100644 index 00000000..490bcd50 --- /dev/null +++ b/app/Analytic/EstimatedTimeComparisonAnalytic.php @@ -0,0 +1,50 @@ +<?php + +namespace Kanboard\Analytic; + +use Kanboard\Core\Base; +use Kanboard\Model\Task; + +/** + * Estimated/Spent Time Comparison + * + * @package analytic + * @author Frederic Guillot + */ +class EstimatedTimeComparisonAnalytic extends Base +{ + /** + * Build report + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function build($project_id) + { + $rows = $this->db->table(Task::TABLE) + ->columns('SUM(time_estimated) AS time_estimated', 'SUM(time_spent) AS time_spent', 'is_active') + ->eq('project_id', $project_id) + ->groupBy('is_active') + ->findAll(); + + $metrics = array( + 'open' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ), + 'closed' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ), + ); + + foreach ($rows as $row) { + $key = $row['is_active'] == Task::STATUS_OPEN ? 'open' : 'closed'; + $metrics[$key]['time_spent'] = $row['time_spent']; + $metrics[$key]['time_estimated'] = $row['time_estimated']; + } + + return $metrics; + } +} diff --git a/app/Analytic/TaskDistributionAnalytic.php b/app/Analytic/TaskDistributionAnalytic.php new file mode 100644 index 00000000..614c5f72 --- /dev/null +++ b/app/Analytic/TaskDistributionAnalytic.php @@ -0,0 +1,48 @@ +<?php + +namespace Kanboard\Analytic; + +use Kanboard\Core\Base; + +/** + * Task Distribution + * + * @package analytic + * @author Frederic Guillot + */ +class TaskDistributionAnalytic extends Base +{ + /** + * Build report + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function build($project_id) + { + $metrics = array(); + $total = 0; + $columns = $this->board->getColumns($project_id); + + foreach ($columns as $column) { + $nb_tasks = $this->taskFinder->countByColumnId($project_id, $column['id']); + $total += $nb_tasks; + + $metrics[] = array( + 'column_title' => $column['title'], + 'nb_tasks' => $nb_tasks, + ); + } + + if ($total === 0) { + return array(); + } + + foreach ($metrics as &$metric) { + $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2); + } + + return $metrics; + } +} diff --git a/app/Analytic/UserDistributionAnalytic.php b/app/Analytic/UserDistributionAnalytic.php new file mode 100644 index 00000000..e1815f9c --- /dev/null +++ b/app/Analytic/UserDistributionAnalytic.php @@ -0,0 +1,56 @@ +<?php + +namespace Kanboard\Analytic; + +use Kanboard\Core\Base; + +/** + * User Distribution + * + * @package analytic + * @author Frederic Guillot + */ +class UserDistributionAnalytic extends Base +{ + /** + * Build Report + * + * @access public + * @param integer $project_id + * @return array + */ + public function build($project_id) + { + $metrics = array(); + $total = 0; + $tasks = $this->taskFinder->getAll($project_id); + $users = $this->projectUserRole->getAssignableUsersList($project_id); + + foreach ($tasks as $task) { + $user = isset($users[$task['owner_id']]) ? $users[$task['owner_id']] : $users[0]; + $total++; + + if (! isset($metrics[$user])) { + $metrics[$user] = array( + 'nb_tasks' => 0, + 'percentage' => 0, + 'user' => $user, + ); + } + + $metrics[$user]['nb_tasks']++; + } + + if ($total === 0) { + return array(); + } + + foreach ($metrics as &$metric) { + $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2); + } + + ksort($metrics); + + return array_values($metrics); + } +} |