Bug fixes on statistic page

* Statistic page is now more clean with 0 or 1 values (for new Piwigos)
 * Rectification of a mistake in functions_mysqli.inc.php (replace 'groups' by 'rank')
This commit is contained in:
Zacharie
2020-06-17 14:31:15 +02:00
parent 2e70ebf777
commit fd8394df07
3 changed files with 94 additions and 47 deletions
+78 -39
View File
@@ -118,10 +118,21 @@ ORDER BY
' LIMIT '.$limit; ' LIMIT '.$limit;
$result = query2array($query.';'); $result = query2array($query.';');
$lastDate = $date->sub(new DateInterval('P'.($last - 1).'Y'.($date->format('n') - 1).'M')); $lastDate = $date->sub(new DateInterval('P'.($last - 1).'Y'.($date->format('n') - 1).'M'));
return set_missing_values('month', $result, false, $lastDate, new DateTime()); return set_missing_values('month', $result, $lastDate, new DateTime());
} }
return set_missing_values('month', query2array($query.';'), false); if (count(query2array($query.';')) > 1 )
{
return set_missing_values('month', query2array($query.';'));
} else {
$last_year_date = new DateTime();
return set_missing_values(
'month',
query2array($query.';'),
$last_year_date->sub(new DateInterval('P1Y')),
new DateTime()
);
}
} }
function get_month_stats() function get_month_stats()
@@ -182,7 +193,7 @@ ORDER BY
{ {
$lastDate = new DateTime(); $lastDate = new DateTime();
} }
$result['month'][] = set_missing_values('day',$val, false, new DateTime($key), $lastDate); $result['month'][] = set_missing_values('day',$val, new DateTime($key), $lastDate);
} }
$query = ' $query = '
@@ -216,7 +227,7 @@ check_status(ACCESS_ADMINISTRATOR);
// | Refresh summary from details | // | Refresh summary from details |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
history_summarize(); //history_summarize();
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Display statistics header | // | Display statistics header |
@@ -240,22 +251,23 @@ $template->assign(
// | Set missing rows to 0 | // | Set missing rows to 0 |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
function set_missing_values($unit, $data, $keep_size=true, $firstDate = null, $lastDate = null) function set_missing_values($unit, $data, $firstDate = null, $lastDate = null)
{ {
if (count($data) <= 1)
{
return $data;
}
$limit = count($data); $limit = count($data);
$result = array(); $result = array();
if ($firstDate == null) if ($firstDate == null)
{ {
//firstDate is actually the last date when keep_size is true because we want the most recent values first $date = get_date_object($data[count($data) - 1]);
$date = get_date_object($data[0]);
} else { } else {
$date = $firstDate; $date = $firstDate;
} }
if ($lastDate == null)
{
$date_end = get_date_object($data[0]);
} else {
$date_end = $lastDate;
}
//Declare variable according the unit //Declare variable according the unit
if ($unit == 'year') if ($unit == 'year')
@@ -280,24 +292,9 @@ function set_missing_values($unit, $data, $keep_size=true, $firstDate = null, $l
} }
//Fill an empty array with all the dates //Fill an empty array with all the dates
if ($keep_size) while ($date <= $date_end) {
{ $result[$date->format($date_format)] = 0;
for ($i=0; $i < $limit; $i++) $date->add(new DateInterval($date_add));
{
$result[$date->format($date_format)] = 0;
$date->sub(new DateInterval($date_add));
}
} else {
if ($lastDate == null)
{
$date_end = get_date_object($data[0]);
} else {
$date_end = $lastDate;
}
while ($date <= $date_end) {
$result[$date->format($date_format)] = 0;
$date->add(new DateInterval($date_add));
}
} }
//Overload with database rows //Overload with database rows
@@ -341,16 +338,58 @@ function get_date_object($row)
// | Send data to template | // | Send data to template |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
$template->append( $actual_date = new DateTime();
'compareYears', $actual_date->add(new DateInterval('PT1S'));
get_month_of_last_years($conf['stat_compare_year_displayed'])
$first_date = new DateTime();
$last_hours = set_missing_values(
'hour',
get_last(72, 'hour'),
$first_date->sub(new DateInterval("P3D")),
$actual_date
); );
$template->append('monthStats', get_month_stats());
$template->append('lastHours', set_missing_values('hour',get_last(72, 'hour'))); $first_date = new DateTime();
$template->append('lastDays', set_missing_values('day',get_last(90, 'day'))); $last_days = set_missing_values(
$template->append('lastMonths', set_missing_values('month',get_last(24, 'month'))); 'day',
$template->append('lastYears', set_missing_values('year',get_last(60, 'year'))); get_last(90, 'day'),
$template->assign('langCode', strval($user['language'])); $first_date->sub(new DateInterval("P90D")),
$actual_date
);
$first_date = new DateTime();
$last_months = set_missing_values(
'month',
get_last(60, 'month'),
$first_date->sub(new DateInterval("P60M")),
$actual_date
);
if (count(get_last(60, 'year')) > 1 )
{
$last_years = set_missing_values(
'year',
get_last(60, 'year')
);
} else {
$last_year_date = new DateTime();
$last_years = set_missing_values(
'year',
get_last(60, 'year'),
$last_year_date->sub(new DateInterval('P1Y')),
new DateTime()
);
}
$template->assign(array(
'compareYears' => get_month_of_last_years($conf['stat_compare_year_displayed']),
'monthStats' => get_month_stats(),
'lastHours' => $last_hours,
'lastDays' => $last_days,
'lastMonths' => $last_months,
'lastYears' => $last_years,
'langCode' => strval($user['language'])
));
$template->assign_var_from_handle('ADMIN_CONTENT', 'stats'); $template->assign_var_from_handle('ADMIN_CONTENT', 'stats');
?> ?>
+14 -6
View File
@@ -2,12 +2,12 @@
Data Get Data Get
-------*/ -------*/
data = {}; data = {};
data["hours"] = $("#data").data("hours")[0]; data["hours"] = $("#data").data("hours");
data["days"] = $("#data").data("days")[0]; data["days"] = $("#data").data("days");
data["months"] = $("#data").data("months")[0]; data["months"] = $("#data").data("months");
data["years"] = $("#data").data("years")[0]; data["years"] = $("#data").data("years");
data["compare-years"] = $("#data").data("compare-years")[0]; data["compare-years"] = $("#data").data("compare-years");
data["month-stats"] = $("#data").data("month-stats")[0]; data["month-stats"] = $("#data").data("month-stats");
data_unit = { data_unit = {
"hours":"day", "hours":"day",
@@ -70,6 +70,11 @@ function changeData(dataType, options = displayOptions) {
display: false display: false
} }
}], }],
yAxes: [{
ticks: {
min: 0
}
}]
}, },
legend: { legend: {
display:false display:false
@@ -112,6 +117,9 @@ function changeData(dataType, options = displayOptions) {
scaleLabel: { scaleLabel: {
display: true, display: true,
labelString: 'Page visited' labelString: 'Page visited'
},
tick: {
min: 0
} }
}] }]
} }
+2 -2
View File
@@ -140,9 +140,9 @@ function pwg_query($query)
if (preg_match('/\bgroups\b/', $query)) if (preg_match('/\bgroups\b/', $query))
{ {
// first we unescape what's already escaped (to avoid double escaping) // first we unescape what's already escaped (to avoid double escaping)
$query = preg_replace('/`groups`/', 'rank', $query); $query = preg_replace('/`groups`/', 'groups', $query);
// then we escape the keyword // then we escape the keyword
$query = preg_replace('/\bgroups\b/', '`rank`', $query); $query = preg_replace('/\bgroups\b/', '`groups`', $query);
} }
$start = microtime(true); $start = microtime(true);