From 29200d6469e39e614ec8c261d537b3a225bc7435 Mon Sep 17 00:00:00 2001 From: Nirgal Date: Wed, 16 Oct 2019 11:10:19 +0000 Subject: [PATCH] graph: Added support for days and steps --- html/graph.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/html/graph.php b/html/graph.php index 9f6f4e7..34f73ba 100644 --- a/html/graph.php +++ b/html/graph.php @@ -4,14 +4,16 @@ require("config.php"); $IMGFILE="/tmp/power.svg"; +$days = array_key_exists('d', $_REQUEST) ? (int)$_REQUEST['d'] : 0; $hours = array_key_exists('h', $_REQUEST) ? (int)$_REQUEST['h'] : 0; $minutes = array_key_exists('m', $_REQUEST) ? (int)$_REQUEST['m'] : 0; -if (!$hours && !$minutes) +if (!$days && !$hours && !$minutes) $hours = 1; +$step = array_key_exists('step', $_REQUEST) ? (int)$_REQUEST['step'] : 0; $params = [ "--daemon", RRDSOCK, "--imgformat", "SVG", - "-s", "now-".$hours."h".$minutes."m", + "-s", "now-".$days."d".$hours."h".$minutes."m", "--width", "".IMGWIDTH, "--height", "".IMGHEIGHT, "--vertical-label", "watts", @@ -29,6 +31,10 @@ $params = [ #"LINE:maxwatts#0000FF", #"GPRINT:maxwatts:Max %6.2lf %sW", ]; +if ($step) { + $params[] = '--step'; + $params[] = "$step"; +} /*header("Content-Type: text/plain"); foreach ($params as $param) echo(escapeshellarg($param)." "); @@ -42,6 +48,6 @@ if ($result === FALSE) { } header("Content-Type: image/svg+xml"); header("Cache-Control: no-cache, max-age=0, must-revalidate"); -header("Refresh: ".(60*(60*$hours)+$minutes)/IMGWIDTH); +header("Refresh: ".(60*(60*(24*$days+$hours))+$minutes)/IMGWIDTH); readfile($IMGFILE); ?> -- 2.30.2