summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-22 20:44:15 -0400
committerFrederic Guillot <fred@kanboard.net>2016-03-22 20:44:15 -0400
commit8768a4e3699c5b9235d8c834ad7689ae66ef36aa (patch)
tree6be77f7213fd6e3f865c3d71e4f3809cf1cac1c4 /app
parent585f73433373d8e2912c60f4ed0efab827484232 (diff)
Fixes cycle time calculation when the start date is defined in the future
Diffstat (limited to 'app')
-rw-r--r--app/Analytic/AverageLeadCycleTimeAnalytic.php13
-rw-r--r--app/Model/ProjectDailyStats.php9
2 files changed, 15 insertions, 7 deletions
diff --git a/app/Analytic/AverageLeadCycleTimeAnalytic.php b/app/Analytic/AverageLeadCycleTimeAnalytic.php
index 5a7a3c0f..62c83559 100644
--- a/app/Analytic/AverageLeadCycleTimeAnalytic.php
+++ b/app/Analytic/AverageLeadCycleTimeAnalytic.php
@@ -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'];
- $end = $task['date_completed'] ?: time();
- $start = $task['date_started'];
+ // Start date can be in the future when defined with the Gantt chart
+ if ($start > 0 && $end > $start) {
+ return $end - $start;
+ }
- return $end - $start;
+ return 0;
}
/**
diff --git a/app/Model/ProjectDailyStats.php b/app/Model/ProjectDailyStats.php
index 957ad51d..974f5813 100644
--- a/app/Model/ProjectDailyStats.php
+++ b/app/Model/ProjectDailyStats.php
@@ -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;
}
}