From f002dbe4ceb8505b237bd67b66365d636bddd4b2 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Mon, 1 Sep 2014 20:58:05 -0400 Subject: Add average on repartition charts. It needs some verification on the value used to calculate the averages. --- app/Models/StatsDAO.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'app/Models/StatsDAO.php') diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 89be76a26..bd4271ba8 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -151,6 +151,68 @@ SQL; return $this->convertToSerie($repartition); } + /** + * Calculates the average number of article per hour per feed + * + * @param integer $feed id + * @return integer + */ + public function calculateEntryAveragePerFeedPerHour($feed = null) { + return $this->calculateEntryAveragePerFeedPerPeriod(1/24, $feed); + } + + /** + * Calculates the average number of article per day of week per feed + * + * @param integer $feed id + * @return integer + */ + public function calculateEntryAveragePerFeedPerDayOfWeek($feed = null) { + return $this->calculateEntryAveragePerFeedPerPeriod(7, $feed); + } + + /** + * Calculates the average number of article per month per feed + * + * @param integer $feed id + * @return integer + */ + 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 + */ + protected function calculateEntryAveragePerFeedPerPeriod($period, $feed = null) { + if ($feed) { + $restrict = "WHERE e.id_feed = {$feed}"; + } else { + $restrict = ''; + } + $sql = <<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); + + return round($res['count'] / ($interval->format('%a') / ($period)), 2); + } + /** * Initialize an array for statistics depending on a range * -- cgit v1.2.3 From 8731de5c3ad4eea8ae30d1f6435c569ed31b8828 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Sep 2014 10:37:29 +0200 Subject: Fix repartition stats with 0 or 1 article. --- app/Models/StatsDAO.php | 8 +++++++- app/Models/StatsDAOSQLite.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'app/Models/StatsDAO.php') diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index bd4271ba8..b8dc40592 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -209,8 +209,14 @@ SQL; $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 round($res['count'] / ($interval->format('%a') / ($period)), 2); + return round($res['count'] / ($interval_in_days / $period), 2); } /** diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php index 6cb54ddf6..3b1256de1 100644 --- a/app/Models/StatsDAOSQLite.php +++ b/app/Models/StatsDAOSQLite.php @@ -53,6 +53,7 @@ SQL; $stm->execute(); $res = $stm->fetchAll(PDO::FETCH_NAMED); + $repartition = array(); foreach ($res as $value) { $repartition[(int) $value['period']] = (int) $value['count']; } -- cgit v1.2.3 From 55843ff7a59f058e54046a3c2f85e2b476522c9d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 19 Sep 2014 16:45:16 +0200 Subject: Few fixes about statistics --- app/Models/StatsDAO.php | 1 + app/Models/Themes.php | 1 + app/i18n/de.php | 2 +- app/i18n/en.php | 2 +- app/i18n/fr.php | 2 +- app/views/configure/feed.phtml | 23 +++++++++++++---------- app/views/stats/idle.phtml | 4 +++- app/views/stats/repartition.phtml | 4 ++-- p/themes/icons/stats.svg | 31 +++++++++++++++++++++++++++++++ 9 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 p/themes/icons/stats.svg (limited to 'app/Models/StatsDAO.php') diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index b8dc40592..40505ab3e 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -315,6 +315,7 @@ SQL; 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 WHERE f.id = e.id_feed diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 538eb6554..68fc17a2b 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -96,6 +96,7 @@ class FreshRSS_Themes extends Minz_Model { 'search' => '🔍', 'share' => 'â™ș', 'starred' => '★', + 'stats' => '%', 'tag' => '⚐', 'up' => '△', 'view-normal' => '☰', diff --git a/app/i18n/de.php b/app/i18n/de.php index 3dc1536de..6caa3cd84 100644 --- a/app/i18n/de.php +++ b/app/i18n/de.php @@ -150,7 +150,7 @@ return array ( 'website_url' => 'Webseiten-Adresse URL', 'feed_url' => 'Feed URL', 'articles' => 'Artikel', - 'number_articles' => 'Anzahl der Artikel', + 'number_articles' => '%d Artikel', 'by_feed' => 'per Feed', 'by_default' => 'Als Vorgabe', 'keep_history' => 'Kleinste Anzahl der Artikel, die behalten werden', diff --git a/app/i18n/en.php b/app/i18n/en.php index e84787508..b9588c8b8 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -215,7 +215,7 @@ return array ( 'website_url' => 'Website URL', 'feed_url' => 'Feed URL', 'articles' => 'articles', - 'number_articles' => 'Number of articles', + 'number_articles' => '%d articles', 'by_feed' => 'by feed', 'by_default' => 'By default', 'keep_history' => 'Minimum number of articles to keep', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index fab5c3470..4cc9c8598 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -215,7 +215,7 @@ return array ( 'website_url' => 'URL du site', 'feed_url' => 'URL du flux', 'articles' => 'articles', - 'number_articles' => 'Nombre d’articles', + 'number_articles' => '%d articles', 'by_feed' => 'par flux', 'by_default' => 'Par dĂ©faut', 'keep_history' => 'Nombre minimum d’articles Ă  conserver', diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml index a8dd9a8cb..aa653e585 100644 --- a/app/views/configure/feed.phtml +++ b/app/views/configure/feed.phtml @@ -70,6 +70,13 @@ +
+
+ + + +
+
@@ -80,17 +87,13 @@
- -
- - - -
-
-
-
- +
+ + + + +
diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 608e2d33c..14b83ae95 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -23,7 +23,9 @@
-
  • +
  • + () +
  • diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml index ead275696..b425c1458 100644 --- a/app/views/stats/repartition.phtml +++ b/app/views/stats/repartition.phtml @@ -24,8 +24,8 @@ feed) {?> - - + + diff --git a/p/themes/icons/stats.svg b/p/themes/icons/stats.svg new file mode 100644 index 000000000..408d9e67f --- /dev/null +++ b/p/themes/icons/stats.svg @@ -0,0 +1,31 @@ + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + + + + Gnome Symbolic Icon Theme + + + + + + + + + + + + + + -- cgit v1.2.3