aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/statsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers/statsController.php')
-rw-r--r--app/Controllers/statsController.php66
1 files changed, 43 insertions, 23 deletions
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php
index 0e3430fcc..5d1dee72c 100644
--- a/app/Controllers/statsController.php
+++ b/app/Controllers/statsController.php
@@ -6,6 +6,40 @@
class FreshRSS_stats_Controller extends Minz_ActionController {
/**
+ * This action is called before every other action in that class. It is
+ * the common boiler plate for every action. It is triggered by the
+ * underlying framework.
+ */
+ public function firstAction() {
+ if (!FreshRSS_Auth::hasAccess()) {
+ Minz_Error::error(403);
+ }
+
+ Minz_View::prependTitle(_t('admin.stats.title') . ' · ');
+ }
+
+ private function convertToSerie($data) {
+ $serie = array();
+
+ foreach ($data as $key => $value) {
+ $serie[] = array($key, $value);
+ }
+
+ return $serie;
+ }
+
+ private function convertToPieSerie($data) {
+ $serie = array();
+
+ foreach ($data as $value) {
+ $value['data'] = array(array(0, (int) $value['data']));
+ $serie[] = $value;
+ }
+
+ return $serie;
+ }
+
+ /**
* This action handles the statistic main page.
*
* It displays the statistic main page.
@@ -20,10 +54,11 @@ class FreshRSS_stats_Controller extends Minz_ActionController {
$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();
- $this->view->average = $statsDAO->calculateEntryAverage();
- $this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
- $this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
+ $entryCount = $statsDAO->calculateEntryCount();
+ $this->view->count = $this->convertToSerie($entryCount);
+ $this->view->average = round(array_sum(array_values($entryCount)) / count($entryCount), 2);
+ $this->view->feedByCategory = $this->convertToPieSerie($statsDAO->calculateFeedByCategory());
+ $this->view->entryByCategory = $this->convertToPieSerie($statsDAO->calculateEntryByCategory());
$this->view->topFeed = $statsDAO->calculateTopFeed();
}
@@ -104,27 +139,12 @@ class FreshRSS_stats_Controller extends Minz_ActionController {
$this->view->feed = $feedDAO->searchById($id);
$this->view->days = $statsDAO->getDays();
$this->view->months = $statsDAO->getMonths();
- $this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id);
+ $this->view->repartition = $statsDAO->calculateEntryRepartitionPerFeed($id);
+ $this->view->repartitionHour = $this->convertToSerie($statsDAO->calculateEntryRepartitionPerFeedPerHour($id));
$this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id);
- $this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id);
+ $this->view->repartitionDayOfWeek = $this->convertToSerie($statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id));
$this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id);
- $this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id);
+ $this->view->repartitionMonth = $this->convertToSerie($statsDAO->calculateEntryRepartitionPerFeedPerMonth($id));
$this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id);
}
-
- /**
- * This action is called before every other action in that class. It is
- * the common boiler plate for every action. It is triggered by the
- * underlying framework.
- */
- public function firstAction() {
- if (!FreshRSS_Auth::hasAccess()) {
- Minz_Error::error(
- 403, array('error' => array(_t('access_denied')))
- );
- }
-
- Minz_View::prependTitle(_t('stats') . ' · ');
- }
-
}