aboutsummaryrefslogtreecommitdiff
path: root/app/Models/StatsDAOSQLite.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <github@ainw.org> 2014-09-29 18:54:03 -0400
committerGravatar Alexis Degrugillier <github@ainw.org> 2014-09-29 18:54:03 -0400
commitcd88414abcffd94cfce933cf578ecc640b691381 (patch)
treebcc2166c49d7139e3ef7191abcdd7353f11d12ea /app/Models/StatsDAOSQLite.php
parent3d288eb170091c2679cac34ee09e850b56e46861 (diff)
Add an average per day for the 30 day period
Diffstat (limited to 'app/Models/StatsDAOSQLite.php')
-rw-r--r--app/Models/StatsDAOSQLite.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php
index 3b1256de1..bb2336532 100644
--- a/app/Models/StatsDAOSQLite.php
+++ b/app/Models/StatsDAOSQLite.php
@@ -34,6 +34,29 @@ SQL;
return $this->convertToSerie($count);
}
+ /**
+ * Calculates entry average per day on a 30 days period.
+ *
+ * @return integer
+ */
+ public function calculateEntryAverage() {
+ $period = self::ENTRY_COUNT_PERIOD;
+
+ // Get stats per day for the last 30 days
+ $sql = <<<SQL
+SELECT COUNT(1) / {$period} AS average
+FROM {$this->prefix}entry AS e
+WHERE strftime('%Y%m%d', e.date, 'unixepoch')
+ BETWEEN strftime('%Y%m%d', 'now', '-{$period} days')
+ AND strftime('%Y%m%d', 'now', '-1 day')
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetch(PDO::FETCH_NAMED);
+
+ return round($res['average'], 2);
+ }
+
protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) {
if ($feed) {
$restrict = "WHERE e.id_feed = {$feed}";