aboutsummaryrefslogtreecommitdiff
path: root/app/Models/StatsDAOSQLite.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-20 15:39:06 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-20 15:39:06 +0200
commit73bbdaa015ec8596603fa88bd2cb03f85548e05e (patch)
tree1faa5344f86c41c1984ac0312375dfefa8706036 /app/Models/StatsDAOSQLite.php
parentb466b6075e868f24d55126308949e5f990e6a70b (diff)
parent68c0a827d221eeb398774d558f3d23b6e1c9e76c (diff)
Merge pull request #542 from aledeg/sqlite-stats
Add statistics support for Sqlite
Diffstat (limited to 'app/Models/StatsDAOSQLite.php')
-rw-r--r--app/Models/StatsDAOSQLite.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php
index c923e5fd0..dea590c92 100644
--- a/app/Models/StatsDAOSQLite.php
+++ b/app/Models/StatsDAOSQLite.php
@@ -2,8 +2,36 @@
class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
+ /**
+ * Calculates entry count per day on a 30 days period.
+ * Returns the result as a JSON string.
+ *
+ * @return string
+ */
public function calculateEntryCount() {
- return $this->convertToSerie(array()); //TODO: Implement 30-day statistics for SQLite
+ $count = $this->initEntryCountArray();
+ $period = parent::ENTRY_COUNT_PERIOD;
+
+ // Get stats per day for the last 30 days
+ $sql = <<<SQL
+SELECT round(julianday(e.date, 'unixepoch') - julianday('now')) AS day,
+COUNT(1) AS count
+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')
+GROUP BY day
+ORDER BY day ASC
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($res as $value) {
+ $count[(int)$value['day']] = (int) $value['count'];
+ }
+
+ return $this->convertToSerie($count);
}
}