From e98ac32716dfe9343baa5bce7ad2c1e98c40540c Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Wed, 22 Jan 2014 19:06:46 -0500 Subject: Ajout de statistiques de l'application Conflicts: app/i18n/en.php app/i18n/fr.php --- app/Models/StatsDAO.php | 178 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 app/Models/StatsDAO.php (limited to 'app/Models/StatsDAO.php') diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php new file mode 100644 index 000000000..a317c8f27 --- /dev/null +++ b/app/Models/StatsDAO.php @@ -0,0 +1,178 @@ +prefix}entry AS e +, {$this->prefix}feed AS f +WHERE e.id_feed = f.id +AND f.priority = 10 +SQL; + $stm = $this->bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_ASSOC); + $repartition['main_stream'] = $res[0]; + + // Generates the repartition for all entries + $sql = <<prefix}entry AS e +SQL; + $stm = $this->bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_ASSOC); + $repartition['all_feeds'] = $res[0]; + + return $repartition; + } + + /** + * Calculates entry count per day on a 30 days period. + * Returns the result as a JSON string. + * + * @return string + */ + public function calculateEntryCount() { + $count = array(); + + // Generates a list of 30 last day to be sure we always have 30 days. + // If we do not do that kind of thing, we'll end up with holes in the + // days if the user do not have a lot of feeds. + $sql = <<bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_ASSOC); + foreach ($res as $value) { + $count[$value['day']] = 0; + } + + // Get stats per day for the last 30 days and applies the result on + // the array created with the last query. + $sql = <<prefix}entry AS e +WHERE FROM_UNIXTIME(e.date, '%Y%m%d') BETWEEN DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -30 DAY), '%Y%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y%m%d') +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 feed count per category. + * Returns the result as a JSON string. + * + * @return string + */ + public function calculateFeedByCategory() { + $sql = <<prefix}category AS c, +{$this->prefix}feed AS f +WHERE c.id = f.category +GROUP BY label +SQL; + $stm = $this->bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_ASSOC); + + return $this->convertToPieSerie($res); + } + + /** + * Calculates entry count per category. + * Returns the result as a JSON string. + * + * @return string + */ + public function calculateEntryByCategory() { + $sql = <<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 +SQL; + $stm = $this->bd->prepare($sql); + $stm->execute(); + $res = $stm->fetchAll(PDO::FETCH_ASSOC); + + return $this->convertToPieSerie($res); + } + + private function convertToSerie($data) { + $serie = array(); + + foreach ($data as $key => $value) { + $serie[] = array($key, $value); + } + + return json_encode($serie); + } + + private function convertToPieSerie($data) { + $serie = array(); + + foreach ($data as $value) { + $value['data'] = array(array(0, (int)$value['data'])); + $serie[] = $value; + } + + return json_encode($serie); + } + +} -- cgit v1.2.3 From b0641fd0ebcaa02dcbeb2983703bff6516f93487 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 26 Jan 2014 08:54:52 -0500 Subject: Modification des statistiques. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout de la liste des 10 plus gros contributeurs Ajout de règles CSS pour les thèmes Flat et Dark Modification de l'affichage des camemberts (tri par nombre qui remplace le tri alphabétique) --- app/Controllers/indexController.php | 1 + app/Models/StatsDAO.php | 29 +++++++++++++++++++++++- app/i18n/en.php | 4 ++++ app/i18n/fr.php | 4 ++++ app/views/index/stats.phtml | 37 +++++++++++++++++++++++------- p/themes/Dark/freshrss.css | 45 +++++++++++++++++++++++++++++++++++++ p/themes/Flat/freshrss.css | 45 +++++++++++++++++++++++++++++++++++++ p/themes/Origine/freshrss.css | 5 ++++- 8 files changed, 160 insertions(+), 10 deletions(-) (limited to 'app/Models/StatsDAO.php') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 74883962d..cb6be6049 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -200,6 +200,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->count = ($statsDAO->calculateEntryCount()); $this->view->feedByCategory = $statsDAO->calculateFeedByCategory(); $this->view->entryByCategory = $statsDAO->calculateEntryByCategory(); + $this->view->topFeed = $statsDAO->calculateTopFeed(); } public function aboutAction () { diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index a317c8f27..60cec7847 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -122,6 +122,7 @@ FROM {$this->prefix}category AS c, {$this->prefix}feed AS f WHERE c.id = f.category GROUP BY label +ORDER BY data DESC SQL; $stm = $this->bd->prepare($sql); $stm->execute(); @@ -146,6 +147,7 @@ FROM {$this->prefix}category AS c, WHERE c.id = f.category AND f.id = e.id_feed GROUP BY label +ORDER BY data DESC SQL; $stm = $this->bd->prepare($sql); $stm->execute(); @@ -154,6 +156,31 @@ SQL; return $this->convertToPieSerie($res); } + /** + * Calculates the 10 top feeds based on their number of entries + * + * @return array + */ + public function calculateTopFeed() { + $sql = <<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 id +ORDER BY count DESC +LIMIT 10 +SQL; + $stm = $this->bd->prepare($sql); + $stm->execute(); + return $stm->fetchAll(PDO::FETCH_ASSOC); + } + private function convertToSerie($data) { $serie = array(); @@ -168,7 +195,7 @@ SQL; $serie = array(); foreach ($data as $value) { - $value['data'] = array(array(0, (int)$value['data'])); + $value['data'] = array(array(0, (int) $value['data'])); $serie[] = $value; } diff --git a/app/i18n/en.php b/app/i18n/en.php index 70fd8a74b..e5cf623c7 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -11,6 +11,8 @@ return array ( 'users' => 'Users', 'categories' => 'Categories', 'category' => 'Category', + 'feed' => 'Feed', + 'feeds' => 'Feeds', 'shortcuts' => 'Shortcuts', 'about' => 'About', 'stats' => 'Statistics', @@ -309,4 +311,6 @@ return array ( 'stats_entry_per_day' => 'Entries per day (last 30 days)', 'stats_feed_per_category' => 'Feeds per category', 'stats_entry_per_category' => 'Entries per category', + 'stats_top_feed' => 'Top ten feeds', + 'stats_entry_count' => 'Entry count', ); diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 53645477b..693dce5d1 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -11,6 +11,8 @@ return array ( 'users' => 'Utilisateurs', 'categories' => 'Catégories', 'category' => 'Catégorie', + 'feed' => 'Flux', + 'feeds' => 'Flux', 'shortcuts' => 'Raccourcis', 'about' => 'À propos', 'stats' => 'Statistiques', @@ -309,4 +311,6 @@ return array ( 'stats_entry_per_day' => 'Nombre d’articles par jour (30 derniers jours)', 'stats_feed_per_category' => 'Flux par catégorie', 'stats_entry_per_category' => 'Articles par catégorie', + 'stats_top_feed' => 'Les dix plus gros flux', + 'stats_entry_count' => 'Nombre d’articles', ); diff --git a/app/views/index/stats.phtml b/app/views/index/stats.phtml index 487c50a4b..ae9db172b 100644 --- a/app/views/index/stats.phtml +++ b/app/views/index/stats.phtml @@ -16,23 +16,23 @@ - repartition['main_stream']['total']?> - repartition['all_feeds']['total']?> + repartition['main_stream']['total']?> + repartition['all_feeds']['total']?> - repartition['main_stream']['read']?> - repartition['all_feeds']['read']?> + repartition['main_stream']['read']?> + repartition['all_feeds']['read']?> - repartition['main_stream']['unread']?> - repartition['all_feeds']['unread']?> + repartition['main_stream']['unread']?> + repartition['all_feeds']['unread']?> - repartition['main_stream']['favorite']?> - repartition['all_feeds']['favorite']?> + repartition['main_stream']['favorite']?> + repartition['all_feeds']['favorite']?> @@ -55,6 +55,27 @@
+
+

+ + + + + + + + + + topFeed as $feed):?> + + + + + + + +
+