1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-28 01:10:51 +01:00

option to graph post rates by 'minute', 'day', 'year', etc.

This commit is contained in:
Savetheinternet 2011-12-23 13:07:52 +11:00
parent 0dd36bda54
commit d60658736e
2 changed files with 34 additions and 12 deletions

View File

@ -58,23 +58,30 @@
);
$theme['config'][] = Array(
'title' => 'Width',
'title' => 'Graph Width',
'name' => 'width',
'type' => 'text',
'comment' => '(graph width)',
'size' => 3,
'default' => '700'
);
$theme['config'][] = Array(
'title' => 'Height',
'title' => 'Graph Height',
'name' => 'height',
'type' => 'text',
'comment' => '(graph height)',
'size' => 3,
'default' => '150'
);
$theme['config'][] = Array(
'title' => 'Graph Rate',
'name' => 'rate',
'type' => 'text',
'comment' => 'Graph posts per X? ("minute", "day", "year", etc.)',
'size' => 3,
'default' => 'hour'
);
$theme['install_callback'] = 'rrdtool_install';
if(!function_exists('rrdtool_install')) {
function rrdtool_install($settings) {
@ -89,6 +96,9 @@
if(!is_numeric($settings['height']) || $settings['height'] < 1)
return Array(false, 'Invalid height: <strong>' . $settings['height'] . '</strong>!');
if(!in_array($settings['rate'], Array('second', 'minute', 'day', 'hour', 'week', 'month', 'year')))
return Array(false, 'Invalid rate: <strong>' . $settings['rate'] . '</strong>!');
$job = '*/' . $settings['interval'] . ' * * * * php -q ' . str_replace('\\', '/', dirname(__FILE__)) . '/cron.php' . PHP_EOL;
if(function_exists('system')) {

View File

@ -86,13 +86,20 @@
'-E',
'-X', '0',
'-Y',
'-v posts/minute',
'-v posts/' . $settings['rate'],
'DEF:posts-second=' . $file . ':posts:AVERAGE',
'CDEF:posts-minute=posts-second,60,*',
'CDEF:posts-hour=posts-minute,60,*',
'CDEF:posts-day=posts-hour,24,*',
'CDEF:posts-week=posts-day,7,*',
'CDEF:posts-month=posts-day,28,*',
'CDEF:posts-year=posts-day,365,*',
'DEF:posts=' . $file . ':posts:AVERAGE',
'CDEF:posts-min=posts,60,*',
'LINE2:posts-min#663300:Posts',
'GPRINT:posts-min:MAX:Max\\: %5.2lf',
'GPRINT:posts-min:AVERAGE:Average\\: %5.2lf',
'GPRINT:posts-min:LAST:Current\\: %5.2lf posts/min',
'GPRINT:posts-' . $settings['rate'] . ':MAX:Max\\: %5.2lf',
'GPRINT:posts-' . $settings['rate'] . ':AVERAGE:Average\\: %5.2lf',
'GPRINT:posts-' . $settings['rate'] . ':LAST:Current\\: %5.2lf posts/' . $settings['rate'],
'HRULE:0#000000')))
error('RRDtool failed: ' . htmlentities(rrd_error()));
}
@ -112,7 +119,7 @@
'-E',
'-X', '0',
'-Y',
'-v posts/minute');
'-v posts/' . $settings['rate']);
$red = 0;
$green = 0;
@ -130,9 +137,14 @@
str_pad(dechex($green*85), 2, '0', STR_PAD_LEFT) .
str_pad(dechex($blue*85), 2, '0', STR_PAD_LEFT);
$options[] = 'DEF:posts' . $board . '=' . $settings['path'] . '/' . $board . '.rrd' . ':posts:AVERAGE';
$options[] = 'CDEF:posts' . $board . '-min=posts' . $board . ',60,*';
$options[] = 'LINE2:posts' . $board . '-min#' . $color . ':' .
$options[] = 'DEF:posts' . $board . '-second=' . $settings['path'] . '/' . $board . '.rrd' . ':posts:AVERAGE';
$options[] = 'CDEF:posts' . $board . '-minute=posts' . $board . '-second,60,*';
$options[] = 'CDEF:posts' . $board . '-hour=posts' . $board . '-minute,60,*';
$options[] = 'CDEF:posts' . $board . '-day=posts' . $board . '-hour,24,*';
$options[] = 'CDEF:posts' . $board . '-week=posts' . $board . '-day,7,*';
$options[] = 'CDEF:posts' . $board . '-month=posts' . $board . '-day,28,*';
$options[] = 'CDEF:posts' . $board . '-year=posts' . $board . '-day,365,*';
$options[] = 'LINE2:posts' . $board . '-' . $settings['rate'] . '#' . $color . ':' .
sprintf($config['board_abbreviation'], $board);
// Randomize colors using this horrible undocumented algorithm I threw together while debugging