Add average on repartition charts.

It needs some verification on the value used to calculate the averages.
This commit is contained in:
Alexis Degrugillier committed 2014-09-01 20:58:05 -04:00
1 parent a126d99b3c
commit f002dbe4ce
3 files changed
+107 -6

No files matched your search

+3
View File
@@ -67,8 +67,11 @@ class FreshRSS_stats_Controller extends Minz_ActionController {
$this->view->days = $statsDAO->getDays();
$this->view->months = $statsDAO->getMonths();
$this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id);
$this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id);
$this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id);
$this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id);
$this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id);
$this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id);
}
public function firstAction() {
+62
View File
@@ -151,6 +151,68 @@ SQL;
return $this->convertToSerie($repartition);
}
/**
* Calculates the average number of article per hour per feed
*
* @param integer $feed id
* @return integer
*/
public function calculateEntryAveragePerFeedPerHour($feed = null) {
return $this->calculateEntryAveragePerFeedPerPeriod(1/24, $feed);
}
/**
* Calculates the average number of article per day of week per feed
*
* @param integer $feed id
* @return integer
*/
public function calculateEntryAveragePerFeedPerDayOfWeek($feed = null) {
return $this->calculateEntryAveragePerFeedPerPeriod(7, $feed);
}
/**
* Calculates the average number of article per month per feed
*
* @param integer $feed id
* @return integer
*/
public function calculateEntryAveragePerFeedPerMonth($feed = null) {
return $this->calculateEntryAveragePerFeedPerPeriod(30, $feed);
}
/**
* Calculates the average number of article per feed
*
* @param float $period number used to divide the number of day in the period
* @param integer $feed id
* @return integer
*/
protected function calculateEntryAveragePerFeedPerPeriod($period, $feed = null) {
if ($feed) {
$restrict = "WHERE e.id_feed = {$feed}";
} else {
$restrict = '';
}
$sql = <<<SQL
SELECT COUNT(1) AS count
, MIN(date) AS date_min
, MAX(date) AS date_max
FROM {$this->prefix}entry AS e
{$restrict}
SQL;
$stm = $this->bd->prepare($sql);
$stm->execute();
$res = $stm->fetch(PDO::FETCH_NAMED);
$date_min = new \DateTime();
$date_min->setTimestamp($res['date_min']);
$date_max = new \DateTime();
$date_max->setTimestamp($res['date_max']);
$interval = $date_max->diff($date_min, true);
return round($res['count'] / ($interval->format('%a') / ($period)), 2);
}
/**
* Initialize an array for statistics depending on a range
*
+42 -6
View File
@@ -56,11 +56,22 @@ function initStats() {
return;
}
// Entry per hour
var avg_h = [];
for (var i = -1; i <= 24; i++) {
avg_h.push([i, <?php echo $this->averageHour?>]);
}
Flotr.draw(document.getElementById('statsEntryPerHour'),
[<?php echo $this->repartitionHour ?>],
[{
data: <?php echo $this->repartitionHour ?>,
bars: {horizontal: false, show: true}
}, {
data: avg_h,
lines: {show: true},
label: <?php echo $this->averageHour?>,
yaxis: 2
}],
{
grid: {verticalLines: false},
bars: {horizontal: false, show: true},
xaxis: {noTicks: 23,
tickFormatter: function(x) {
var x = parseInt(x);
@@ -70,14 +81,26 @@ function initStats() {
max: 23.9,
tickDecimals: 0},
yaxis: {min: 0},
y2axis: {showLabels: false},
mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
});
// Entry per day of week
var avg_dow = [];
for (var i = -1; i <= 7; i++) {
avg_dow.push([i, <?php echo $this->averageDayOfWeek?>]);
}
Flotr.draw(document.getElementById('statsEntryPerDayOfWeek'),
[<?php echo $this->repartitionDayOfWeek ?>],
[{
data: <?php echo $this->repartitionDayOfWeek ?>,
bars: {horizontal: false, show: true}
}, {
data: avg_dow,
lines: {show: true},
label: <?php echo $this->averageDayOfWeek?>,
yaxis: 2
}],
{
grid: {verticalLines: false},
bars: {horizontal: false, show: true},
xaxis: {noTicks: 6,
tickFormatter: function(x) {
var x = parseInt(x),
@@ -88,14 +111,26 @@ function initStats() {
max: 6.9,
tickDecimals: 0},
yaxis: {min: 0},
y2axis: {showLabels: false},
mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
});
// Entry per month
var avg_m = [];
for (var i = 0; i <= 13; i++) {
avg_m.push([i, <?php echo $this->averageMonth?>]);
}
Flotr.draw(document.getElementById('statsEntryPerMonth'),
[<?php echo $this->repartitionMonth ?>],
[{
data: <?php echo $this->repartitionMonth ?>,
bars: {horizontal: false, show: true}
}, {
data: avg_m,
lines: {show: true},
label: <?php echo $this->averageMonth?>,
yaxis: 2
}],
{
grid: {verticalLines: false},
bars: {horizontal: false, show: true},
xaxis: {noTicks: 12,
tickFormatter: function(x) {
var x = parseInt(x),
@@ -106,6 +141,7 @@ function initStats() {
max: 12.9,
tickDecimals: 0},
yaxis: {min: 0},
y2axis: {showLabels: false},
mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
});