summaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-19 10:37:29 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-19 10:37:29 +0200
commit8731de5c3ad4eea8ae30d1f6435c569ed31b8828 (patch)
treeb1b0924420a383ef8dd15a7ca1551fbdfc70ea81 /app/Models
parent2f5304a1f7052bce1315f2ed85141568f0995e7c (diff)
Fix repartition stats with 0 or 1 article.
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/StatsDAO.php8
-rw-r--r--app/Models/StatsDAOSQLite.php1
2 files changed, 8 insertions, 1 deletions
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
index bd4271ba8..b8dc40592 100644
--- a/app/Models/StatsDAO.php
+++ b/app/Models/StatsDAO.php
@@ -209,8 +209,14 @@ SQL;
$date_max = new \DateTime();
$date_max->setTimestamp($res['date_max']);
$interval = $date_max->diff($date_min, true);
+ $interval_in_days = $interval->format('%a');
+ if ($interval_in_days <= 0) {
+ // Surely only one article.
+ // We will return count / (period/period) == count.
+ $interval_in_days = $period;
+ }
- return round($res['count'] / ($interval->format('%a') / ($period)), 2);
+ return round($res['count'] / ($interval_in_days / $period), 2);
}
/**
diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php
index 6cb54ddf6..3b1256de1 100644
--- a/app/Models/StatsDAOSQLite.php
+++ b/app/Models/StatsDAOSQLite.php
@@ -53,6 +53,7 @@ SQL;
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_NAMED);
+ $repartition = array();
foreach ($res as $value) {
$repartition[(int) $value['period']] = (int) $value['count'];
}