Graph from file

This flow creates a graph from a TXT file. When logging data to CSV file in array the flow wil generate separate msg.payload for each index.

Then it will draw them to two graphs.

In this example we have the following data per index: XXXX,Y,AAAAAA,BBBBBB

A = Value B = Average over last 30 values

in this example we will also plot a seperate graph 'a/b*100%' which show the deviation from the average.

A and Y are disregarded in the function block by a split string operation.

[{"id":"4fa73dd9.83cca4","type":"comment","z":"5643fa59.7d6c64","name":"File Browser","info":"1) Update the default folder in the Init node\n2) Update the default folder in the Reset node as well\n3) You can duplicate the Reset nodes and use them as saved shortcuts\n4) Check the Convert Timestamps function node if you want to see your dates in a different format. I just used the Javascript toISOString format.\n5) The Graph button can read any CSV file which have any number of values, but the first column always contains a timestamp column with javascript timestamp of the data point.","x":150,"y":80,"wires":[]},{"id":"d185a45.2327a58","type":"inject","z":"5643fa59.7d6c64","name":"Init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"change","payload":"C:\\Users\\pike\\logs","payloadType":"str","x":150,"y":140,"wires":[["3d4e5e51.bdf952"]]},{"id":"eb17c7ee.e61988","type":"ui_dropdown","z":"5643fa59.7d6c64","name":"File Selector","label":"","tooltip":"","place":"Select a file","group":"a25e3f35.7e46c","order":2,"width":"5","height":"1","passthru":false,"multiple":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":950,"y":180,"wires":[["be4830df.5775d","802ce3c5.9338a"]]},{"id":"dd88bd23.37cde","type":"function","z":"5643fa59.7d6c64","name":"Format data","func":"// format the data for the dropdown\nmsg.options = [];\nfor (var i=0; i<msg.payload.length; i++) {\n    // This is a file\n    obj = {};\n    obj [msg.payload[i].name.replace(/^.*(\\\\|\\/|\\:)/, '')]=msg.payload[i].name;\n    msg.options.push(obj);\n}\nmsg.payload={};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":180,"wires":[["eb17c7ee.e61988"]]},{"id":"d19cc7d8.646328","type":"http response","z":"5643fa59.7d6c64","name":"","statusCode":"","headers":{},"x":990,"y":460,"wires":[]},{"id":"99ff4953.d0d5c8","type":"change","z":"5643fa59.7d6c64","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"text/csv","tot":"str"},{"t":"set","p":"headers.Content-Disposition","pt":"msg","to":"contentdisposition","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":460,"wires":[["d19cc7d8.646328"]]},{"id":"2519dd0d.54d6b2","type":"ui_button","z":"5643fa59.7d6c64","name":"","group":"a25e3f35.7e46c","order":3,"width":"2","height":"1","passthru":false,"label":"Graph","tooltip":"","color":"","bgcolor":"","icon":"show_chart","payload":"1","payloadType":"str","topic":"","x":150,"y":600,"wires":[["30f41c01.358a54"]]},{"id":"30f41c01.358a54","type":"function","z":"5643fa59.7d6c64","name":"Get filename","func":"// Get the filename from the flow context\nlet filename = flow.get(\"fileselected\");\nlet text = filename.toString();\nmsg.filename = text;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":600,"wires":[["4f4072b6.0c320c"]]},{"id":"4f4072b6.0c320c","type":"file in","z":"5643fa59.7d6c64","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":500,"y":600,"wires":[["4d254665.d508e8","d8ff4091.1c9bc"]]},{"id":"4d254665.d508e8","type":"csv","z":"5643fa59.7d6c64","name":"","sep":",","hdrin":true,"hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"x":650,"y":660,"wires":[[]]},{"id":"3d4e5e51.bdf952","type":"function","z":"5643fa59.7d6c64","name":"Folder handling","func":"let folder = context.get(\"folder\");\nif (folder===undefined) {\n    folder=\"/\";\n    context.set(\"folder\", folder);\n}\n\nlet hidden = context.get(\"hidden\");\nif (hidden===undefined) {\n    hidden=false;\n    context.set(\"hidden\", hidden);\n}\n\nif (msg.topic===\"up\") {\n    var the_arr = folder.split('/');\n    the_arr.pop();\n    folder=the_arr.join('/'); \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"change\") {\n    folder=msg.payload;    \n    context.set(\"folder\", folder);\n}\nif (msg.topic===\"hidden\") {\n    hidden=msg.payload;    \n    context.set(\"hidden\", hidden);\n}\n\nmsg.payload = {\"start\":folder, \"hidden\": hidden};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":100,"wires":[["993d7272.843ae","399ac341.7d43bc"]]},{"id":"399ac341.7d43bc","type":"ui_text","z":"5643fa59.7d6c64","group":"a25e3f35.7e46c","order":1,"width":"9","height":"1","name":"","label":"Folder:","format":"{{msg.payload.start}}","layout":"row-left","x":560,"y":100,"wires":[]},{"id":"be4830df.5775d","type":"change","z":"5643fa59.7d6c64","name":"Save selection","rules":[{"t":"set","p":"fileselected","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":180,"wires":[[]]},{"id":"993d7272.843ae","type":"fs-file-lister","z":"5643fa59.7d6c64","name":"Files","start":"/home/pi","pattern":"*.*","folders":"*","hidden":false,"lstype":"files","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":570,"y":180,"wires":[["dd88bd23.37cde"]]},{"id":"802ce3c5.9338a","type":"debug","z":"5643fa59.7d6c64","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":140,"wires":[]},{"id":"d8ff4091.1c9bc","type":"split","z":"5643fa59.7d6c64","name":"","splt":"\",\"","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":740,"y":580,"wires":[["3fd1a2f8.550b9e","8713ccc2.a4e03"]]},{"id":"3fd1a2f8.550b9e","type":"debug","z":"5643fa59.7d6c64","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":500,"wires":[]},{"id":"8713ccc2.a4e03","type":"function","z":"5643fa59.7d6c64","name":"","func":"var value = parseInt(msg.payload.substr(10,6),16);\nvar avg = parseInt(msg.payload.substr(17,6),16);\nvar proc = (100-((avg/value)*100)).toFixed(2);\n\n\nvar VAL = {};\nvar AVG = {};\nvar PRO = {};\n\nVAL.payload = value;\nAVG.payload = avg;\nPRO.payload = proc;\nVAL.topic = \"value\";\nAVG.topic = \"average\";\nPRO.topic = \"procent\"\n\n\n\n\nreturn [VAL, AVG, PRO];","outputs":3,"noerr":0,"initialize":"","finalize":"","x":940,"y":580,"wires":[["a3c94f6d.97277"],["a3c94f6d.97277"],["795a77db.a7c0d8","48d4d33b.fafebc"]]},{"id":"a3c94f6d.97277","type":"ui_chart","z":"5643fa59.7d6c64","name":"data/average","group":"a25e3f35.7e46c","order":5,"width":0,"height":0,"label":"chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"data/average","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"120","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#7aa4c2","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1250,"y":560,"wires":[[]]},{"id":"795a77db.a7c0d8","type":"ui_chart","z":"5643fa59.7d6c64","name":"data/average","group":"a25e3f35.7e46c","order":6,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"data/average","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"60","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#7aa4c2","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1250,"y":600,"wires":[[]]},{"id":"4d758af9.4aa414","type":"ui_button","z":"5643fa59.7d6c64","name":"","group":"a25e3f35.7e46c","order":4,"width":0,"height":0,"passthru":false,"label":"Clear Graph","tooltip":"","color":"","bgcolor":"","icon":"fa-bomb","payload":"[]","payloadType":"json","topic":"","x":920,"y":720,"wires":[["a3c94f6d.97277","795a77db.a7c0d8"]]},{"id":"48d4d33b.fafebc","type":"debug","z":"5643fa59.7d6c64","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1250,"y":680,"wires":[]},{"id":"a25e3f35.7e46c","type":"ui_group","name":"Group 2","tab":"b63d1f91.68095","order":1,"disp":true,"width":"16","collapse":false},{"id":"b63d1f91.68095","type":"ui_tab","name":"Files","icon":"dashboard","disabled":false,"hidden":false}]

Flow Info

Created 3 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • comment (x1)
  • csv (x1)
  • debug (x3)
  • file in (x1)
  • function (x4)
  • http response (x1)
  • inject (x1)
  • split (x1)
Other
  • fs-file-lister (x1)
  • ui_button (x2)
  • ui_chart (x2)
  • ui_dropdown (x1)
  • ui_group (x1)
  • ui_tab (x1)
  • ui_text (x1)

Tags

  • logging
  • average
  • graph
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option