| <?php |
|
|
| namespace Kanboard\Model; |
|
|
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class ProjectDailyColumnStatsModel extends Base |
| { |
| |
| |
| |
| |
| |
| const TABLE = 'project_daily_column_stats'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function updateTotals($project_id, $date) |
| { |
| $this->db->startTransaction(); |
| $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('day', $date)->remove(); |
|
|
| foreach ($this->getStatsByColumns($project_id) as $column_id => $column) { |
| $this->db->table(self::TABLE)->insert(array( |
| 'day' => $date, |
| 'project_id' => $project_id, |
| 'column_id' => $column_id, |
| 'total' => $column['total'], |
| 'score' => $column['score'], |
| )); |
| } |
|
|
| $this->db->closeTransaction(); |
|
|
| return true; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function countDays($project_id, $from, $to) |
| { |
| return $this->db->table(self::TABLE) |
| ->eq('project_id', $project_id) |
| ->gte('day', $from) |
| ->lte('day', $to) |
| ->findOneColumn('COUNT(DISTINCT day)'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getAggregatedMetrics($project_id, $from, $to, $field = 'total') |
| { |
| $columns = $this->columnModel->getList($project_id); |
| $metrics = $this->getMetrics($project_id, $from, $to); |
| return $this->buildAggregate($metrics, $columns, $field); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getMetrics($project_id, $from, $to) |
| { |
| return $this->db->table(self::TABLE) |
| ->eq('project_id', $project_id) |
| ->gte('day', $from) |
| ->lte('day', $to) |
| ->asc(self::TABLE.'.day') |
| ->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private function buildAggregate(array &$metrics, array &$columns, $field) |
| { |
| $column_ids = array_keys($columns); |
| $days = array_unique(array_column($metrics, 'day')); |
| $rows = array(array_merge(array(e('Date')), array_values($columns))); |
|
|
| foreach ($days as $day) { |
| $rows[] = $this->buildRowAggregate($metrics, $column_ids, $day, $field); |
| } |
|
|
| return $rows; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private function buildRowAggregate(array &$metrics, array &$column_ids, $day, $field) |
| { |
| $row = array($day); |
|
|
| foreach ($column_ids as $column_id) { |
| $row[] = $this->findValueInMetrics($metrics, $day, $column_id, $field); |
| } |
|
|
| return $row; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private function findValueInMetrics(array &$metrics, $day, $column_id, $field) |
| { |
| foreach ($metrics as $metric) { |
| if ($metric['day'] === $day && $metric['column_id'] == $column_id) { |
| return (int) $metric[$field]; |
| } |
| } |
|
|
| return 0; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| private function getStatsByColumns($project_id) |
| { |
| $totals = $this->getTotalByColumns($project_id); |
| $scores = $this->getScoreByColumns($project_id); |
| $columns = array(); |
|
|
| foreach ($totals as $column_id => $total) { |
| $columns[$column_id] = array('total' => $total, 'score' => 0); |
| } |
|
|
| foreach ($scores as $column_id => $score) { |
| $columns[$column_id]['score'] = (int) $score; |
| } |
|
|
| return $columns; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| private function getScoreByColumns($project_id) |
| { |
| $stats = $this->db->table(TaskModel::TABLE) |
| ->columns('column_id', 'SUM(score) AS score') |
| ->eq('project_id', $project_id) |
| ->eq('is_active', TaskModel::STATUS_OPEN) |
| ->notNull('score') |
| ->groupBy('column_id') |
| ->findAll(); |
|
|
| return array_column($stats, 'score', 'column_id'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| private function getTotalByColumns($project_id) |
| { |
| $stats = $this->db->table(TaskModel::TABLE) |
| ->columns('column_id', 'COUNT(*) AS total') |
| ->eq('project_id', $project_id) |
| ->in('is_active', $this->getTaskStatusConfig()) |
| ->groupBy('column_id') |
| ->findAll(); |
|
|
| return array_column($stats, 'total', 'column_id'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| private function getTaskStatusConfig() |
| { |
| if ($this->configModel->get('cfd_include_closed_tasks') == 1) { |
| return array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED); |
| } |
|
|
| return array(TaskModel::STATUS_OPEN); |
| } |
| } |
|
|