summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-16 19:46:23 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-16 19:46:23 -0500
commitc603cb5949eba24fc09012e8f2684f33078ed713 (patch)
tree31035c5893912d1b8a439283fd01c9067573a450
parent81e4c3199edd4e92f66fe7db6bc36d30d16ee96d (diff)
Simplify class ProjectDailyStats
-rw-r--r--app/Model/ProjectDailyStats.php39
-rw-r--r--tests/units/Model/ProjectDailyStatsTest.php5
2 files changed, 17 insertions, 27 deletions
diff --git a/app/Model/ProjectDailyStats.php b/app/Model/ProjectDailyStats.php
index 12fecbe6..957ad51d 100644
--- a/app/Model/ProjectDailyStats.php
+++ b/app/Model/ProjectDailyStats.php
@@ -31,27 +31,14 @@ class ProjectDailyStats extends Base
$lead_cycle_time = $this->averageLeadCycleTimeAnalytic->build($project_id);
- $exists = $this->db->table(ProjectDailyStats::TABLE)
- ->eq('day', $date)
- ->eq('project_id', $project_id)
- ->exists();
+ $this->db->table(self::TABLE)->eq('day', $date)->eq('project_id', $project_id)->remove();
- if ($exists) {
- $this->db->table(ProjectDailyStats::TABLE)
- ->eq('project_id', $project_id)
- ->eq('day', $date)
- ->update(array(
- 'avg_lead_time' => $lead_cycle_time['avg_lead_time'],
- 'avg_cycle_time' => $lead_cycle_time['avg_cycle_time'],
- ));
- } else {
- $this->db->table(ProjectDailyStats::TABLE)->insert(array(
- 'day' => $date,
- 'project_id' => $project_id,
- 'avg_lead_time' => $lead_cycle_time['avg_lead_time'],
- 'avg_cycle_time' => $lead_cycle_time['avg_cycle_time'],
- ));
- }
+ $this->db->table(self::TABLE)->insert(array(
+ 'day' => $date,
+ 'project_id' => $project_id,
+ 'avg_lead_time' => $lead_cycle_time['avg_lead_time'],
+ 'avg_cycle_time' => $lead_cycle_time['avg_cycle_time'],
+ ));
$this->db->closeTransaction();
@@ -70,11 +57,11 @@ class ProjectDailyStats extends Base
public function getRawMetrics($project_id, $from, $to)
{
return $this->db->table(self::TABLE)
- ->columns('day', 'avg_lead_time', 'avg_cycle_time')
- ->eq(self::TABLE.'.project_id', $project_id)
- ->gte('day', $from)
- ->lte('day', $to)
- ->asc(self::TABLE.'.day')
- ->findAll();
+ ->columns('day', 'avg_lead_time', 'avg_cycle_time')
+ ->eq('project_id', $project_id)
+ ->gte('day', $from)
+ ->lte('day', $to)
+ ->asc('day')
+ ->findAll();
}
}
diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php
index 677a97d0..9efdb199 100644
--- a/tests/units/Model/ProjectDailyStatsTest.php
+++ b/tests/units/Model/ProjectDailyStatsTest.php
@@ -18,9 +18,12 @@ class ProjectDailyStatsTest extends Base
$ts = new TaskStatus($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_started' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));
+
$pds->updateTotals(1, date('Y-m-d', strtotime('-1 day')));
$this->assertTrue($ts->close(1));