From f78c290074ac730fd7e1d7f62e6b082c9d8f1946 Mon Sep 17 00:00:00 2001 From: dohertj2 Date: Sun, 22 Feb 2026 06:07:14 -0500 Subject: [PATCH] Add time range buttons (1H/6H/24H) to flow rate popup Replace static tag-history binding with expression binding using runScript to call flowrate.queryHistory(), which dynamically queries tag history based on the selected time range. Buttons highlight blue when active, grey when inactive. Co-Authored-By: Claude Opus 4.6 --- .../views/FlowRatePopup/view.json | 83 ++----------------- .../ignition/script-python/flowrate/code.py | 14 ++++ .../script-python/flowrate/resource.json | 16 ++++ 3 files changed, 39 insertions(+), 74 deletions(-) create mode 100644 projects/watermeter/ignition/script-python/flowrate/code.py create mode 100644 projects/watermeter/ignition/script-python/flowrate/resource.json diff --git a/projects/watermeter/com.inductiveautomation.perspective/views/FlowRatePopup/view.json b/projects/watermeter/com.inductiveautomation.perspective/views/FlowRatePopup/view.json index 661b722..3c22fb3 100644 --- a/projects/watermeter/com.inductiveautomation.perspective/views/FlowRatePopup/view.json +++ b/projects/watermeter/com.inductiveautomation.perspective/views/FlowRatePopup/view.json @@ -1,7 +1,6 @@ { "custom": { - "timeAmount": 1, - "timeUnits": "HOUR" + "timeHours": 1 }, "params": {}, "props": { @@ -19,7 +18,7 @@ "dom": { "onClick": { "config": { - "script": "\tself.view.custom.timeAmount = 1\n\tself.view.custom.timeUnits = \"HOUR\"" + "script": "\tself.view.custom.timeHours = 1" }, "scope": "G", "type": "script" @@ -37,7 +36,7 @@ "props.style.backgroundColor": { "binding": { "config": { - "expression": "if({view.custom.timeAmount} = 1 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')" + "expression": "if({view.custom.timeHours} = 1, '#4747FF', '#AAAAAA')" }, "type": "expr" } @@ -58,7 +57,7 @@ "dom": { "onClick": { "config": { - "script": "\tself.view.custom.timeAmount = 6\n\tself.view.custom.timeUnits = \"HOUR\"" + "script": "\tself.view.custom.timeHours = 6" }, "scope": "G", "type": "script" @@ -76,7 +75,7 @@ "props.style.backgroundColor": { "binding": { "config": { - "expression": "if({view.custom.timeAmount} = 6 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')" + "expression": "if({view.custom.timeHours} = 6, '#4747FF', '#AAAAAA')" }, "type": "expr" } @@ -97,7 +96,7 @@ "dom": { "onClick": { "config": { - "script": "\tself.view.custom.timeAmount = 24\n\tself.view.custom.timeUnits = \"HOUR\"" + "script": "\tself.view.custom.timeHours = 24" }, "scope": "G", "type": "script" @@ -115,7 +114,7 @@ "props.style.backgroundColor": { "binding": { "config": { - "expression": "if({view.custom.timeAmount} = 24 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')" + "expression": "if({view.custom.timeHours} = 24, '#4747FF', '#AAAAAA')" }, "type": "expr" } @@ -130,45 +129,6 @@ "text": "24H" }, "type": "ia.input.button" - }, - { - "events": { - "dom": { - "onClick": { - "config": { - "script": "\tself.view.custom.timeAmount = 7\n\tself.view.custom.timeUnits = \"DAY\"" - }, - "scope": "G", - "type": "script" - } - } - }, - "meta": { - "name": "Btn7D" - }, - "position": { - "basis": "60px", - "shrink": 0 - }, - "propConfig": { - "props.style.backgroundColor": { - "binding": { - "config": { - "expression": "if({view.custom.timeAmount} = 7 && \"{view.custom.timeUnits}\" = \"DAY\", '#4747FF', '#AAAAAA')" - }, - "type": "expr" - } - } - }, - "props": { - "style": { - "color": "#FFFFFF", - "fontWeight": "bold", - "margin": 2 - }, - "text": "7D" - }, - "type": "ia.input.button" } ], "meta": { @@ -202,34 +162,9 @@ "props.series[0].data": { "binding": { "config": { - "aggregate": "Average", - "avoidScanClassValidation": true, - "dateRange": { - "mostRecent": "{view.custom.timeAmount}", - "mostRecentUnits": "{view.custom.timeUnits}" - }, - "enableValueCache": true, - "ignoreBadQuality": false, - "polling": { - "enabled": true, - "rate": "30" - }, - "preventInterpolation": false, - "returnFormat": "Wide", - "returnSize": { - "delay": "1", - "delayUnits": "MIN", - "type": "INTERVAL" - }, - "tags": [ - { - "alias": "Flow Rate", - "path": "[CoreDB/ignition-ignition:default]watermeter/prefilterflowrate" - } - ], - "valueFormat": "DATASET" + "expression": "runScript('flowrate.queryHistory', 30000, {view.custom.timeHours})" }, - "type": "tag-history" + "type": "expr" } } }, diff --git a/projects/watermeter/ignition/script-python/flowrate/code.py b/projects/watermeter/ignition/script-python/flowrate/code.py new file mode 100644 index 0000000..54d16cf --- /dev/null +++ b/projects/watermeter/ignition/script-python/flowrate/code.py @@ -0,0 +1,14 @@ +def queryHistory(timeHours): + from java.util import Date + + end = Date() + start = Date(end.getTime() - long(timeHours * 3600000)) + + return system.tag.queryTagHistory( + paths=["[CoreDB/ignition-ignition:default]watermeter/prefilterflowrate"], + startDate=start, + endDate=end, + returnSize=120, + aggregationMode="Average", + returnFormat="Wide" + ) diff --git a/projects/watermeter/ignition/script-python/flowrate/resource.json b/projects/watermeter/ignition/script-python/flowrate/resource.json new file mode 100644 index 0000000..1db8a11 --- /dev/null +++ b/projects/watermeter/ignition/script-python/flowrate/resource.json @@ -0,0 +1,16 @@ +{ + "scope": "A", + "version": 1, + "restricted": false, + "overridable": true, + "files": [ + "code.py" + ], + "attributes": { + "lastModification": { + "actor": "dohertj2", + "timestamp": "2026-02-22T00:00:00Z" + }, + "hintScope": 2 + } +}