Fixes cycle time calculation when the start date is defined in the future
This commit is contained in:
@@ -85,14 +85,15 @@ class AverageLeadCycleTimeAnalytic extends Base
|
||||
*/
|
||||
private function calculateCycleTime(array &$task)
|
||||
{
|
||||
if (empty($task['date_started'])) {
|
||||
return 0;
|
||||
$end = (int) $task['date_completed'] ?: time();
|
||||
$start = (int) $task['date_started'];
|
||||
|
||||
// Start date can be in the future when defined with the Gantt chart
|
||||
if ($start > 0 && $end > $start) {
|
||||
return $end - $start;
|
||||
}
|
||||
|
||||
$end = $task['date_completed'] ?: time();
|
||||
$start = $task['date_started'];
|
||||
|
||||
return $end - $start;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,12 +56,19 @@ class ProjectDailyStats extends Base
|
||||
*/
|
||||
public function getRawMetrics($project_id, $from, $to)
|
||||
{
|
||||
return $this->db->table(self::TABLE)
|
||||
$metrics = $this->db->table(self::TABLE)
|
||||
->columns('day', 'avg_lead_time', 'avg_cycle_time')
|
||||
->eq('project_id', $project_id)
|
||||
->gte('day', $from)
|
||||
->lte('day', $to)
|
||||
->asc('day')
|
||||
->findAll();
|
||||
|
||||
foreach ($metrics as &$metric) {
|
||||
$metric['avg_lead_time'] = (int) $metric['avg_lead_time'];
|
||||
$metric['avg_cycle_time'] = (int) $metric['avg_cycle_time'];
|
||||
}
|
||||
|
||||
return $metrics;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user