Browse Source

Fix repartition stats with 0 or 1 article.

Marien Fressinaud 11 years ago
parent
commit
8731de5c3a
2 changed files with 8 additions and 1 deletions
  1. 7 1
      app/Models/StatsDAO.php
  2. 1 0
      app/Models/StatsDAOSQLite.php

+ 7 - 1
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);
 	}
 
 	/**

+ 1 - 0
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'];
 		}