htdocs/24hours.php
author Dan
Sat, 11 Oct 2008 23:09:13 +0000
changeset 14 506a7e0fb106
parent 12 7f043e712c35
child 20 e2f6e3af9959
permissions -rw-r--r--
Disabled "snippet not found" message, for now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     1
<?php
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     2
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     3
require('../stats-fe.php');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     4
require('../graphs.php');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     5
require('../timezone.php');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     6
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     7
$first_channel = array_keys($stats_data['messages']);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     8
$first_channel = $first_channel[0];
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     9
$channel = ( isset($_REQUEST['channel']) && isset($stats_data['messages'][$_REQUEST['channel']]) ) ? $_REQUEST['channel'] : $first_channel;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    10
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    11
// generate the data
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    12
// we're doing this by absolute hours, not by strictly "24 hours ago", e.g. on-the-hour stats
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    13
$this_hour = gmmktime(gmdate('H'), 0, 0);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    14
$graphdata = array();
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    15
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    16
for ( $i = 23; $i >= 0; $i-- )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    17
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    18
  $basetime = $this_hour - ( $i * 3600 );
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    19
  $ts = date('H:i', $basetime);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    20
  $basetime += 3600;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    21
  $graphdata[$ts] = stats_message_count($channel, 60, $basetime);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    22
}
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    23
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    24
$max = max($graphdata);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    25
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    26
// Determine axis interval
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    27
$interval = 2;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    28
if ( $max > 20 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    29
  $interval = 4;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    30
if ( $max > 25 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    31
  $interval = 5;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    32
if ( $max > 50 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    33
  $interval = 10;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    34
if ( $max > 200 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    35
  $interval = 40;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    36
if ( $max > 500 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    37
  $interval = 80;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    38
if ( $max > 1000 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    39
  $interval = 100;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    40
if ( $max > 2000 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    41
  $interval = 200;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    42
if ( $max > 5000 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    43
  $interval = 1000;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    44
if ( $max > 15000 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    45
  $interval = 1500;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    46
if ( $max > 30000 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    47
  $interval = round($max / 10);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    48
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    49
$g = new GraphMaker(); // _Compat();
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    50
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    51
$g->SetGraphPadding(20, 30, 20, 15);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    52
$g->SetGraphAreaHeight(200);
12
7f043e712c35 Packed graphs a little tighter
Dan
parents: 8
diff changeset
    53
$g->SetBarDimensions(26, 0);
7f043e712c35 Packed graphs a little tighter
Dan
parents: 8
diff changeset
    54
$g->SetBarPadding(7);
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    55
$g->SetBarData($graphdata);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    56
$g->SetGraphBackgroundTransparent(240, 250, 255, 0);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    57
$g->SetGraphTransparency(25);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    58
$g->SetAxisStep($interval);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    59
$g->SetGraphTitle($channel . ' message count - last 24 hours');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    60
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    61
$g->DrawGraph();