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