Added display of configured options
authorBrian Flowers <git-admn@bsflowers.net>
Mon, 10 Oct 2016 19:22:22 +0000 (15:22 -0400)
committerBrian Flowers <git-admn@bsflowers.net>
Mon, 10 Oct 2016 19:22:22 +0000 (15:22 -0400)
index.php

index 4f74185..60b6b10 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -95,33 +95,37 @@ foreach ($hosts as $host)
       context.lineWidth = 2;
 <?php
 
-  $result = $db_handle->query("SELECT DISTINCT attribute FROM MEASUREMENTS WHERE host='$host'");
+  $result = $db_handle->query("SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1");
   $attributes = Array();
   while($attribute = $result->fetchArray(SQLITE3_ASSOC))
+  {
+      print_r($attribute);
     if ( $attribute['attribute'] )
-      array_push($attributes, $attribute['attribute']);
+      $attributes[$attribute['attribute']] = $attribute['name'];
+  }
 
   $i = 0;
-  foreach ($attributes as $attribute)
+  foreach (array_keys($attributes) as $attribute)
     {
-    $query = "SELECT timestamp,value ".
+    $query = "SELECT printf('%d', timestamp) AS timestamp,value ".
               "FROM MEASUREMENTS ".
               "WHERE host='$host' AND attribute='$attribute' ".
               "ORDER BY timestamp DESC LIMIT 100";
-echo "// $query \n";
+
     $result = $db_handle->query($query);
     echo "      context.beginPath();\n";
     echo "      context.strokeStyle = '$colors[$i]';\n";
     $record = $result->fetchArray(SQLITE3_ASSOC);
     $final = $record['timestamp'];
-    echo "      context.moveTo(0, ".$record['value'].");\n";
+    echo "      context.moveTo(0, ".sprintf("%d", $record['value']"".");\n";
     while( $record = $result->fetchArray(SQLITE3_ASSOC) )
       {
-      echo "      context.lineTo(".($final - $record['timestamp']).", ".(400-$record['value']*4).");\n";
+      echo "      context.lineTo(".sprintf("%d", $final - $record['timestamp']).", ".(400-$record['value']*4).");\n";
       }
     echo "      context.stroke();\n";
 
-    echo "      context.strokeText('$attribute', 300, ".(395-15*$i).");";
+    $name = $attributes[$attribute];
+    echo "      context.strokeText('$name', 300, ".(395-15*$i).");";
     $i+=1;
     }
 ?>