From 0965aecefef0fa1e67e649d24c6d4b3ba0e143c1 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 29 Sep 2014 18:57:40 -0400 Subject: Add string delimiters for averages. Before, if the average was equal to 0, it was displayed on the graph but the label was not displayed. Now, the label is displayed. Conflicts: app/views/stats/index.phtml --- app/views/stats/index.phtml | 9 ++++++++- app/views/stats/repartition.phtml | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'app/views/stats') diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtml index 412e77e16..bbdcfaec8 100644 --- a/app/views/stats/index.phtml +++ b/app/views/stats/index.phtml @@ -92,7 +92,14 @@ function initStats() { } // Entry per day Flotr.draw(document.getElementById('statsEntryPerDay'), - [count ?>], + [{ + data: count ?>, + bars: {horizontal: false, show: true} + },{ + data: avg, + lines: {show: true}, + label: "average?>" + }], { grid: {verticalLines: false}, bars: {horizontal: false, show: true}, diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml index b425c1458..750a3ffdc 100644 --- a/app/views/stats/repartition.phtml +++ b/app/views/stats/repartition.phtml @@ -67,7 +67,7 @@ function initStats() { }, { data: avg_h, lines: {show: true}, - label: averageHour?>, + label: "averageHour?>", yaxis: 2 }], { @@ -96,7 +96,7 @@ function initStats() { }, { data: avg_dow, lines: {show: true}, - label: averageDayOfWeek?>, + label: "averageDayOfWeek?>", yaxis: 2 }], { @@ -126,7 +126,7 @@ function initStats() { }, { data: avg_m, lines: {show: true}, - label: averageMonth?>, + label: "averageMonth?>", yaxis: 2 }], { -- cgit v1.2.3 From 57d4914bf81f3380fe55fa06b7b312f1c463e3e3 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 29 Sep 2014 18:54:03 -0400 Subject: Add an average per day for the 30 day period Conflicts: app/views/stats/index.phtml --- app/Controllers/statsController.php | 1 + app/Models/StatsDAO.php | 27 ++++++++++++++++++++++++--- app/Models/StatsDAOSQLite.php | 23 +++++++++++++++++++++++ app/views/stats/index.phtml | 7 +++++-- 4 files changed, 53 insertions(+), 5 deletions(-) (limited to 'app/views/stats') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 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.php index 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 = <<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 integer 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 = <<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.phtml index bbdcfaec8..37803f2f9 100644 --- a/app/views/stats/index.phtml +++ b/app/views/stats/index.phtml @@ -91,6 +91,10 @@ function initStats() { return; } // Entry per day + var avg = []; + for (var i = -31; i <= 0; i++) { + avg.push([i, average?>]); + } Flotr.draw(document.getElementById('statsEntryPerDay'), [{ data: count ?>, @@ -102,8 +106,7 @@ function initStats() { }], { 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);}} }); -- cgit v1.2.3 From 8a09958281e7a4352c86d5734cbc9c6dc90b3c96 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 29 Sep 2014 18:26:28 -0400 Subject: Add percent of total on top 10 feeds --- app/i18n/en.php | 1 + app/i18n/fr.php | 1 + app/views/stats/index.phtml | 2 ++ 3 files changed, 4 insertions(+) (limited to 'app/views/stats') diff --git a/app/i18n/en.php b/app/i18n/en.php index beba02c4d..0d3654744 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -56,6 +56,7 @@ return array ( 'stats_entry_per_hour' => 'Per hour', 'stats_entry_per_day_of_week' => 'Per day of week', 'stats_entry_per_month' => 'Per month', + 'stats_percent_of_total' => '%% of total', 'last_week' => 'Last week', 'last_month' => 'Last month', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index b0fbf15ae..c72fc3e93 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -56,6 +56,7 @@ return array ( 'stats_entry_per_hour' => 'Par heure', 'stats_entry_per_day_of_week' => 'Par jour de la semaine', 'stats_entry_per_month' => 'Par mois', + 'stats_percent_of_total' => '%% du total', 'last_week' => 'Depuis la semaine dernière', 'last_month' => 'Depuis le mois dernier', diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtml index 37803f2f9..fa57a77c0 100644 --- a/app/views/stats/index.phtml +++ b/app/views/stats/index.phtml @@ -48,6 +48,7 @@ + @@ -56,6 +57,7 @@ + repartition['all_feeds']['total'] * 100, 1);?> -- cgit v1.2.3