From 73ff5ec89b711791b3993f9158dc9554a623602c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 16 Jan 2016 17:01:56 -0500 Subject: Remove ProjectAnalytic class --- app/Model/ProjectAnalytic.php | 106 ---------------------------------------- app/Model/ProjectDailyStats.php | 2 +- 2 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 app/Model/ProjectAnalytic.php (limited to 'app/Model') diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php deleted file mode 100644 index 5753a5ae..00000000 --- a/app/Model/ProjectAnalytic.php +++ /dev/null @@ -1,106 +0,0 @@ - 0, - 'total_lead_time' => 0, - 'total_cycle_time' => 0, - 'avg_lead_time' => 0, - 'avg_cycle_time' => 0, - ); - - $tasks = $this->db - ->table(Task::TABLE) - ->columns('date_completed', 'date_creation', 'date_started') - ->eq('project_id', $project_id) - ->desc('id') - ->limit(1000) - ->findAll(); - - foreach ($tasks as &$task) { - $stats['count']++; - $stats['total_lead_time'] += ($task['date_completed'] ?: time()) - $task['date_creation']; - $stats['total_cycle_time'] += empty($task['date_started']) ? 0 : ($task['date_completed'] ?: time()) - $task['date_started']; - } - - $stats['avg_lead_time'] = $stats['count'] > 0 ? (int) ($stats['total_lead_time'] / $stats['count']) : 0; - $stats['avg_cycle_time'] = $stats['count'] > 0 ? (int) ($stats['total_cycle_time'] / $stats['count']) : 0; - - return $stats; - } - - /** - * Get the average time spent into each column - * - * @access public - * @param integer $project_id - * @return array - */ - public function getAverageTimeSpentByColumn($project_id) - { - $stats = array(); - $columns = $this->board->getColumnsList($project_id); - - // Get the time spent of the last move for each tasks - $tasks = $this->db - ->table(Task::TABLE) - ->columns('id', 'date_completed', 'date_moved', 'column_id') - ->eq('project_id', $project_id) - ->desc('id') - ->limit(1000) - ->findAll(); - - // Init values - foreach ($columns as $column_id => $column_title) { - $stats[$column_id] = array( - 'count' => 0, - 'time_spent' => 0, - 'average' => 0, - 'title' => $column_title, - ); - } - - // Get time spent foreach task/column and take into account the last move - foreach ($tasks as &$task) { - $sums = $this->transition->getTimeSpentByTask($task['id']); - - if (! isset($sums[$task['column_id']])) { - $sums[$task['column_id']] = 0; - } - - $sums[$task['column_id']] += ($task['date_completed'] ?: time()) - $task['date_moved']; - - foreach ($sums as $column_id => $time_spent) { - if (isset($stats[$column_id])) { - $stats[$column_id]['count']++; - $stats[$column_id]['time_spent'] += $time_spent; - } - } - } - - // Calculate average for each column - foreach ($columns as $column_id => $column_title) { - $stats[$column_id]['average'] = $stats[$column_id]['count'] > 0 ? (int) ($stats[$column_id]['time_spent'] / $stats[$column_id]['count']) : 0; - } - - return $stats; - } -} diff --git a/app/Model/ProjectDailyStats.php b/app/Model/ProjectDailyStats.php index e79af372..12fecbe6 100644 --- a/app/Model/ProjectDailyStats.php +++ b/app/Model/ProjectDailyStats.php @@ -29,7 +29,7 @@ class ProjectDailyStats extends Base { $this->db->startTransaction(); - $lead_cycle_time = $this->projectAnalytic->getAverageLeadAndCycleTime($project_id); + $lead_cycle_time = $this->averageLeadCycleTimeAnalytic->build($project_id); $exists = $this->db->table(ProjectDailyStats::TABLE) ->eq('day', $date) -- cgit v1.2.3