aboutsummaryrefslogtreecommitdiff
path: root/app/Models/StatsDAOSQLite.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 16:18:26 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 16:18:26 +0200
commit799bb6e0de68f5dddde53a6ea7178a518d16cbfa (patch)
treeb8b7b63edae7b9f7553a5df15f2c53c002b26fb5 /app/Models/StatsDAOSQLite.php
parent6dfbc28042c6e18da9c7578ed626064a4d8c7cb3 (diff)
parentcaf98a6468dcea5ae8c38062e4eb527cb3667db9 (diff)
Merge branch 'hotfixes' into beta
Conflicts: CHANGELOG README.fr.md README.md constants.php
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}";