From 804a5e90fbab0bb1a5bef320bfbd57287561f653 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 21 Feb 2025 21:16:19 -0300 Subject: [PATCH] Update graph period handling to support dynamic input --- wgrrd/views.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/wgrrd/views.py b/wgrrd/views.py index 034160d..1903f4f 100644 --- a/wgrrd/views.py +++ b/wgrrd/views.py @@ -38,19 +38,13 @@ def view_rrd_graph(request): with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file: graph_file = tmp_file.name - #command = [ - # "rrdtool", "graph", graph_file, - # "--start", "-6h", - # "--title", "RRD Data Graph", - # "--vertical-label", "Value", - # f"DEF:txdata={rrd_file_path}:tx:AVERAGE", - # f"DEF:rxdata={rrd_file_path}:rx:AVERAGE", - # "LINE1:txdata#FF0000:Transmitted", - # "LINE1:rxdata#0000FF:Received" - #] + + period = request.GET.get('period', '6h') + if not (period[:-1].isdigit() and period[-1] in ['h', 'd']): + period = '6h' command = [ "rrdtool", "graph", graph_file, - "--start", "-6h", + "--start", f"-{period}", "--title", "RRD Data Graph", "--vertical-label", "Value", f"DEF:txdata={rrd_file_path}:tx:AVERAGE",