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 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"custom": {
|
"custom": {
|
||||||
"timeAmount": 1,
|
"timeHours": 1
|
||||||
"timeUnits": "HOUR"
|
|
||||||
},
|
},
|
||||||
"params": {},
|
"params": {},
|
||||||
"props": {
|
"props": {
|
||||||
@@ -19,7 +18,7 @@
|
|||||||
"dom": {
|
"dom": {
|
||||||
"onClick": {
|
"onClick": {
|
||||||
"config": {
|
"config": {
|
||||||
"script": "\tself.view.custom.timeAmount = 1\n\tself.view.custom.timeUnits = \"HOUR\""
|
"script": "\tself.view.custom.timeHours = 1"
|
||||||
},
|
},
|
||||||
"scope": "G",
|
"scope": "G",
|
||||||
"type": "script"
|
"type": "script"
|
||||||
@@ -37,7 +36,7 @@
|
|||||||
"props.style.backgroundColor": {
|
"props.style.backgroundColor": {
|
||||||
"binding": {
|
"binding": {
|
||||||
"config": {
|
"config": {
|
||||||
"expression": "if({view.custom.timeAmount} = 1 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
|
"expression": "if({view.custom.timeHours} = 1, '#4747FF', '#AAAAAA')"
|
||||||
},
|
},
|
||||||
"type": "expr"
|
"type": "expr"
|
||||||
}
|
}
|
||||||
@@ -58,7 +57,7 @@
|
|||||||
"dom": {
|
"dom": {
|
||||||
"onClick": {
|
"onClick": {
|
||||||
"config": {
|
"config": {
|
||||||
"script": "\tself.view.custom.timeAmount = 6\n\tself.view.custom.timeUnits = \"HOUR\""
|
"script": "\tself.view.custom.timeHours = 6"
|
||||||
},
|
},
|
||||||
"scope": "G",
|
"scope": "G",
|
||||||
"type": "script"
|
"type": "script"
|
||||||
@@ -76,7 +75,7 @@
|
|||||||
"props.style.backgroundColor": {
|
"props.style.backgroundColor": {
|
||||||
"binding": {
|
"binding": {
|
||||||
"config": {
|
"config": {
|
||||||
"expression": "if({view.custom.timeAmount} = 6 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
|
"expression": "if({view.custom.timeHours} = 6, '#4747FF', '#AAAAAA')"
|
||||||
},
|
},
|
||||||
"type": "expr"
|
"type": "expr"
|
||||||
}
|
}
|
||||||
@@ -97,7 +96,7 @@
|
|||||||
"dom": {
|
"dom": {
|
||||||
"onClick": {
|
"onClick": {
|
||||||
"config": {
|
"config": {
|
||||||
"script": "\tself.view.custom.timeAmount = 24\n\tself.view.custom.timeUnits = \"HOUR\""
|
"script": "\tself.view.custom.timeHours = 24"
|
||||||
},
|
},
|
||||||
"scope": "G",
|
"scope": "G",
|
||||||
"type": "script"
|
"type": "script"
|
||||||
@@ -115,7 +114,7 @@
|
|||||||
"props.style.backgroundColor": {
|
"props.style.backgroundColor": {
|
||||||
"binding": {
|
"binding": {
|
||||||
"config": {
|
"config": {
|
||||||
"expression": "if({view.custom.timeAmount} = 24 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
|
"expression": "if({view.custom.timeHours} = 24, '#4747FF', '#AAAAAA')"
|
||||||
},
|
},
|
||||||
"type": "expr"
|
"type": "expr"
|
||||||
}
|
}
|
||||||
@@ -130,45 +129,6 @@
|
|||||||
"text": "24H"
|
"text": "24H"
|
||||||
},
|
},
|
||||||
"type": "ia.input.button"
|
"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": {
|
"meta": {
|
||||||
@@ -202,34 +162,9 @@
|
|||||||
"props.series[0].data": {
|
"props.series[0].data": {
|
||||||
"binding": {
|
"binding": {
|
||||||
"config": {
|
"config": {
|
||||||
"aggregate": "Average",
|
"expression": "runScript('flowrate.queryHistory', 30000, {view.custom.timeHours})"
|
||||||
"avoidScanClassValidation": true,
|
|
||||||
"dateRange": {
|
|
||||||
"mostRecent": "{view.custom.timeAmount}",
|
|
||||||
"mostRecentUnits": "{view.custom.timeUnits}"
|
|
||||||
},
|
},
|
||||||
"enableValueCache": true,
|
"type": "expr"
|
||||||
"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"
|
|
||||||
},
|
|
||||||
"type": "tag-history"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
14
projects/watermeter/ignition/script-python/flowrate/code.py
Normal file
14
projects/watermeter/ignition/script-python/flowrate/code.py
Normal file
@@ -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"
|
||||||
|
)
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user