Hello, I am new to Node-RED and would appreciate any help I can get with this. I made a flow which allows you to upload a file, type in the files name and it will then read that file and use the headers for two drop downs, You can choose two headers and +,-,* and / and it will do that.
My current issues are:
I need it to pass the file name down when a file uploaded rather than have the user type in the file.
Currently it is set so that after 5 messages go through the flow it will carry on, the issue with that is if someone does it in the wrong order or changes something, it will crash. Is it possible to resolve this?
Finally is it possible to do something like this with JSON or Kafka?
I have spent a couple of hours looking, I might just be looking in the wrong places, but I haven't found anything that resolves these issues. Any links or advice would be greatly apricated, thank you.
Flow:
[{"id":"708ff173.7f789","type":"csv","z":"5e2fd65b.332578","name":"","sep":",","hdrin":false,"hdrout":"all","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":850,"y":40,"wires":[["69e6a7bc.4054a8"]]},{"id":"53158969.3182a8","type":"file in","z":"5e2fd65b.332578","name":"","filename":"TestingFileInput","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":660,"y":40,"wires":[["708ff173.7f789"]]},{"id":"99ee054.ff743f8","type":"python-function","z":"5e2fd65b.332578","name":"","func":"call = \"\";\n\ni = 1;\nmsg[\"options\"] = [];\nmsg[\"options\"].append(msg[\"payload\"][0][\"col\" + str(i)]);\ni += 1;\nwhile i <= len(msg[\"payload\"][0]):\n msg[\"options\"].append(msg[\"payload\"][0][\"col\" + str(i)]);\n i+= 1;\n\nreturn [msg, msg, msg, msg] ","outputs":4,"x":580,"y":180,"wires":[["cf7a832c.14142"],["719990d.627dc7"],["6744ce88.fc713"],["c78575c4.6a2e48"]]},{"id":"cf7a832c.14142","type":"ui_dropdown","z":"5e2fd65b.332578","name":"","label":"","tooltip":"","place":"Select column","group":"d984ee28.de125","order":3,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"","x":940,"y":80,"wires":[["17338d8e.9aaae2"]]},{"id":"4e579112.18cac","type":"ui_dropdown","z":"5e2fd65b.332578","name":"","label":"","tooltip":"","place":"Select option","group":"d984ee28.de125","order":4,"width":0,"height":0,"passthru":false,"multiple":false,"options":[{"label":"+","value":"+","type":"str"},{"label":"/","value":"/","type":"str"},{"label":"*","value":"*","type":"str"},{"label":"-","value":"-","type":"str"}],"payload":"","topic":"msg.d4","x":1000,"y":180,"wires":[["17338d8e.9aaae2"]]},{"id":"719990d.627dc7","type":"ui_dropdown","z":"5e2fd65b.332578","name":"","label":"","tooltip":"","place":"Select column","group":"d984ee28.de125","order":5,"width":0,"height":0,"passthru":false,"multiple":false,"options":[],"payload":"","topic":"","x":940,"y":120,"wires":[["17338d8e.9aaae2"]]},{"id":"17338d8e.9aaae2","type":"join","z":"5e2fd65b.332578","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1350,"y":140,"wires":[["a3006da8.bc73c"]]},{"id":"a3006da8.bc73c","type":"python-function","z":"5e2fd65b.332578","name":"","func":"i = 1 \nmsg[\"second\"] = []\nthird = \"\"\nfirstarray= []\nthirdarray = []\ntes = []\nfirst = \"\"\nstri = \"\"\n\n\nwhile i <= len(msg[\"payload\"][0][0]):\n stri = \"col\" + str(i)\n#itterating to see what col was chosen by the first choice\n if msg[\"payload\"][1] == msg[\"payload\"][0][0][stri]:\n first = stri\n \n if msg[\"payload\"][3] == msg[\"payload\"][0][0][stri]:\n third = stri\n i += 1\n\ni = 1\n\nwhile i + 1 < len(msg[\"payload\"][0]):\n firstarray.append(msg[\"payload\"][0][i][first])\n i += 1\n\ni = 1\nwhile i + 1 < len(msg[\"payload\"][0]):\n thirdarray.append(msg[\"payload\"][0][i][third])\n i += 1\n\ni = 1\n\nwhile i + 1 < len(firstarray):\n if msg[\"payload\"][2] == \"+\":\n tes.append(int(firstarray[i]) + int(thirdarray[i]))\n if msg[\"payload\"][2] == \"*\":\n tes.append(int(firstarray[i]) * int(thirdarray[i]))\n if msg[\"payload\"][2] == \"/\":\n tes.append(int(firstarray[i]) / int(thirdarray[i]))\n if msg[\"payload\"][2] == \"-\":\n tes.append(int(firstarray[i]) - int(thirdarray[i]))\n i += 1\ntext = msg[\"payload\"][4]\nmsg[\"payload\"][0] = text\nmsg[\"payload\"][1] = tes\nreturn msg","outputs":1,"x":1520,"y":220,"wires":[["c8aa0120.ae3f2"]]},{"id":"69e6a7bc.4054a8","type":"change","z":"5e2fd65b.332578","name":"","rules":[{"t":"set","p":"all","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":120,"wires":[["99ee054.ff743f8"]]},{"id":"641a6e69.d5335","type":"ui_text_input","z":"5e2fd65b.332578","name":"","label":"name of new column","tooltip":"","group":"d984ee28.de125","order":6,"width":0,"height":0,"passthru":false,"mode":"text","delay":"0","topic":"","x":960,"y":240,"wires":[["17338d8e.9aaae2"]]},{"id":"6744ce88.fc713","type":"change","z":"5e2fd65b.332578","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"[\"+\", \"-\", \"/\" ,\"*\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":180,"wires":[["4e579112.18cac"]]},{"id":"b6439579.e0efe8","type":"ui_text_input","z":"5e2fd65b.332578","name":"","label":"File name","tooltip":"","group":"d984ee28.de125","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","x":280,"y":20,"wires":[["f73070e.2f7739"]]},{"id":"f73070e.2f7739","type":"change","z":"5e2fd65b.332578","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":40,"wires":[["53158969.3182a8"]]},{"id":"c78575c4.6a2e48","type":"change","z":"5e2fd65b.332578","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":220,"wires":[["641a6e69.d5335"]]},{"id":"dbb49191.58209","type":"ui_upload","z":"5e2fd65b.332578","group":"d984ee28.de125","title":"upload","name":"","order":5,"width":0,"height":5,"chunk":256,"transfer":"text","x":70,"y":20,"wires":[["b6439579.e0efe8"]]},{"id":"c8aa0120.ae3f2","type":"debug","z":"5e2fd65b.332578","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1710,"y":220,"wires":[]},{"id":"d984ee28.de125","type":"ui_group","name":"Two","tab":"1e101955.bd39b7","order":2,"disp":true,"width":"6","collapse":false},{"id":"1e101955.bd39b7","type":"ui_tab","name":"LastDemo","icon":"dashboard","disabled":false,"hidden":false}]