arneman / node-red-contrib-dashboard-bar-chart-data

2 stars 2 forks source link

Persistent data with Bar-Chart node #13

Open Soiski71 opened 1 year ago

Soiski71 commented 1 year ago

Hi, I'm sorry but I need to come Back on the Bar-Chart Node and how it handles the persistent data. With this simple data flow I'm trying to reset the last combined data from bar-chart (when node red service is restarted). If I connect the persistent data to the final chart flow it shows it in the start correctly (restore works from flow TEST2), but immediately once new data is inserted to bar-chart flow it overrides all restored data with new data (chart data starts from "zero").

If I tried liking the persistent data to bar-chart-data it does not handle it correctly

Can you send a sample code how you have solved that bar-chart-data fully survives a node-red system restart.

Help much appreciated !

[{"id":"e63eadb6b8d64e2b","type":"bar-chart-data","z":"3d738ea.22f7872","name":"bar-chart-data","x_interval":"minutes","x_size":"30","unit":"","precision":2,"is_meter_reading":"False","agg_by":"sum","x":475.4999580383301,"y":171.25000953674316,"wires":[["929f8ee9b8921c30"]]},{"id":"929f8ee9b8921c30","type":"ui_chart","z":"3d738ea.22f7872","name":"","group":"20ad50091d22a9aa","order":15,"width":0,"height":0,"label":"TEST chart","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":704.2500267028809,"y":171.2499942779541,"wires":[["b19823f62ac9abb4"]]},{"id":"9e80f37af0d3c009","type":"random","z":"3d738ea.22f7872","name":"","low":1,"high":10,"inte":"true","property":"payload","x":240.5000114440918,"y":237.49999523162842,"wires":[["e63eadb6b8d64e2b"]]},{"id":"2b354017907bfeb6","type":"inject","z":"3d738ea.22f7872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"20","topic":"","payload":"","payloadType":"date","x":132.49999618530273,"y":161.2500114440918,"wires":[["9e80f37af0d3c009"]]},{"id":"fcd6bb31e1d76879","type":"inject","z":"3d738ea.22f7872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"clear","payloadType":"str","x":267.74999618530273,"y":312.74999618530273,"wires":[["e63eadb6b8d64e2b"]]},{"id":"7b3e207ac0da8f2b","type":"inject","z":"3d738ea.22f7872","name":"Clear","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":539.0000190734863,"y":314.00001335144043,"wires":[["929f8ee9b8921c30"]]},{"id":"b19823f62ac9abb4","type":"change","z":"3d738ea.22f7872","name":"","rules":[{"t":"set","p":"#:(file)::TEST2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":911.7500305175781,"y":172.74999237060547,"wires":[["a5b6285c5462cba9"]]},{"id":"aa4cc4fb3f634d04","type":"inject","z":"3d738ea.22f7872","name":"Restore","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"#:(file)::TEST2","payloadType":"flow","x":752.5000267028809,"y":308.7501049041748,"wires":[["2b84ca6179424b8f","929f8ee9b8921c30"]]},{"id":"2b84ca6179424b8f","type":"debug","z":"3d738ea.22f7872","name":"debug 68","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":964.9999122619629,"y":294.5000114440918,"wires":[]},{"id":"a5b6285c5462cba9","type":"debug","z":"3d738ea.22f7872","name":"debug 69","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1073.7501602172852,"y":122.00000762939453,"wires":[]},{"id":"20ad50091d22a9aa","type":"ui_group","name":"Default","tab":"15ab88b14795fa9a","order":1,"disp":true,"width":22,"collapse":false,"className":""},{"id":"15ab88b14795fa9a","type":"ui_tab","name":"X-TEST","icon":"dashboard","disabled":false,"hidden":false}]

arneman commented 1 year ago

I gave you an example in https://github.com/arneman/node-red-contrib-dashboard-bar-chart-data/issues/8

In your example you only store the payload of the message and you inject the stored data after the bar-chart-data node, but it has to be injected before (and then bar-chart-data sends a new message to the chart).

another example without persist node: [ { "id": "35cacbff598f14a1", "type": "bar-chart-data", "z": "faf7d35d62e6719c", "name": "bar-chart-data", "x_interval": "seconds", "x_size": "60", "unit": "", "precision": 2, "is_meter_reading": "False", "agg_by": "sum", "x": 560, "y": 560, "wires": [ [ "f40133052733dd08", "6ab8252d49d27fdb" ] ] }, { "id": "a43fc9b07b7fd6de", "type": "inject", "z": "faf7d35d62e6719c", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": "20", "topic": "test", "payload": "1", "payloadType": "num", "x": 310, "y": 560, "wires": [ [ "35cacbff598f14a1" ] ] }, { "id": "6ab8252d49d27fdb", "type": "function", "z": "faf7d35d62e6719c", "name": "store", "func": "flow.set('bar-chart-data-store', msg);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 750, "y": 620, "wires": [ [] ] }, { "id": "89b6d0fa150e7fec", "type": "function", "z": "faf7d35d62e6719c", "name": "restore", "func": "msg = flow.get('bar-chart-data-store' || {});\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 440, "y": 480, "wires": [ [ "35cacbff598f14a1" ] ] }, { "id": "655a4109fe0262a4", "type": "inject", "z": "faf7d35d62e6719c", "name": "after restart", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 230, "y": 480, "wires": [ [ "89b6d0fa150e7fec" ] ] }, { "id": "f40133052733dd08", "type": "ui_chart", "z": "faf7d35d62e6719c", "name": "", "group": "20ad50091d22a9aa", "order": 9, "width": 0, "height": 0, "label": "chart", "chartType": "bar", "legend": "false", "xformat": "HH:mm:ss", "interpolate": "linear", "nodata": "", "dot": false, "ymin": "", "ymax": "", "removeOlder": 1, "removeOlderPoints": "", "removeOlderUnit": "3600", "cutout": 0, "useOneColor": false, "useUTC": false, "colors": [ "#1f77b4", "#aec7e8", "#ff7f0e", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5" ], "outputs": 1, "useDifferentColor": false, "className": "", "x": 810, "y": 540, "wires": [ [] ] }, { "id": "20ad50091d22a9aa", "type": "ui_group", "name": "Default", "tab": "15ab88b14795fa9a", "order": 1, "disp": true, "width": 22, "collapse": false, "className": "" }, { "id": "15ab88b14795fa9a", "type": "ui_tab", "name": "X-TEST", "icon": "dashboard", "disabled": false, "hidden": false } ]