How to load CSV file then show on Dashboard
Posted: Thu Jan 12, 2023 9:02 am
CSV file format example:
2022/10/21 13:37,11,A,059,060,060,061,060,061,061,061,060,061,061,061,061,171,174,674
use datetime for grouping extract the 13 values for x value
y value base 4 for each data item
CSV sample:
Please use example to generate a CSV file and save to place like C:\AIC\IoTStudio\test.csv for flow test.
The below is IoT Studio flow can read CSV and process then show to Dashboard.
2022/10/21 13:37,11,A,059,060,060,061,060,061,061,061,060,061,061,061,061,171,174,674
use datetime for grouping extract the 13 values for x value
y value base 4 for each data item
CSV sample:
Code: Select all
2022/10/21 13:37,11,A,059,060,060,061,060,061,061,061,060,061,061,061,061,171,174,674
2022/10/21 13:37,11,B,061,027,005,004,004,004,004,005,004,005,004,005,004,174,179,674
2022/10/21 13:37,11,C,004,005,004,005,004,005,004,005,004,005,004,005,004,181,181,672
2022/10/21 13:37,11,D,005,004,005,004,004,004,004,004,004,004,004,004,004,175,178,673
2022/10/21 13:37,16,E,005,004,005,004,005,004,004,004,004,004,004,005,004,175,180,670
2022/10/21 13:37,16,F,005,004,005,004,005,004,005,004,005,004,005,004,005,184,185,669
2022/10/21 13:37,21,A,059,060,060,061,060,061,061,061,060,061,061,061,061,171,174,674
2022/10/21 13:37,21,B,061,027,005,004,004,004,004,005,004,005,004,005,004,174,179,674
2022/10/21 13:37,21,C,004,005,004,005,004,005,004,005,004,005,004,005,004,181,181,672
2022/10/21 13:37,21,D,005,004,005,004,004,004,004,004,004,004,004,004,004,175,177,673
2022/10/21 13:37,21,E,005,004,005,004,005,004,004,004,004,004,004,005,004,175,180,670
2022/10/21 13:37,21,F,004,004,005,004,005,004,005,004,005,004,005,004,005,184,184,669
2022/10/21 13:37,31,A,059,060,060,061,060,061,061,061,060,061,061,061,061,171,174,674
2022/10/21 13:37,31,B,061,027,005,004,004,004,004,005,004,005,004,005,004,174,179,674
2022/10/21 13:37,31,C,004,004,004,005,004,005,004,005,004,005,004,005,004,181,181,672
2022/10/21 13:37,31,D,005,004,005,004,004,004,004,004,004,004,004,004,004,175,177,673
2022/10/21 13:37,31,E,005,004,005,004,005,004,004,004,004,004,004,005,004,175,180,670
2022/10/21 13:37,31,F,005,004,005,004,005,004,005,004,005,004,005,004,005,184,184,669
The below is IoT Studio flow can read CSV and process then show to Dashboard.
Code: Select all
[{"id":"ede36954d1d14044","type":"file in","z":"043513c841d9502d","name":"","filename":"C:\\\\AIC\\\\IoTStudio\\\\test.csv","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":370,"y":100,"wires":[["533d6ed0c1478fd4"]]},{"id":"533d6ed0c1478fd4","type":"csv","z":"043513c841d9502d","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":590,"y":100,"wires":[["28b24029b6c70cac"]]},{"id":"44cb1c7ecfb540ab","type":"inject","z":"043513c841d9502d","name":"load CSV","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":100,"wires":[["ede36954d1d14044"]]},{"id":"52f3f3278399e323","type":"ui_chart","z":"043513c841d9502d","name":"","group":"9afd0cfbde869675","order":1,"width":6,"height":"12","label":"","chartType":"line","legend":"true","xformat":"x","interpolate":"linear","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"200","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":530,"y":240,"wires":[["74810882c0b39f2c"]]},{"id":"28b24029b6c70cac","type":"function","z":"043513c841d9502d","name":"Group by DayTime","func":"let arr = msg.payload;\nlet obj = {};\nfor(let i=0; i<arr.length; i++) {\n let row = arr[i];\n if (!obj.hasOwnProperty(row.col1)) {\n obj[row.col1] = []; \n }\n obj[row.col1].push(row);\n}\nmsg.payload = obj;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":140,"wires":[["9ea36eee1164f55a"]]},{"id":"6fbdd2091f0cdb68","type":"function","z":"043513c841d9502d","name":"Extract A B C D E F values","func":"let source = global.get(\"source\");\nlet keys = global.get(\"keys\");\nlet idx = global.get(\"idx\");\nlet obj = [];\nnode.warn(idx);\nmsg.daytime = keys[idx];\nnode.warn(msg.daytime);\nfor(let i=0; i<6; i++) {\n obj.push(source[msg.daytime][i]);\n}\nmsg.payload = obj;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":180,"wires":[["bd35b58108298dae"]]},{"id":"bd35b58108298dae","type":"function","z":"043513c841d9502d","name":"Gen ponters for dashboard","func":"let arr = msg.payload;\nlet y = 4;\nlet data = [];\nfor(let i=0; i<arr.length; i++) {\n let row = arr[i];\n for(let col=4; col<17; col++) {\n let x = parseInt(row[\"col\"+col]);\n let ponter = {\"x\": x, \"y\": y};\n data.push(ponter);\n y = y + 4; \n }\n}\n\nmsg.payload = [{\n \"series\": [msg.daytime],\n \"data\": [data],\n \"labels\": [msg.daytime]\n}];\nmsg.topic = msg.daytime;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":240,"wires":[["52f3f3278399e323"]]},{"id":"9ea36eee1164f55a","type":"function","z":"043513c841d9502d","name":"Set Global Values","func":"global.set(\"source\", msg.payload);\nglobal.set(\"keys\", Object.keys(msg.payload));\nnode.warn(global.get(\"keys\"));\nglobal.set(\"idx\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":140,"wires":[["6fbdd2091f0cdb68"]]},{"id":"74810882c0b39f2c","type":"delay","z":"043513c841d9502d","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":660,"y":240,"wires":[["5fb260cd4a2d5462"]]},{"id":"5fb260cd4a2d5462","type":"function","z":"043513c841d9502d","name":"Next Data","func":"let idx = global.get(\"idx\");\nlet keys = global.get(\"keys\");\nidx = idx + 1;\nif (idx < keys.length) {\n global.set(\"idx\", idx);\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":240,"wires":[["6fbdd2091f0cdb68"]]},{"id":"9afd0cfbde869675","type":"ui_group","name":"TEST","tab":"b63d1f91.68095","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"b63d1f91.68095","type":"ui_tab","name":"AIC","icon":"dashboard","disabled":false,"hidden":false}]