htdocs/graph.php
author Dan
Wed, 31 Dec 2008 21:54:19 -0500
changeset 39 4027a5b47db5
parent 34 a8daa2016cf1
child 43 ce2e9caf2dfa
permissions -rw-r--r--
echo: added ability to PM people with !pm [nick] [message]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     1
<?php
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     2
require('../stats-fe.php');
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     3
require('../graphs.php');
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     4
require('../timezone.php');
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     5
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     6
$channel_list = stats_channel_list();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     7
$first_channel = $channel_list[0];
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     8
$channel = ( isset($_REQUEST['channel']) && in_array($_REQUEST['channel'], $channel_list) ) ? $_REQUEST['channel'] : $first_channel;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
     9
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    10
$g = new GraphMaker(); // _Compat();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    11
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    12
$g->SetGraphPadding(20, 30, 20, 15);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    13
$g->SetGraphAreaHeight(200);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    14
$g->SetBarDimensions(26, 0);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    15
$g->SetBarPadding(7);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    16
$g->SetGraphBackgroundTransparent(240, 250, 255, 0);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    17
$g->SetGraphTransparency(25);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    18
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    19
// generate the data
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    20
// we're doing this by absolute hours, not by strictly "24 hours ago", e.g. on-the-hour stats
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    21
$mode = ( isset($_GET['mode']) ) ? $_GET['mode'] : 'lastday';
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    22
switch ( $mode )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    23
{
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    24
  case 'lastday':
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    25
  default:
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    26
    $graph_title = $channel . ' message count - last 24 hours';
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    27
    $this_hour = gmmktime(gmdate('H'), 0, 0);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    28
    $graphdata = array();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    29
    
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    30
    for ( $i = 23; $i >= 0; $i-- )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    31
    {
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    32
      $basetime = $this_hour - ( $i * 3600 );
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    33
      $ts = date('H:i', $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    34
      $basetime += 3600;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    35
      $graphdata[$ts] = stats_message_count($channel, 60, $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    36
    }
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    37
    break;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    38
  case 'lastweek':
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    39
    $graph_title = $channel . ' activity - last 14 days';
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    40
    $this_day = gmmktime(0, 0, 0);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    41
    $graphdata = array();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    42
    
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    43
    for ( $i = 13; $i >= 0; $i-- )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    44
    {
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    45
      $basetime = $this_day - ( $i * 86400 );
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    46
      $ts = date('D n/j', $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    47
      $basetime += 86400;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    48
      $graphdata[$ts] = stats_message_count($channel, 1440, $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    49
    }
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    50
    $g->SetBarPadding(12);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    51
    break;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    52
  case 'lastmonth':
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    53
    $graph_title = $channel . ' activity - last 30 days';
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    54
    $this_day = gmmktime(0, 0, 0);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    55
    $graphdata = array();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    56
    
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    57
    for ( $i = 29; $i >= 0; $i-- )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    58
    {
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    59
      $basetime = $this_day - ( $i * 86400 );
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    60
      $ts = date('Y-m-d', $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    61
      $basetime += 86400;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    62
      $graphdata[$ts] = stats_message_count($channel, 1440, $basetime);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    63
    }
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    64
    $g->SetBarPadding(15);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    65
    break;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    66
}
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    67
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    68
$max = max($graphdata);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    69
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    70
// Determine axis interval
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    71
$interval = 2;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    72
if ( $max > 20 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    73
  $interval = 4;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    74
if ( $max > 25 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    75
  $interval = 5;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    76
if ( $max > 50 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    77
  $interval = 10;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    78
if ( $max > 200 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    79
  $interval = 40;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    80
if ( $max > 500 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    81
  $interval = 80;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    82
if ( $max > 1000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    83
  $interval = 100;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    84
if ( $max > 2000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    85
  $interval = 200;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    86
if ( $max > 3200 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    87
  $interval = 300;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    88
if ( $max > 4000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    89
  $interval = 500;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    90
if ( $max > 5000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    91
  $interval = 1000;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    92
if ( $max > 15000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    93
  $interval = 1500;
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    94
if ( $max > 30000 )
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    95
  $interval = round($max / 10);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    96
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    97
$g->SetBarData($graphdata);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    98
$g->SetAxisStep($interval);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
    99
$g->SetGraphTitle($graph_title);
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
   100
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
   101
$g->DrawGraph();
a8daa2016cf1 Added support for last month and last 2 weeks graphs; adjusted web interface accordingly
Dan
parents:
diff changeset
   102