aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-09-27 23:35:39 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-09-27 23:35:39 +0200
commitdbc68590da1d95c249f780e2d3ff4707f6f504e9 (patch)
tree6dac2afd76362d434f6c763d97cc32b94e9b81f8 /app/Models
parent90164df068783f32fee9ca445c99b340004a13c7 (diff)
A bit more PostgreSQL
Simplified statistics https://github.com/FreshRSS/FreshRSS/pull/1250
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/StatsDAO.php30
-rw-r--r--app/Models/StatsDAOPGSQL.php125
-rw-r--r--app/Models/StatsDAOSQLite.php2
3 files changed, 16 insertions, 141 deletions
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
index e6998a6d7..fa682f488 100644
--- a/app/Models/StatsDAO.php
+++ b/app/Models/StatsDAO.php
@@ -41,8 +41,8 @@ SELECT COUNT(1) AS total,
COUNT(1) - SUM(e.is_read) AS count_unreads,
SUM(e.is_read) AS count_reads,
SUM(e.is_favorite) AS count_favorites
-FROM {$this->prefix}entry AS e
-, {$this->prefix}feed AS f
+FROM `{$this->prefix}entry` AS e
+, `{$this->prefix}feed` AS f
WHERE e.id_feed = f.id
{$filter}
SQL;
@@ -68,7 +68,7 @@ SQL;
$sql = <<<SQL
SELECT FLOOR((date - {$midnight}) / 86400) AS day,
COUNT(*) as count
-FROM {$this->prefix}entry
+FROM `{$this->prefix}entry`
WHERE date >= {$oldest} AND date < {$midnight}
GROUP BY day
ORDER BY day ASC
@@ -138,7 +138,7 @@ SQL;
$sql = <<<SQL
SELECT DATE_FORMAT(FROM_UNIXTIME(e.date), '{$period}') AS period
, COUNT(1) AS count
-FROM {$this->prefix}entry AS e
+FROM `{$this->prefix}entry` AS e
{$restrict}
GROUP BY period
ORDER BY period ASC
@@ -202,7 +202,7 @@ SQL;
SELECT COUNT(1) AS count
, MIN(date) AS date_min
, MAX(date) AS date_max
-FROM {$this->prefix}entry AS e
+FROM `{$this->prefix}entry` AS e
{$restrict}
SQL;
$stm = $this->bd->prepare($sql);
@@ -246,8 +246,8 @@ SQL;
$sql = <<<SQL
SELECT c.name AS label
, COUNT(f.id) AS data
-FROM {$this->prefix}category AS c,
-{$this->prefix}feed AS f
+FROM `{$this->prefix}category` AS c,
+`{$this->prefix}feed` AS f
WHERE c.id = f.category
GROUP BY label
ORDER BY data DESC
@@ -269,9 +269,9 @@ SQL;
$sql = <<<SQL
SELECT c.name AS label
, COUNT(e.id) AS data
-FROM {$this->prefix}category AS c,
-{$this->prefix}feed AS f,
-{$this->prefix}entry AS e
+FROM `{$this->prefix}category` AS c,
+`{$this->prefix}feed` AS f,
+`{$this->prefix}entry` AS e
WHERE c.id = f.category
AND f.id = e.id_feed
GROUP BY label
@@ -295,9 +295,9 @@ SELECT f.id AS id
, MAX(f.name) AS name
, MAX(c.name) AS category
, COUNT(e.id) AS count
-FROM {$this->prefix}category AS c,
-{$this->prefix}feed AS f,
-{$this->prefix}entry AS e
+FROM `{$this->prefix}category` AS c,
+`{$this->prefix}feed` AS f,
+`{$this->prefix}entry` AS e
WHERE c.id = f.category
AND f.id = e.id_feed
GROUP BY f.id
@@ -320,8 +320,8 @@ SELECT MAX(f.id) as id
, MAX(f.name) AS name
, MAX(date) AS last_date
, COUNT(*) AS nb_articles
-FROM {$this->prefix}feed AS f,
-{$this->prefix}entry AS e
+FROM `{$this->prefix}feed` AS f,
+`{$this->prefix}entry` AS e
WHERE f.id = e.id_feed
GROUP BY f.id
ORDER BY name
diff --git a/app/Models/StatsDAOPGSQL.php b/app/Models/StatsDAOPGSQL.php
index 0bde72e58..649dfa8b5 100644
--- a/app/Models/StatsDAOPGSQL.php
+++ b/app/Models/StatsDAOPGSQL.php
@@ -3,94 +3,6 @@
class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO {
/**
- * Calculates entry repartition for the selection.
- * The repartition includes:
- * - total entries
- * - read entries
- * - unread entries
- * - favorite entries
- *
- * @param null|integer $feed feed id
- * @param boolean $only_main
- * @return array
- */
- public function calculateEntryRepartitionPerFeed($feed = null, $only_main = false) {
- $filter = '';
- if ($only_main) {
- $filter .= 'AND f.priority = 10';
- }
- if (!is_null($feed)) {
- $filter .= "AND e.id_feed = {$feed}";
- }
- $sql = <<<SQL
-SELECT COUNT(1) AS total,
-COUNT(1) - SUM(case when e.is_read then 1 else 0 end) AS unread,
-SUM(case when e.is_read then 1 else 0 end) AS read,
-SUM(case when e.is_favorite then 1 else 0 end) AS favorite
-FROM "{$this->prefix}entry" AS e
-, "{$this->prefix}feed" AS f
-WHERE e.id_feed = f.id
-{$filter}
-SQL;
- $stm = $this->bd->prepare($sql);
- $stm->execute();
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
-
- return $res[0];
- }
-
- /**
- * Calculates entry count per day on a 30 days period.
- * Returns the result as a JSON string.
- *
- * @return string
- */
- public function calculateEntryCount() {
- $count = $this->initEntryCountArray();
- $period = self::ENTRY_COUNT_PERIOD;
-
- // Get stats per day for the last 30 days
- $sql = <<<SQL
-SELECT to_timestamp(e.date) - NOW() AS day,
-COUNT(1) AS count
-FROM "{$this->prefix}entry" AS e
-WHERE to_timestamp(e.date) BETWEEN NOW() - INTERVAL '{$period} DAYS' AND NOW() - INTERVAL '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[$value['day']] = (int) $value['count'];
- }
-
- 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 to_timestamp(e.date) BETWEEN NOW() - INTERVAL '{$period} DAYS' AND NOW() - INTERVAL '1 DAY'
-SQL;
- $stm = $this->bd->prepare($sql);
- $stm->execute();
- $res = $stm->fetch(PDO::FETCH_NAMED);
-
- return round($res['average'], 2);
- }
-
- /**
* Calculates the number of article per hour of the day per feed
*
* @param integer $feed id
@@ -152,41 +64,4 @@ SQL;
return $this->convertToSerie($repartition);
}
- /**
- * Calculates the average number of article per feed
- *
- * @param float $period number used to divide the number of day in the period
- * @param integer $feed id
- * @return integer
- */
- protected function calculateEntryAveragePerFeedPerPeriod($period, $feed = null) {
- $restrict = '';
- if ($feed) {
- $restrict = "WHERE e.id_feed = {$feed}";
- }
- $sql = <<<SQL
-SELECT COUNT(1) AS count
-, MIN(date) AS date_min
-, MAX(date) AS date_max
-FROM "{$this->prefix}entry" AS e
-{$restrict}
-SQL;
- $stm = $this->bd->prepare($sql);
- $stm->execute();
- $res = $stm->fetch(PDO::FETCH_NAMED);
- $date_min = new \DateTime();
- $date_min->setTimestamp($res['date_min']);
- $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 $res['count'] / ($interval_in_days / $period);
- }
-
}
diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php
index e09d18c77..ec0cfa81a 100644
--- a/app/Models/StatsDAOSQLite.php
+++ b/app/Models/StatsDAOSQLite.php
@@ -11,7 +11,7 @@ class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO {
$sql = <<<SQL
SELECT strftime('{$period}', e.date, 'unixepoch') AS period
, COUNT(1) AS count
-FROM {$this->prefix}entry AS e
+FROM `{$this->prefix}entry` AS e
{$restrict}
GROUP BY period
ORDER BY period ASC