Merging apparently split branches
authorDan
Tue, 30 Dec 2008 06:16:54 -0500
changeset 37 c3cbefda414a
parent 36 a7d884914a74 (current diff)
parent 35 a76ae7eaa2eb (diff)
child 38 e6a4b7f91e91
Merging apparently split branches
--- a/htdocs/24hours.php	Tue Dec 30 06:16:28 2008 -0500
+++ b/htdocs/24hours.php	Tue Dec 30 06:16:54 2008 -0500
@@ -1,61 +1,5 @@
 <?php
 
-require('../stats-fe.php');
-require('../graphs.php');
-require('../timezone.php');
-
-$channel_list = stats_channel_list();
-$first_channel = $channel_list[0];
-$channel = ( isset($_REQUEST['channel']) && in_array($_REQUEST['channel'], $channel_list) ) ? $_REQUEST['channel'] : $first_channel;
-
-// generate the data
-// we're doing this by absolute hours, not by strictly "24 hours ago", e.g. on-the-hour stats
-$this_hour = gmmktime(gmdate('H'), 0, 0);
-$graphdata = array();
-
-for ( $i = 23; $i >= 0; $i-- )
-{
-  $basetime = $this_hour - ( $i * 3600 );
-  $ts = date('H:i', $basetime);
-  $basetime += 3600;
-  $graphdata[$ts] = stats_message_count($channel, 60, $basetime);
-}
-
-$max = max($graphdata);
+$_GET['mode'] = 'lastday';
+require('graph.php');
 
-// Determine axis interval
-$interval = 2;
-if ( $max > 20 )
-  $interval = 4;
-if ( $max > 25 )
-  $interval = 5;
-if ( $max > 50 )
-  $interval = 10;
-if ( $max > 200 )
-  $interval = 40;
-if ( $max > 500 )
-  $interval = 80;
-if ( $max > 1000 )
-  $interval = 100;
-if ( $max > 2000 )
-  $interval = 200;
-if ( $max > 5000 )
-  $interval = 1000;
-if ( $max > 15000 )
-  $interval = 1500;
-if ( $max > 30000 )
-  $interval = round($max / 10);
-
-$g = new GraphMaker(); // _Compat();
-
-$g->SetGraphPadding(20, 30, 20, 15);
-$g->SetGraphAreaHeight(200);
-$g->SetBarDimensions(26, 0);
-$g->SetBarPadding(7);
-$g->SetBarData($graphdata);
-$g->SetGraphBackgroundTransparent(240, 250, 255, 0);
-$g->SetGraphTransparency(25);
-$g->SetAxisStep($interval);
-$g->SetGraphTitle($channel . ' message count - last 24 hours');
-
-$g->DrawGraph();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/graph.php	Tue Dec 30 06:16:54 2008 -0500
@@ -0,0 +1,102 @@
+<?php
+require('../stats-fe.php');
+require('../graphs.php');
+require('../timezone.php');
+
+$channel_list = stats_channel_list();
+$first_channel = $channel_list[0];
+$channel = ( isset($_REQUEST['channel']) && in_array($_REQUEST['channel'], $channel_list) ) ? $_REQUEST['channel'] : $first_channel;
+
+$g = new GraphMaker(); // _Compat();
+
+$g->SetGraphPadding(20, 30, 20, 15);
+$g->SetGraphAreaHeight(200);
+$g->SetBarDimensions(26, 0);
+$g->SetBarPadding(7);
+$g->SetGraphBackgroundTransparent(240, 250, 255, 0);
+$g->SetGraphTransparency(25);
+
+// generate the data
+// we're doing this by absolute hours, not by strictly "24 hours ago", e.g. on-the-hour stats
+$mode = ( isset($_GET['mode']) ) ? $_GET['mode'] : 'lastday';
+switch ( $mode )
+{
+  case 'lastday':
+  default:
+    $graph_title = $channel . ' message count - last 24 hours';
+    $this_hour = gmmktime(gmdate('H'), 0, 0);
+    $graphdata = array();
+    
+    for ( $i = 23; $i >= 0; $i-- )
+    {
+      $basetime = $this_hour - ( $i * 3600 );
+      $ts = date('H:i', $basetime);
+      $basetime += 3600;
+      $graphdata[$ts] = stats_message_count($channel, 60, $basetime);
+    }
+    break;
+  case 'lastweek':
+    $graph_title = $channel . ' activity - last 14 days';
+    $this_day = gmmktime(0, 0, 0);
+    $graphdata = array();
+    
+    for ( $i = 13; $i >= 0; $i-- )
+    {
+      $basetime = $this_day - ( $i * 86400 );
+      $ts = date('D n/j', $basetime);
+      $basetime += 86400;
+      $graphdata[$ts] = stats_message_count($channel, 1440, $basetime);
+    }
+    $g->SetBarPadding(12);
+    break;
+  case 'lastmonth':
+    $graph_title = $channel . ' activity - last 30 days';
+    $this_day = gmmktime(0, 0, 0);
+    $graphdata = array();
+    
+    for ( $i = 29; $i >= 0; $i-- )
+    {
+      $basetime = $this_day - ( $i * 86400 );
+      $ts = date('Y-m-d', $basetime);
+      $basetime += 86400;
+      $graphdata[$ts] = stats_message_count($channel, 1440, $basetime);
+    }
+    $g->SetBarPadding(15);
+    break;
+}
+
+$max = max($graphdata);
+
+// Determine axis interval
+$interval = 2;
+if ( $max > 20 )
+  $interval = 4;
+if ( $max > 25 )
+  $interval = 5;
+if ( $max > 50 )
+  $interval = 10;
+if ( $max > 200 )
+  $interval = 40;
+if ( $max > 500 )
+  $interval = 80;
+if ( $max > 1000 )
+  $interval = 100;
+if ( $max > 2000 )
+  $interval = 200;
+if ( $max > 3200 )
+  $interval = 300;
+if ( $max > 4000 )
+  $interval = 500;
+if ( $max > 5000 )
+  $interval = 1000;
+if ( $max > 15000 )
+  $interval = 1500;
+if ( $max > 30000 )
+  $interval = round($max / 10);
+
+$g->SetBarData($graphdata);
+$g->SetAxisStep($interval);
+$g->SetGraphTitle($graph_title);
+
+$g->DrawGraph();
+
--- a/htdocs/index.php	Tue Dec 30 06:16:28 2008 -0500
+++ b/htdocs/index.php	Tue Dec 30 06:16:54 2008 -0500
@@ -83,7 +83,9 @@
       ?>
     </ul>
     <h1>Last 24 hours</h1>
-    <img alt="Graph image" src="24hours.php?channel=<?php echo urlencode($channel); ?>" />
+    <img alt="Graph image" src="graph.php?mode=lastday&amp;channel=<?php echo urlencode($channel); ?>" />
+    <h1>Last 2 weeks</h1>
+    <img alt="Graph image" src="graph.php?mode=lastweek&amp;channel=<?php echo urlencode($channel); ?>" />
     
     <div class="footer">
     <b><?php echo $nick; ?> is a privacy-respecting bot.</b> <a href="privacy.php">Read about what information <?php echo $nick; ?> collects</a>
--- a/htdocs/news.php	Tue Dec 30 06:16:28 2008 -0500
+++ b/htdocs/news.php	Tue Dec 30 06:16:54 2008 -0500
@@ -13,12 +13,15 @@
   </head>
   <body>
     <h1>Updates and changes</h1>
+    <h3>2008-12-24</h3>
+    <p><?php echo $nick; ?> now has modular graph support and thus is able to show different graphs. Included now are options for the last
+       24 hours as before, plus the last two weeks and the last 30 days. More, of course, can be added if needed.</p>
+    <h3>2008-11-15</h3>
     <p>I've been updating <?php echo $nick; ?> recently with some really cool enhancements to the back-end. This is more technical stuff
        so you might want to read on only if you're a geek.</p>
     <p><?php echo $nick; ?> only stores info with MySQL now. All the stats go into a MySQL table that had an initial size of over 360,000
-       records after the import of the existing flat file database. This means that while querying can be slower (things aren't split up
-       like they were with the flatfile DB) it's a more portable programming technique and it means it can be easily expanded in the
-       future to include more data. The table's indexed so it should be decently fast.</p>
+       records after the import of the existing flat file database. It makes for a more portable programming technique and it means it can
+       be easily expanded in the future to include more data. The table's indexed so it should be decently fast.</p>
     <p>In addition, smarter functionality is being included, plus a few bugs here and there have been fixed.</p>
   </body>
 </head>