A free, self-hostable news aggregator…
Add an average per day for the 30 day period
Alexis Degrugilliercd88414abcff
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.phpindex 256543f37..3069be34d 100644--- a/app/Controllers/statsController.php+++ b/app/Controllers/statsController.php@@ -21,6 +21,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController {Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));$this->view->repartition = $statsDAO->calculateEntryRepartition();$this->view->count = $statsDAO->calculateEntryCount();+ $this->view->average = $statsDAO->calculateEntryAverage();$this->view->feedByCategory = $statsDAO->calculateFeedByCategory();$this->view->entryByCategory = $statsDAO->calculateEntryByCategory();$this->view->topFeed = $statsDAO->calculateTopFeed();diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.phpindex 40505ab3e..08dd4cd5c 100644--- a/app/Models/StatsDAO.php+++ b/app/Models/StatsDAO.php@@ -79,6 +79,27 @@ 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 FROM_UNIXTIME(e.date, '%Y%m%d') BETWEEN DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -{$period} DAY), '%Y%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y%m%d')+SQL;+ $stm = $this->bd->prepare($sql);+ $stm->execute();+ $res = $stm->fetch(PDO::FETCH_NAMED);++ return round($res['average'], 2);+ }+/*** Initialize an array for the entry count.*@@ -160,7 +181,7 @@ SQL;public function calculateEntryAveragePerFeedPerHour($feed = null) {return $this->calculateEntryAveragePerFeedPerPeriod(1/24, $feed);}-+/*** Calculates the average number of article per day of week per feed*@@ -180,10 +201,10 @@ SQL;public function calculateEntryAveragePerFeedPerMonth($feed = null) {return $this->calculateEntryAveragePerFeedPerPeriod(30, $feed);}-+/*** 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 integerdiff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.phpindex 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}";diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtmlindex 31185fbe3..9b19cb560 100644--- a/app/views/stats/index.phtml+++ b/app/views/stats/index.phtml@@ -93,12 +93,22 @@ function initStats() {return;}// Entry per day+ var avg = [];+ for (var i = -31; i <= 0; i++) {+ avg.push([i, <?php echo $this->average?>]);+ }Flotr.draw(document.getElementById('statsEntryPerDay'),- [<?php echo $this->count ?>],+ [{+ data: <?php echo $this->count ?>,+ bars: {horizontal: false, show: true}+ },{+ data: avg,+ lines: {show: true},+ label: <?php echo $this->average?>+ }],{grid: {verticalLines: false},- bars: {horizontal: false, show: true},- xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0},+ xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0, min: -30.75, max: -0.25},yaxis: {min: 0},mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}});