From 3821f5a7240a9d02bc49bc80589d34bffeef1374 Mon Sep 17 00:00:00 2001 From: Brian Flowers Date: Sun, 9 Apr 2017 17:14:39 -0400 Subject: [PATCH] Minor update to the README --- README | 5 +-- graph2.php | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 graph2.php diff --git a/README b/README index 2f976a2..d4b45c4 100644 --- a/README +++ b/README @@ -2,12 +2,13 @@ bdsm-web A Slightly Cyberpunk project [git|www].slightlycyberpunk.com -bdsm-web is a set of PHP scripts for displaying data from bdsm using HTML5 canvas charts. +bdsm-web is a set of PHP scripts for displaying graphs and data from bdsm +monitors in a web interface, with graphs drawn using HTML5 canvas elements. 0) PREREQUISITES a) bdsm configured using the sqlite3 processor -b) a remotely modern web browser +b) a somewhat modern web browser ((HTML5 support) 1) INSTALLATION INSTRUCTIONS diff --git a/graph2.php b/graph2.php new file mode 100644 index 0000000..42f9ab8 --- /dev/null +++ b/graph2.php @@ -0,0 +1,114 @@ +query("SELECT DISTINCT host FROM MEASUREMENTS"); +} +catch(PDOException $e) +{ + echo 'Connection failed: ' . $e->getMessage(); +} + +if( !$result ) +{ + echo "Error: No data found in database file /home/bdsm/etc/bdsm/bdsm.db"; + echo "Query: SELECT DISTINCT host FROM MEASUREMENTS"; +} + +$colors = Array("#55F", "#5C5", "#F55", "#5FF", "#F5F", "#FF5", "#555"); + +$hosts = Array(); +while($host = $result->fetch()) + if ( $host['host'] ) + array_push($hosts, $host['host']); +$host = urldecode($_GET['host']); + +if( !in_array($host, $hosts) ) + die("Error: Host not found."); +?> + + + + bdsm at monitor.slightlycyberpunk.com | <?php echo $host; ?> + + + +
"; + echo "Error: No configuration found in database file /home/bdsm/etc/bdsm/bdsm.db for host $host
"; + echo "Query: SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1;"; + die(); + } + + $attributes = Array(); + while($attribute = $result->fetch()) + { + if ( $attribute['attribute'] ) + $attributes[$attribute['attribute']] = $attribute['name']; + } + $i = 0; + + foreach (array_keys($attributes) as $attribute) + { + $query = "SELECT printf('%d', timestamp) AS timestamp,value ". + "FROM MEASUREMENTS ". + "WHERE host='$host' AND attribute='$attribute' ". + "ORDER BY timestamp DESC LIMIT 100"; + + $result = $db->query($query); + $record = $result->fetch(); + $final = $record['timestamp']; + $timediff = time() - $final; + + $timestamp = ($timediff % 60)."s"; + if( $timediff > 60 ) + $timestamp = (($timediff / 60) % 60)."m ".$timestamp; + + echo " context.font = '12px monospace';"; + echo " context.strokeStyle = '$colors[$i]';\n"; + echo " context.strokeText('-$timestamp', 350.5, ".(10.5+10*$i).");\n"; + + //echo " context.strokeStyle = '$colors[$i]';\n"; + echo " context.moveTo(0, ".sprintf("%d", $record['value']).");\n"; + echo " context.beginPath();\n"; + while( $record = $result->fetch() ) + { + echo " context.lineTo(".sprintf("%d", $final - $record['timestamp']).", ".(400-$record['value']*4).");\n"; + } + echo " context.stroke();\n"; + + $name = $attributes[$attribute]; + echo " context.strokeText('$name', ".(100*($i%5)+.5).", ".(425+(10*floor($i/5))+.5).");"; + $i+=1; + } +?> + + + + -- 1.8.3.1