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..89be76a26 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('%H', $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/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php index dea590c92..6cb54ddf6 100644 --- a/app/Models/StatsDAOSQLite.php +++ b/app/Models/StatsDAOSQLite.php @@ -28,10 +28,36 @@ SQL; $res = $stm->fetchAll(PDO::FETCH_ASSOC); foreach ($res as $value) { - $count[(int)$value['day']] = (int) $value['count']; + $count[(int) $value['day']] = (int) $value['count']; } return $this->convertToSerie($count); } + 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); + } + } 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 7eebc569b..cc04e757c 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -77,6 +77,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..09892d3c5 --- /dev/null +++ b/app/views/stats/repartition.phtml @@ -0,0 +1,99 @@ +partial('aside_stats'); ?> + +
+ + + feed) {?> +

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

+ +

+ + +
+

+
+
+ +
+

+
+
+ +
+

+
+
+
+ +