From 181fcd98893f65a2c5159158fbfc022b4661ea13 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 13 Jun 2014 01:00:27 -0400 Subject: Refactor statistics I made a new controller to handle statistics. The old statistics have been moved in that controller and a new action has been added to display idle feeds. I also added a menu in the left panel to navigate between the statistics pages. See #90 --- app/Controllers/statsController.php | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/Controllers/statsController.php (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php new file mode 100644 index 000000000..cb8870fa9 --- /dev/null +++ b/app/Controllers/statsController.php @@ -0,0 +1,73 @@ +view->loginOk) { + Minz_Error::error( + 403, array('error' => array(Minz_Translate::t('access_denied'))) + ); + } + + Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + + $statsDAO = new FreshRSS_StatsDAO (); + 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->feedByCategory = $statsDAO->calculateFeedByCategory(); + $this->view->entryByCategory = $statsDAO->calculateEntryByCategory(); + $this->view->topFeed = $statsDAO->calculateTopFeed(); + } + + public function idleAction() { + if (!$this->view->loginOk) { + Minz_Error::error( + 403, array('error' => array(Minz_Translate::t('access_denied'))) + ); + } + + Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + + $statsDAO = new FreshRSS_StatsDAO (); + $feeds = $statsDAO->calculateFeedLastDate(); + $idleFeeds = array(); + $now = new \DateTime(); + $feedDate = clone $now; + $lastWeek = clone $now; + $lastWeek->modify('-1 week'); + $lastMonth = clone $now; + $lastMonth->modify('-1 month'); + $last3Month = clone $now; + $last3Month->modify('-3 month'); + $last6Month = clone $now; + $last6Month->modify('-6 month'); + $lastYear = clone $now; + $lastYear->modify('-1 year'); + + foreach ($feeds as $feed) { + $feedDate->setTimestamp($feed['last_date']); + if ($feedDate >= $lastWeek) { + continue; + } + if ($feedDate < $lastWeek) { + $idleFeeds['lastWeek'][] = $feed['name']; + } + if ($feedDate < $lastMonth) { + $idleFeeds['lastMonth'][] = $feed['name']; + } + if ($feedDate < $last3Month) { + $idleFeeds['last3Month'][] = $feed['name']; + } + if ($feedDate < $last6Month) { + $idleFeeds['last6Month'][] = $feed['name']; + } + if ($feedDate < $lastYear) { + $idleFeeds['lastYear'][] = $feed['name']; + } + } + + $this->view->idleFeeds = $idleFeeds; + } + +} -- cgit v1.2.3 From d9f570a84d32921287fadced6dce0304b565bb85 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 13 Jun 2014 18:19:09 -0400 Subject: Refactor idle feed stats --- app/Controllers/statsController.php | 12 ++++---- app/views/stats/idle.phtml | 60 +++++++------------------------------ 2 files changed, 17 insertions(+), 55 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index cb8870fa9..655d453c6 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -51,23 +51,23 @@ class FreshRSS_stats_Controller extends Minz_ActionController { continue; } if ($feedDate < $lastWeek) { - $idleFeeds['lastWeek'][] = $feed['name']; + $idleFeeds['last_week'][] = $feed['name']; } if ($feedDate < $lastMonth) { - $idleFeeds['lastMonth'][] = $feed['name']; + $idleFeeds['last_month'][] = $feed['name']; } if ($feedDate < $last3Month) { - $idleFeeds['last3Month'][] = $feed['name']; + $idleFeeds['last_3_month'][] = $feed['name']; } if ($feedDate < $last6Month) { - $idleFeeds['last6Month'][] = $feed['name']; + $idleFeeds['last_6_month'][] = $feed['name']; } if ($feedDate < $lastYear) { - $idleFeeds['lastYear'][] = $feed['name']; + $idleFeeds['last_year'][] = $feed['name']; } } - $this->view->idleFeeds = $idleFeeds; + $this->view->idleFeeds = array_reverse($idleFeeds); } } diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 5c11b3f86..08ce440e8 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -5,53 +5,15 @@

-
-

- -
    - idleFeeds['lastWeek'] as $feed): ?> -
  • - -
-
- -
-

- -
    - idleFeeds['lastMonth'] as $feed): ?> -
  • - -
-
- -
-

- -
    - idleFeeds['last3Month'] as $feed): ?> -
  • - -
-
- -
-

- -
    - idleFeeds['last6Month'] as $feed): ?> -
  • - -
-
- -
-

- -
    - idleFeeds['lastYear'] as $feed): ?> -
  • - -
-
+ idleFeeds as $period => $feeds): ?> +
+

+ +
    + +
  • + +
+
+ \ No newline at end of file -- cgit v1.2.3 From e9cee8cc20835b3151de70e4df25cc5e80c4ec85 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 15 Jun 2014 11:48:08 -0400 Subject: Fix syntax --- app/Controllers/statsController.php | 26 ++++++++++++-------------- app/views/stats/idle.phtml | 10 +++++----- 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 655d453c6..cbc67cac3 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -3,13 +3,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { public function mainAction() { - if (!$this->view->loginOk) { - Minz_Error::error( - 403, array('error' => array(Minz_Translate::t('access_denied'))) - ); - } - - Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + $this->initAction(); $statsDAO = new FreshRSS_StatsDAO (); Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); @@ -21,13 +15,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { } public function idleAction() { - if (!$this->view->loginOk) { - Minz_Error::error( - 403, array('error' => array(Minz_Translate::t('access_denied'))) - ); - } - - Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + $this->initAction(); $statsDAO = new FreshRSS_StatsDAO (); $feeds = $statsDAO->calculateFeedLastDate(); @@ -69,5 +57,15 @@ class FreshRSS_stats_Controller extends Minz_ActionController { $this->view->idleFeeds = array_reverse($idleFeeds); } + + private function initAction() { + if (!$this->view->loginOk) { + Minz_Error::error( + 403, array('error' => array(Minz_Translate::t('access_denied'))) + ); + } + + Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + } } diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 08ce440e8..26806bb0e 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -5,15 +5,15 @@

- idleFeeds as $period => $feeds): ?> + idleFeeds as $period => $feeds){ ?>

    - +
  • - +
- - \ No newline at end of file + + -- cgit v1.2.3 From 60fe99344e1d87850f1a44791c1f0a675d13c756 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 15 Jun 2014 12:13:33 -0400 Subject: Refactor and formatting --- app/Controllers/statsController.php | 100 ++++++++++++++-------------- app/Models/StatsDAO.php | 24 +++---- app/i18n/en.php | 14 ++-- app/i18n/fr.php | 14 ++-- app/layout/aside_stats.phtml | 4 +- app/layout/header.phtml | 2 +- app/views/stats/idle.phtml | 24 +++---- app/views/stats/index.phtml | 127 ++++++++++++++++++++++++++++++++++++ app/views/stats/main.phtml | 127 ------------------------------------ 9 files changed, 216 insertions(+), 220 deletions(-) create mode 100644 app/views/stats/index.phtml delete mode 100644 app/views/stats/main.phtml (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index cbc67cac3..fb5609cb4 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -2,70 +2,66 @@ class FreshRSS_stats_Controller extends Minz_ActionController { - public function mainAction() { - $this->initAction(); - - $statsDAO = new FreshRSS_StatsDAO (); + public function indexAction() { + $statsDAO = new FreshRSS_StatsDAO (); 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->feedByCategory = $statsDAO->calculateFeedByCategory(); $this->view->entryByCategory = $statsDAO->calculateEntryByCategory(); $this->view->topFeed = $statsDAO->calculateTopFeed(); - } - - public function idleAction() { - $this->initAction(); + } - $statsDAO = new FreshRSS_StatsDAO (); - $feeds = $statsDAO->calculateFeedLastDate(); - $idleFeeds = array(); - $now = new \DateTime(); - $feedDate = clone $now; - $lastWeek = clone $now; - $lastWeek->modify('-1 week'); - $lastMonth = clone $now; - $lastMonth->modify('-1 month'); - $last3Month = clone $now; - $last3Month->modify('-3 month'); - $last6Month = clone $now; - $last6Month->modify('-6 month'); - $lastYear = clone $now; - $lastYear->modify('-1 year'); + public function idleAction() { + $statsDAO = new FreshRSS_StatsDAO (); + $feeds = $statsDAO->calculateFeedLastDate(); + $idleFeeds = array(); + $now = new \DateTime(); + $feedDate = clone $now; + $lastWeek = clone $now; + $lastWeek->modify('-1 week'); + $lastMonth = clone $now; + $lastMonth->modify('-1 month'); + $last3Month = clone $now; + $last3Month->modify('-3 month'); + $last6Month = clone $now; + $last6Month->modify('-6 month'); + $lastYear = clone $now; + $lastYear->modify('-1 year'); - foreach ($feeds as $feed) { - $feedDate->setTimestamp($feed['last_date']); - if ($feedDate >= $lastWeek) { - continue; - } - if ($feedDate < $lastWeek) { - $idleFeeds['last_week'][] = $feed['name']; - } - if ($feedDate < $lastMonth) { - $idleFeeds['last_month'][] = $feed['name']; - } - if ($feedDate < $last3Month) { - $idleFeeds['last_3_month'][] = $feed['name']; - } - if ($feedDate < $last6Month) { - $idleFeeds['last_6_month'][] = $feed['name']; - } - if ($feedDate < $lastYear) { - $idleFeeds['last_year'][] = $feed['name']; - } - } + foreach ($feeds as $feed) { + $feedDate->setTimestamp($feed['last_date']); + if ($feedDate >= $lastWeek) { + continue; + } + if ($feedDate < $lastWeek) { + $idleFeeds['last_week'][] = $feed['name']; + } + if ($feedDate < $lastMonth) { + $idleFeeds['last_month'][] = $feed['name']; + } + if ($feedDate < $last3Month) { + $idleFeeds['last_3_month'][] = $feed['name']; + } + if ($feedDate < $last6Month) { + $idleFeeds['last_6_month'][] = $feed['name']; + } + if ($feedDate < $lastYear) { + $idleFeeds['last_year'][] = $feed['name']; + } + } - $this->view->idleFeeds = array_reverse($idleFeeds); - } + $this->view->idleFeeds = array_reverse($idleFeeds); + } - private function initAction() { + public function firstAction() { if (!$this->view->loginOk) { - Minz_Error::error( - 403, array('error' => array(Minz_Translate::t('access_denied'))) - ); - } + Minz_Error::error( + 403, array('error' => array(Minz_Translate::t('access_denied'))) + ); + } - Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); + Minz_View::prependTitle(Minz_Translate::t('stats') . ' · '); } } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index f9f4740fd..eafe86407 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -180,14 +180,14 @@ SQL; $stm->execute(); return $stm->fetchAll(PDO::FETCH_ASSOC); } - - /** - * Calculates the last publication date for each feed - * - * @return array - */ - public function calculateFeedLastDate() { - $sql = <<prefix}feed AS f, @@ -196,10 +196,10 @@ WHERE f.id = e.id_feed GROUP BY f.id ORDER BY name SQL; - $stm = $this->bd->prepare($sql); - $stm->execute(); - return $stm->fetchAll(PDO::FETCH_ASSOC); - } + $stm = $this->bd->prepare($sql); + $stm->execute(); + return $stm->fetchAll(PDO::FETCH_ASSOC); + } private function convertToSerie($data) { $serie = array(); diff --git a/app/i18n/en.php b/app/i18n/en.php index 8d5f305c0..19cf4a06d 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -46,14 +46,14 @@ return array ( 'no_query_filter' => 'No filter', 'about' => 'About', 'stats' => 'Statistics', - 'stats_idle' => 'Idle feeds', - 'stats_main' => 'Main statistics', + 'stats_idle' => 'Idle feeds', + 'stats_main' => 'Main statistics', - 'last_week' => 'Last week', - 'last_month' => 'Last month', - 'last_3_month' => 'Last three months', - 'last_6_month' => 'Last six months', - 'last_year' => 'Last year', + 'last_week' => 'Last week', + 'last_month' => 'Last month', + 'last_3_month' => 'Last three months', + 'last_6_month' => 'Last six months', + 'last_year' => 'Last year', 'your_rss_feeds' => 'Your RSS feeds', 'add_rss_feed' => 'Add a RSS feed', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 3441425df..54fe55ea0 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -46,14 +46,14 @@ return array ( 'no_query_filter' => 'Aucun filtre appliqué', 'about' => 'À propos', 'stats' => 'Statistiques', - 'stats_idle' => 'Flux inactifs', - 'stats_main' => 'Statistiques principales', + 'stats_idle' => 'Flux inactifs', + 'stats_main' => 'Statistiques principales', - 'last_week' => 'La dernière semaine', - 'last_month' => 'Le dernier mois', - 'last_3_month' => 'Les derniers trois mois', - 'last_6_month' => 'Les derniers six mois', - 'last_year' => 'La dernière année', + 'last_week' => 'La dernière semaine', + 'last_month' => 'Le dernier mois', + 'last_3_month' => 'Les derniers trois mois', + 'last_6_month' => 'Les derniers six mois', + 'last_year' => 'La dernière année', 'your_rss_feeds' => 'Vos flux RSS', 'add_rss_feed' => 'Ajouter un flux RSS', diff --git a/app/layout/aside_stats.phtml b/app/layout/aside_stats.phtml index bc1e85592..32a3f5dee 100644 --- a/app/layout/aside_stats.phtml +++ b/app/layout/aside_stats.phtml @@ -1,7 +1,7 @@ + diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtml new file mode 100644 index 000000000..a48181fe4 --- /dev/null +++ b/app/views/stats/index.phtml @@ -0,0 +1,127 @@ +partial('aside_stats'); ?> + +
+ + +

+ +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
repartition['main_stream']['total']); ?>repartition['all_feeds']['total']); ?>
repartition['main_stream']['read']); ?>repartition['all_feeds']['read']); ?>
repartition['main_stream']['unread']); ?>repartition['all_feeds']['unread']); ?>
repartition['main_stream']['favorite']); ?>repartition['all_feeds']['favorite']); ?>
+
+ +
+

+
+
+ +
+

+
+
+
+ +
+

+
+
+
+ +
+

+ + + + + + + + + + topFeed as $feed): ?> + + + + + + + +
+
+
+ + diff --git a/app/views/stats/main.phtml b/app/views/stats/main.phtml deleted file mode 100644 index fe372e221..000000000 --- a/app/views/stats/main.phtml +++ /dev/null @@ -1,127 +0,0 @@ -partial('aside_stats'); ?> - -
- - -

- -
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
repartition['main_stream']['total']); ?>repartition['all_feeds']['total']); ?>
repartition['main_stream']['read']); ?>repartition['all_feeds']['read']); ?>
repartition['main_stream']['unread']); ?>repartition['all_feeds']['unread']); ?>
repartition['main_stream']['favorite']); ?>repartition['all_feeds']['favorite']); ?>
-
- -
-

-
-
- -
-

-
-
-
- -
-

-
-
-
- -
-

- - - - - - - - - - topFeed as $feed): ?> - - - - - - - -
-
-
- - -- cgit v1.2.3 From 3bbd0e446f6a1a0c41a4db36d2841db36dc34004 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 6 Jul 2014 11:54:00 +0200 Subject: Prepare statistics for SQLite Temporarily disable 30-day statistics for SQLite https://github.com/marienfressinaud/FreshRSS/issues/100 https://github.com/marienfressinaud/FreshRSS/issues/90 --- app/Controllers/statsController.php | 4 ++-- app/Models/Factory.php | 10 ++++++++++ app/Models/StatsDAO.php | 4 ++-- app/Models/StatsDAOSQLite.php | 9 +++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/Models/StatsDAOSQLite.php (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index fb5609cb4..9009468bc 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -3,7 +3,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { public function indexAction() { - $statsDAO = new FreshRSS_StatsDAO (); + $statsDAO = FreshRSS_Factory::createStatsDAO(); 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()); @@ -13,7 +13,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { } public function idleAction() { - $statsDAO = new FreshRSS_StatsDAO (); + $statsDAO = FreshRSS_Factory::createStatsDAO(); $feeds = $statsDAO->calculateFeedLastDate(); $idleFeeds = array(); $now = new \DateTime(); diff --git a/app/Models/Factory.php b/app/Models/Factory.php index 95d21a277..08569b2e2 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -19,4 +19,14 @@ class FreshRSS_Factory { return new FreshRSS_EntryDAO(); } } + + public static function createStatsDAO() { + $db = Minz_Configuration::dataBase(); + if ($db['type'] === 'sqlite') { + return new FreshRSS_StatsDAOSQLite(); + } else { + return new FreshRSS_StatsDAO(); + } + } + } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index eafe86407..62f238bd2 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -201,7 +201,7 @@ SQL; return $stm->fetchAll(PDO::FETCH_ASSOC); } - private function convertToSerie($data) { + protected function convertToSerie($data) { $serie = array(); foreach ($data as $key => $value) { @@ -211,7 +211,7 @@ SQL; return json_encode($serie); } - private function convertToPieSerie($data) { + protected function convertToPieSerie($data) { $serie = array(); foreach ($data as $value) { diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php new file mode 100644 index 000000000..c923e5fd0 --- /dev/null +++ b/app/Models/StatsDAOSQLite.php @@ -0,0 +1,9 @@ +convertToSerie(array()); //TODO: Implement 30-day statistics for SQLite + } + +} -- cgit v1.2.3 From 937cb4b066f07888dabe8400b71be6633a19a1d6 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 22 Jul 2014 13:41:31 +0200 Subject: Idle feeds: link to configuration page https://github.com/marienfressinaud/FreshRSS/issues/544 --- app/Controllers/statsController.php | 14 +++++++------- app/Models/StatsDAO.php | 3 ++- app/views/stats/idle.phtml | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 9009468bc..be58dd0eb 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -4,9 +4,9 @@ class FreshRSS_stats_Controller extends Minz_ActionController { public function indexAction() { $statsDAO = FreshRSS_Factory::createStatsDAO(); - Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); + 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->count = $statsDAO->calculateEntryCount(); $this->view->feedByCategory = $statsDAO->calculateFeedByCategory(); $this->view->entryByCategory = $statsDAO->calculateEntryByCategory(); $this->view->topFeed = $statsDAO->calculateTopFeed(); @@ -35,19 +35,19 @@ class FreshRSS_stats_Controller extends Minz_ActionController { continue; } if ($feedDate < $lastWeek) { - $idleFeeds['last_week'][] = $feed['name']; + $idleFeeds['last_week'][] = $feed; } if ($feedDate < $lastMonth) { - $idleFeeds['last_month'][] = $feed['name']; + $idleFeeds['last_month'][] = $feed; } if ($feedDate < $last3Month) { - $idleFeeds['last_3_month'][] = $feed['name']; + $idleFeeds['last_3_month'][] = $feed; } if ($feedDate < $last6Month) { - $idleFeeds['last_6_month'][] = $feed['name']; + $idleFeeds['last_6_month'][] = $feed; } if ($feedDate < $lastYear) { - $idleFeeds['last_year'][] = $feed['name']; + $idleFeeds['last_year'][] = $feed; } } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 66f5104b3..9a88a4fcf 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -170,7 +170,8 @@ SQL; */ public function calculateFeedLastDate() { $sql = <<prefix}feed AS f, {$this->prefix}entry AS e diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 356fea20f..f62fa8d8b 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -11,7 +11,7 @@
    -
  • +
-- cgit v1.2.3 From e507256d0bdebd02cf1fcd6fe1477cbac0b6934e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 23 Jul 2014 00:24:00 +0200 Subject: Stats idle feed small bug Some feeds were listed more than once. A bit more independent from the SQL query. https://github.com/marienfressinaud/FreshRSS/issues/544 --- app/Controllers/statsController.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index be58dd0eb..45d13e043 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -15,7 +15,13 @@ class FreshRSS_stats_Controller extends Minz_ActionController { public function idleAction() { $statsDAO = FreshRSS_Factory::createStatsDAO(); $feeds = $statsDAO->calculateFeedLastDate(); - $idleFeeds = array(); + $idleFeeds = array( + 'last_year' => array(), + 'last_6_month' => array(), + 'last_3_month' => array(), + 'last_month' => array(), + 'last_week' => array(), + ); $now = new \DateTime(); $feedDate = clone $now; $lastWeek = clone $now; @@ -34,24 +40,20 @@ class FreshRSS_stats_Controller extends Minz_ActionController { if ($feedDate >= $lastWeek) { continue; } - if ($feedDate < $lastWeek) { - $idleFeeds['last_week'][] = $feed; - } - if ($feedDate < $lastMonth) { - $idleFeeds['last_month'][] = $feed; - } - if ($feedDate < $last3Month) { - $idleFeeds['last_3_month'][] = $feed; - } - if ($feedDate < $last6Month) { - $idleFeeds['last_6_month'][] = $feed; - } if ($feedDate < $lastYear) { $idleFeeds['last_year'][] = $feed; + } elseif ($feedDate < $last6Month) { + $idleFeeds['last_6_month'][] = $feed; + } elseif ($feedDate < $last3Month) { + $idleFeeds['last_3_month'][] = $feed; + } elseif ($feedDate < $lastMonth) { + $idleFeeds['last_month'][] = $feed; + } elseif ($feedDate < $lastWeek) { + $idleFeeds['last_week'][] = $feed; } } - $this->view->idleFeeds = array_reverse($idleFeeds); + $this->view->idleFeeds = $idleFeeds; } public function firstAction() { -- cgit v1.2.3 From d049c1bc806dc0677a4b2b17faf06080600c372f Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Thu, 24 Jul 2014 21:57:59 -0400 Subject: Add article repartition in stats Add article repartition per hour, per day of week, per month for all feeds but also for individual feeds. --- app/Controllers/statsController.php | 15 ++++- app/Models/StatsDAO.php | 129 +++++++++++++++++++++++++++++++++++- app/i18n/en.php | 47 +++++++++---- app/i18n/fr.php | 23 +++++++ app/layout/aside_flux.phtml | 1 + app/layout/aside_stats.phtml | 3 + app/views/stats/main.phtml | 127 ----------------------------------- app/views/stats/repartition.phtml | 100 ++++++++++++++++++++++++++++ 8 files changed, 304 insertions(+), 141 deletions(-) delete mode 100644 app/views/stats/main.phtml create mode 100644 app/views/stats/repartition.phtml (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 45d13e043..06a20c2a6 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -55,7 +55,20 @@ class FreshRSS_stats_Controller extends Minz_ActionController { $this->view->idleFeeds = $idleFeeds; } - + + public function repartitionAction() { + $statsDAO = FreshRSS_Factory::createStatsDAO(); + $feedDAO = FreshRSS_Factory::createFeedDao(); + Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); + $id = Minz_Request::param ('id', null); + $this->view->feed = $feedDAO->searchById($id); + $this->view->days = $statsDAO->getDays(); + $this->view->months = $statsDAO->getMonths(); + $this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id); + $this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id); + $this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id); + } + public function firstAction() { if (!$this->view->loginOk) { Minz_Error::error( diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 9a88a4fcf..ee8d0d663 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -85,9 +85,83 @@ SQL; * @return array */ protected function initEntryCountArray() { + return $this->initStatsArray(-self::ENTRY_COUNT_PERIOD, -1); + } + + /** + * Calculates the number of article per hour of the day per feed + * + * @param integer $feed id + * @return string + */ + public function calculateEntryRepartitionPerFeedPerHour($feed = null) { + return $this->calculateEntryRepartitionPerFeedPerPeriod('%k', $feed); + } + + /** + * Calculates the number of article per day of week per feed + * + * @param integer $feed id + * @return string + */ + public function calculateEntryRepartitionPerFeedPerDayOfWeek($feed = null) { + return $this->calculateEntryRepartitionPerFeedPerPeriod('%w', $feed); + } + + /** + * Calculates the number of article per month per feed + * + * @param integer $feed + * @return string + */ + public function calculateEntryRepartitionPerFeedPerMonth($feed = null) { + return $this->calculateEntryRepartitionPerFeedPerPeriod('%m', $feed); + } + + /** + * Calculates the number of article per period per feed + * + * @param string $period format string to use for grouping + * @param integer $feed id + * @return string + */ + protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) { + if ($feed) { + $restrict = "WHERE e.id_feed = {$feed}"; + } else { + $restrict = ''; + } + $sql = <<prefix}entry AS e +{$restrict} +GROUP BY period +ORDER BY period ASC +SQL; + + $stm = $this->bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_NAMED); + + foreach ($res as $value) { + $repartition[(int) $value['period']] = (int) $value['count']; + } + + return $this->convertToSerie($repartition); + } + + /** + * Initialize an array for statistics depending on a range + * + * @param integer $min + * @param integer $max + * @return array + */ + protected function initStatsArray($min, $max) { return array_map(function () { return 0; - }, array_flip(range(-self::ENTRY_COUNT_PERIOD, -1))); + }, array_flip(range($min, $max))); } /** @@ -205,4 +279,57 @@ SQL; return json_encode($serie); } + /** + * Gets days ready for graphs + * + * @return string + */ + public function getDays() { + return $this->convertToTranslatedJson(array( + 'sun', + 'mon', + 'tue', + 'wed', + 'thu', + 'fri', + 'sat', + )); + } + + /** + * Gets months ready for graphs + * + * @return string + */ + public function getMonths() { + return $this->convertToTranslatedJson(array( + 'jan', + 'feb', + 'mar', + 'apr', + 'may', + 'jun', + 'jul', + 'aug', + 'sep', + 'oct', + 'nov', + 'dec', + )); + } + + /** + * Translates array content and encode it as JSON + * + * @param array $data + * @return string + */ + private function convertToTranslatedJson($data = array()) { + $translated = array_map(function ($a) { + return Minz_Translate::t($a); + }, $data); + + return json_encode($translated); + } + } diff --git a/app/i18n/en.php b/app/i18n/en.php index 8634f99b5..10327c7f5 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -48,6 +48,10 @@ return array ( 'stats' => 'Statistics', 'stats_idle' => 'Idle feeds', 'stats_main' => 'Main statistics', + 'stats_repartition' => 'Articles repartition', + 'stats_entry_per_hour' => 'Per hour', + 'stats_entry_per_day_of_week' => 'Per day of week', + 'stats_entry_per_month' => 'Per month', 'last_week' => 'Last week', 'last_month' => 'Last month', @@ -341,18 +345,37 @@ return array ( 'confirm_action' => 'Are you sure you want to perform this action? It cannot be cancelled!', // DATE - 'january' => 'january', - 'february' => 'february', - 'march' => 'march', - 'april' => 'april', - 'may' => 'may', - 'june' => 'june', - 'july' => 'july', - 'august' => 'august', - 'september' => 'september', - 'october' => 'october', - 'november' => 'november', - 'december' => 'december', + 'january' => 'January', + 'february' => 'February', + 'march' => 'March', + 'april' => 'April', + 'may' => 'May', + 'june' => 'June', + 'july' => 'July', + 'august' => 'August', + 'september' => 'September', + 'october' => 'October', + 'november' => 'November', + 'december' => 'December', + 'january' => 'Jan', + 'february' => 'Feb', + 'march' => 'Mar', + 'april' => 'Apr', + 'may' => 'May', + 'june' => 'Jun', + 'july' => 'Jul', + 'august' => 'Aug', + 'september' => 'Sep', + 'october' => 'Oct', + 'november' => 'Nov', + 'december' => 'Dec', + 'sun' => 'Sun', + 'mon' => 'Mon', + 'tue' => 'Tue', + 'wed' => 'Wed', + 'thu' => 'Thu', + 'fri' => 'Fri', + 'sat' => 'Sat', // special format for date() function 'Jan' => '\J\a\n\u\a\r\y', 'Feb' => '\F\e\b\r\u\a\r\y', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index e04078dba..6ab3d7335 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -48,6 +48,10 @@ return array ( 'stats' => 'Statistiques', 'stats_idle' => 'Flux inactifs', 'stats_main' => 'Statistiques principales', + 'stats_repartition' => 'Répartition des articles', + 'stats_entry_per_hour' => 'Par heure', + 'stats_entry_per_day_of_week' => 'Par jour de la semaine', + 'stats_entry_per_month' => 'Par mois', 'last_week' => 'La dernière semaine', 'last_month' => 'Le dernier mois', @@ -353,6 +357,25 @@ return array ( 'october' => 'octobre', 'november' => 'novembre', 'december' => 'décembre', + 'jan' => 'jan.', + 'feb' => 'fév.', + 'mar' => 'mar.', + 'apr' => 'avr.', + 'may' => 'mai.', + 'jun' => 'juin', + 'jul' => 'jui.', + 'aug' => 'août', + 'sep' => 'sep.', + 'oct' => 'oct.', + 'nov' => 'nov.', + 'dec' => 'déc.', + 'sun' => 'dim.', + 'mon' => 'lun.', + 'tue' => 'mar.', + 'wed' => 'mer.', + 'thu' => 'jeu.', + 'fri' => 'ven.', + 'sat' => 'sam.', // format spécial pour la fonction date() 'Jan' => '\j\a\n\v\i\e\r', 'Feb' => '\f\é\v\r\i\e\r', diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 817dae676..5fbb36730 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -83,6 +83,7 @@
  • +
  • diff --git a/app/layout/aside_stats.phtml b/app/layout/aside_stats.phtml index 32a3f5dee..fbfb9d84d 100644 --- a/app/layout/aside_stats.phtml +++ b/app/layout/aside_stats.phtml @@ -6,4 +6,7 @@
  • +
  • + +
  • diff --git a/app/views/stats/main.phtml b/app/views/stats/main.phtml deleted file mode 100644 index fe372e221..000000000 --- a/app/views/stats/main.phtml +++ /dev/null @@ -1,127 +0,0 @@ -partial('aside_stats'); ?> - -
    - - -

    - -
    -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
    repartition['main_stream']['total']); ?>repartition['all_feeds']['total']); ?>
    repartition['main_stream']['read']); ?>repartition['all_feeds']['read']); ?>
    repartition['main_stream']['unread']); ?>repartition['all_feeds']['unread']); ?>
    repartition['main_stream']['favorite']); ?>repartition['all_feeds']['favorite']); ?>
    -
    - -
    -

    -
    -
    - -
    -

    -
    -
    -
    - -
    -

    -
    -
    -
    - -
    -

    - - - - - - - - - - topFeed as $feed): ?> - - - - - - - -
    -
    -
    - - diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml new file mode 100644 index 000000000..4455abe2a --- /dev/null +++ b/app/views/stats/repartition.phtml @@ -0,0 +1,100 @@ +partial('aside_stats'); ?> + +
    + + + feed) {?> +

    + + + feed->name(); ?> + +

    + +

    + + +
    +

    +
    +
    + +
    +

    +
    +
    + +
    +

    +
    +
    +
    + + \ No newline at end of file -- cgit v1.2.3 From 393fce3e8aaef1b00ab34bf35b7e8b329a5e3dc5 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Tue, 19 Aug 2014 08:55:44 -0400 Subject: Add a feed selector in repartition statistics. Before we could choose the feed in the statistics only from the feed options in the main view. Now with the new drop-down list, it is possible to choose it from the statistics page. The rendering needs to be polished to be nicer. --- app/Controllers/statsController.php | 2 ++ app/views/stats/repartition.phtml | 39 +++++++++++++++++++++++++------------ p/scripts/main.js | 7 +++++++ 3 files changed, 36 insertions(+), 12 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 06a20c2a6..934b076a5 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -58,9 +58,11 @@ class FreshRSS_stats_Controller extends Minz_ActionController { public function repartitionAction() { $statsDAO = FreshRSS_Factory::createStatsDAO(); + $categoryDAO = new FreshRSS_CategoryDAO(); $feedDAO = FreshRSS_Factory::createFeedDao(); Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); $id = Minz_Request::param ('id', null); + $this->view->categories = $categoryDAO->listCategories (); $this->view->feed = $feedDAO->searchById($id); $this->view->days = $statsDAO->getDays(); $this->view->months = $statsDAO->getMonths(); diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml index 09892d3c5..3dc319731 100644 --- a/app/views/stats/repartition.phtml +++ b/app/views/stats/repartition.phtml @@ -2,23 +2,38 @@
    - + +

    + + + feed) {?> -

    - - - feed->name(); ?> - -

    - -

    + + + - +

    - +

    @@ -93,7 +108,7 @@ function initStats() { yaxis: {min: 0}, mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}} }); - + } initStats(); diff --git a/p/scripts/main.js b/p/scripts/main.js index ae7b69364..4802e0941 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1063,6 +1063,12 @@ function init_share_observers() { }); } +function init_stats_observers() { + $('#feed_select').on('change', function(e) { + redirect($(this).find(':selected').data('url')); + }); +} + function init_remove_observers() { $('.post').on('click', 'a.remove', function(e) { var remove_what = $(this).attr('data-remove'); @@ -1177,6 +1183,7 @@ function init_all() { init_remove_observers(); init_feed_observers(); init_password_observers(); + init_stats_observers(); } if (window.console) { -- cgit v1.2.3 From ea99ac1259083ff0a9eb6131d777454b54045626 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 19 Aug 2014 21:55:49 +0200 Subject: Syntax 581 #581 --- app/Controllers/statsController.php | 2 +- app/views/stats/repartition.phtml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'app/Controllers/statsController.php') diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 934b076a5..98f46f0d2 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -62,7 +62,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { $feedDAO = FreshRSS_Factory::createFeedDao(); Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); $id = Minz_Request::param ('id', null); - $this->view->categories = $categoryDAO->listCategories (); + $this->view->categories = $categoryDAO->listCategories(); $this->view->feed = $feedDAO->searchById($id); $this->view->days = $statsDAO->getDays(); $this->view->months = $statsDAO->getMonths(); diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml index 3dc319731..1f920a7ae 100644 --- a/app/views/stats/repartition.phtml +++ b/app/views/stats/repartition.phtml @@ -6,16 +6,16 @@