2014-07-23 15:52:50 +02:00
|
|
|
<?php
|
|
|
|
|
2014-09-27 10:10:43 +02:00
|
|
|
/**
|
|
|
|
* Controller to handle application statistics.
|
|
|
|
*/
|
2014-07-23 15:52:50 +02:00
|
|
|
class FreshRSS_stats_Controller extends Minz_ActionController {
|
|
|
|
|
2014-09-27 10:10:43 +02:00
|
|
|
/**
|
|
|
|
* This action handles the statistic main page.
|
|
|
|
*
|
|
|
|
* It displays the statistic main page.
|
|
|
|
* The values computed to display the page are:
|
|
|
|
* - repartition of read/unread/favorite/not favorite
|
|
|
|
* - number of article per day
|
|
|
|
* - number of feed by category
|
|
|
|
* - number of article by category
|
|
|
|
* - list of most prolific feed
|
|
|
|
*/
|
2014-07-23 15:52:50 +02:00
|
|
|
public function indexAction() {
|
|
|
|
$statsDAO = FreshRSS_Factory::createStatsDAO();
|
2014-09-21 12:12:35 +02:00
|
|
|
Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
|
2014-07-23 15:52:50 +02:00
|
|
|
$this->view->repartition = $statsDAO->calculateEntryRepartition();
|
2014-09-21 12:12:35 +02:00
|
|
|
$this->view->count = $statsDAO->calculateEntryCount();
|
2014-07-23 15:52:50 +02:00
|
|
|
$this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
|
|
|
|
$this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
|
|
|
|
$this->view->topFeed = $statsDAO->calculateTopFeed();
|
|
|
|
}
|
|
|
|
|
2014-09-27 10:10:43 +02:00
|
|
|
/**
|
|
|
|
* This action handles the idle feed statistic page.
|
|
|
|
*
|
|
|
|
* It displays the list of idle feed for different period. The supported
|
|
|
|
* periods are:
|
|
|
|
* - last year
|
|
|
|
* - last 6 months
|
|
|
|
* - last 3 months
|
|
|
|
* - last month
|
|
|
|
* - last week
|
|
|
|
*/
|
2014-07-23 15:52:50 +02:00
|
|
|
public function idleAction() {
|
|
|
|
$statsDAO = FreshRSS_Factory::createStatsDAO();
|
|
|
|
$feeds = $statsDAO->calculateFeedLastDate();
|
2014-09-21 12:12:35 +02:00
|
|
|
$idleFeeds = array(
|
|
|
|
'last_year' => array(),
|
|
|
|
'last_6_month' => array(),
|
|
|
|
'last_3_month' => array(),
|
|
|
|
'last_month' => array(),
|
|
|
|
'last_week' => array(),
|
|
|
|
);
|
2014-07-23 15:52:50 +02:00
|
|
|
$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 < $lastYear) {
|
2014-09-21 12:12:35 +02:00
|
|
|
$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;
|
2014-07-23 15:52:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 12:12:35 +02:00
|
|
|
$this->view->idleFeeds = $idleFeeds;
|
2014-07-23 15:52:50 +02:00
|
|
|
}
|
2014-09-21 12:12:35 +02:00
|
|
|
|
2014-09-27 10:10:43 +02:00
|
|
|
/**
|
|
|
|
* This action handles the article repartition statistic page.
|
|
|
|
*
|
|
|
|
* It displays the number of article and the average of article for the
|
|
|
|
* following periods:
|
|
|
|
* - hour of the day
|
|
|
|
* - day of the week
|
|
|
|
* - month
|
|
|
|
*
|
|
|
|
* @todo verify that the metrics used here make some sense. Especially
|
|
|
|
* for the average.
|
|
|
|
*/
|
2014-09-21 12:12:35 +02:00
|
|
|
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();
|
|
|
|
$this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id);
|
2014-09-27 10:10:43 +02:00
|
|
|
$this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id);
|
2014-09-21 12:12:35 +02:00
|
|
|
$this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id);
|
2014-09-27 10:10:43 +02:00
|
|
|
$this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id);
|
2014-09-21 12:12:35 +02:00
|
|
|
$this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id);
|
2014-09-27 10:10:43 +02:00
|
|
|
$this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id);
|
2014-09-21 12:12:35 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 10:10:43 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-07-23 15:52:50 +02:00
|
|
|
public function firstAction() {
|
|
|
|
if (!$this->view->loginOk) {
|
|
|
|
Minz_Error::error(
|
|
|
|
403, array('error' => array(Minz_Translate::t('access_denied')))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|