画面截图
导出的代码
[{"id": "648f70b0.d1af8","type": "tab","label": "influxdb更新","disabled": false,"info": ""},{"id": "e65c2e04.5407c","type": "influxdb in","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "","query": "","rawOutput": false,"precision": "","retentionPolicy": "","org": "organisation","x": 520,"y": 820,"wires": [["dc9ff540.bbf6b8"]]},{"id": "ba743a19.4ac0e8","type": "file","z": "648f70b0.d1af8","name": "文件path","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1360,"y": 820,"wires": [["b72bb10e.26629"]]},{"id": "dc9ff540.bbf6b8","type": "function","z": "648f70b0.d1af8","name": "数据转换(csv格式)","func": "//node.warn(msg.payload);\nlet result = [];\nfor (let i = 0; i < msg.payload.length; i++) {\n let row = [];\n row[0] = msg.payload[i].data2; //温度信息\n result[i] = row;\n}\n\nmsg.robotId = msg.payload[0].robot_id; //用于文件名前缀\nmsg.payload = result;\n\nreturn msg;\n","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 750,"y": 820,"wires": [["e4201bfc.4c9378"]]},{"id": "e4201bfc.4c9378","type": "csv","z": "648f70b0.d1af8","name": "csv属性设置","sep": ",","hdrin": false,"hdrout": "once","multi": "one","ret": "\\r\\n","temp": "value","skip": "1","strings": false,"include_empty_strings": false,"include_null_values": false,"x": 970,"y": 820,"wires": [["e6d65f32.606ee","a38ed121.def7f"]]},{"id": "e6d65f32.606ee","type": "debug","z": "648f70b0.d1af8","name": "","active": false,"tosidebar": true,"console": false,"tostatus": false,"complete": "false","statusVal": "","statusType": "auto","x": 1170,"y": 760,"wires": []},{"id": "2fb1f8f.b3ddd08","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "put","remoteFilePath": "remotePath","remoteFilePathType": "msg","localFilePath": "filename","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "SFTP设置","x": 370,"y": 980,"wires": [["ecf9e410.459b38"]]},{"id": "fe7e246c.93dca8","type": "function","z": "648f70b0.d1af8","name": "取得前一天的文件","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet date = new Date();\nlet dateStr = date.getFullYear().toString();\ndateStr += prefixZero((date.getMonth() + 1), 2);\ndateStr += prefixZero((date.getDate() - 1), 2);\n\n//test data\n//dateStr = \"20210623\";\n\nlet len = msg.payload.length;\nlet file = [];\nfor (let i = 0; i < len; i++) {\n if (msg.payload[i].indexOf(dateStr) != -1) {\n file.push(msg.payload[i]);\n }\n}\nmsg.remoteFiles = file;\nflow.set(\"date\", dateStr);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 670,"y": 1420,"wires": [["3ab6be3e.0f6082"]]},{"id": "b26d6a97.a6fe68","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天6:30执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "30 06 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 1420,"wires": [["154e2ab3.a536a5"]]},{"id": "154e2ab3.a536a5","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "list","remoteFilePath": "/home/ftpuser/BD/cs001/bd_alarm","remoteFilePathType": "str","localFilePath": "","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "文件一览(bd_alarm)","x": 420,"y": 1420,"wires": [["fe7e246c.93dca8"]]},{"id": "315d8d2d.cbdfa2","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "get","remoteFilePath": "remoteFiles","remoteFilePathType": "msg","localFilePath": "localPath","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "下载到本地","x": 1430,"y": 1460,"wires": [["f48e4d67.4eded"]]},{"id": "3ab6be3e.0f6082","type": "switch","z": "648f70b0.d1af8","name": "","property": "remoteFiles.length","propertyType": "msg","rules": [{"t": "eq","v": "0","vt": "num"},{"t": "gt","v": "0","vt": "num"}],"checkall": "true","repair": false,"outputs": 2,"x": 870,"y": 1420,"wires": [["6de0eac2.027864"],["1a760ff6.0f77"]]},{"id": "50e30eb6.bf8da","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1350,"y": 1360,"wires": []},{"id": "4bf86818.0a9228","type": "comment","z": "648f70b0.d1af8","name": "从SFTP下载解析后的文件(bd_alarm)","info": "","x": 210,"y": 1380,"wires": []},{"id": "b72bb10e.26629","type": "function","z": "648f70b0.d1af8","name": "SFTP路径","func": "msg.remotePath = \"/home/ftpuser/cs001/BDU_data\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 130,"y": 980,"wires": [["2fb1f8f.b3ddd08"]]},{"id": "5aca1c99.bfb0e4","type": "comment","z": "648f70b0.d1af8","name": "从本地上传到SFTP(原始数据)","info": "","x": 190,"y": 940,"wires": []},{"id": "98193f68.47407","type": "csv","z": "648f70b0.d1af8","name": "csv解析方式","sep": ",","hdrin": "","hdrout": "none","multi": "mult","ret": "\\n","temp": "date,takt_rms,result,index","skip": "1","strings": false,"include_empty_strings": "","include_null_values": "","x": 930,"y": 2100,"wires": [["8fcee820.959168"]]},{"id": "66f2bef4.d15d7","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天5:00执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "00 05 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 1960,"wires": [["5e80430c.992ccc"]]},{"id": "fbbbd20a.a49e1","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1370,"y": 2160,"wires": []},{"id": "6467c5f2.f9675c","type": "file in","z": "648f70b0.d1af8","name": "文件路径及名称","filename": "","format": "utf8","chunk": false,"sendError": false,"encoding": "utf8","x": 760,"y": 2180,"wires": [["98193f68.47407"]]},{"id": "8fcee820.959168","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let records = msg.payload;\nif (records == null) {\n return;\n}\n\nfunction convertTime(str){\n\tlet date1 = new Date(str);\n\treturn date1.getTime() * 1000000;\n}\n\nlet res = [];\nlet len = records.length;\nfor (let i = 0; i < len; i++) {\n let obj = [];\n // fields\n obj[0] = {\n movement_evl: 0,\n segment_evl: parseFloat(records[i].takt_rms),\n data_index: parseInt(records[i].index),\n time_gap: 0,\n mark: 0,\n time: convertTime(records[i].date)\n };\n // tags\n obj[1] = {\n plc_id: \"1\",\n robot_id: flow.get(\"robot_id\"),\n cs_id: \"cs001\",\n moto_num: flow.get(\"axis_id\"),\n act_date: flow.get(\"date\")\n };\n res[i] = obj;\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1120,"y": 2100,"wires": [["fbbbd20a.a49e1","5f940f1f.3f32"]]},{"id": "f52a56f3.391c58","type": "comment","z": "648f70b0.d1af8","name": "RMS Takt数据写入","info": "","x": 150,"y": 2060,"wires": []},{"id": "2e93c280.2cc70e","type": "function","z": "648f70b0.d1af8","name": "","func": "//msg.filename = \"C:/temp/data/rms_takt/p2_1_20210601fft.csv_tact.csv_3.csv_3sigma.csv\";\nmsg.filename = msg.payload;\n\n//解析文件名\nlet s = msg.filename.lastIndexOf(\"\\\\\");\nlet splitStr = msg.filename.substr(s + 1).split(\"_\");\nflow.set(\"robot_id\", splitStr[0]);\nflow.set(\"axis_id\", splitStr[1]);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 610,"y": 2100,"wires": [["6467c5f2.f9675c"]]},{"id": "bdf2ba06.5ab968","type": "csv","z": "648f70b0.d1af8","name": "csv解析方式","sep": ",","hdrin": "","hdrout": "none","multi": "one","ret": "\\n","temp": "","skip": "1","strings": false,"include_empty_strings": "","include_null_values": "","x": 990,"y": 2640,"wires": [["b6042bbe.11d9c8"]]},{"id": "33acdbda.963b24","type": "debug","z": "648f70b0.d1af8","name": "","active": false,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1410,"y": 2720,"wires": []},{"id": "4d476239.558e9c","type": "file in","z": "648f70b0.d1af8","name": "文件路径及名称","filename": "","format": "lines","chunk": false,"sendError": false,"encoding": "utf8","x": 780,"y": 2640,"wires": [["bdf2ba06.5ab968"]]},{"id": "635f943c.04c5dc","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let records = msg.payload;\nif (records == null) {\n return;\n}\n\nfunction convertTime(str){\n\tlet date1 = new Date(str);\n\treturn date1.getTime();\n}\n\nconst START_POS = 3;\nlet dateTime = convertTime(records['col1']);\nconst PTN_NO = records['col2'];\n\nlet res = [];\nlet len = Object.getOwnPropertyNames(records).length;\n\nfor (let i = START_POS; i <= len; i++) {\n let obj = [];\n obj[0] = {\n data: parseFloat(records['col' + i]), \n time: (dateTime + i - START_POS) * 1000000\n };\n obj[1] = {\n robot_id: flow.get(\"robot_id\"),\n cs_id: \"cs001\",\n moto_num: flow.get(\"axis_id\"),\n ptn_no: PTN_NO,\n type: \"RMS\",\n date: flow.get(\"date\")\n };\n \n res[i - START_POS] = obj;\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1200,"y": 2640,"wires": [["33acdbda.963b24","fc0987cb.1f1c18"]]},{"id": "ccb9b2f5.de6ac","type": "comment","z": "648f70b0.d1af8","name": "Takt PTN数据写入","info": "","x": 150,"y": 2600,"wires": []},{"id": "b20efe9b.de753","type": "csv","z": "648f70b0.d1af8","name": "csv解析方式","sep": ",","hdrin": "","hdrout": "none","multi": "mult","ret": "\\n","temp": "value1,value2","skip": "0","strings": false,"include_empty_strings": "","include_null_values": "","x": 990,"y": 3240,"wires": [["62c5b80f.bd9348"]]},{"id": "d3ca118f.ef8bb","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1370,"y": 3220,"wires": []},{"id": "b69fb787.2b0648","type": "file in","z": "648f70b0.d1af8","name": "文件路径及名称","filename": "","format": "utf8","chunk": false,"sendError": false,"encoding": "utf8","x": 840,"y": 3160,"wires": [["b20efe9b.de753"]]},{"id": "62c5b80f.bd9348","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let records = msg.payload;\nif (records == null) {\n return;\n}\n\nlet csvValue = records.value1;\nlet timeStamp = new Date().getTime();\n\nlet res = [];\nlet len = records.length;\nfor (let i = 0; i < len; i++) {\n let obj = [];\n // fields\n obj[0] = {\n data: parseFloat(records[i].value1),\n time: (timeStamp + i) * 1000000\n };\n // tags\n obj[1] = {\n robot_id: flow.get(\"robot_id\"),\n cs_id: \"cs001\",\n moto_num: flow.get(\"axis_id\"),\n ptn_no: flow.get(\"ptn_no\"),\n type: \"normal\",\n date: flow.get(\"date\")\n };\n res[i] = obj;\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1140,"y": 3160,"wires": [["d3ca118f.ef8bb","fb61e2c4.86601"]]},{"id": "f3b1dea0.61391","type": "comment","z": "648f70b0.d1af8","name": "PTN标准数据写入","info": "","x": 150,"y": 3120,"wires": []},{"id": "eb9e84f2.d60098","type": "delay","z": "648f70b0.d1af8","name": "","pauseType": "rate","timeout": "5","timeoutUnits": "seconds","rate": "1","nbRateUnits": "1","rateUnits": "second","randomFirst": "1","randomLast": "5","randomUnits": "seconds","drop": false,"outputs": 1,"x": 370,"y": 3160,"wires": [["b621af95.8c6d"]]},{"id": "1a760ff6.0f77","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/bd_alarm/\" + flow.get(\"date\");\nmsg.payload = \"create_time: \" + new Date();\nmsg.filename = msg.localPath + \"/data_info\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1060,"y": 1460,"wires": [["d1e14a82.113e68"]]},{"id": "d1e14a82.113e68","type": "file","z": "648f70b0.d1af8","name": "","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1250,"y": 1420,"wires": [["315d8d2d.cbdfa2"]]},{"id": "a2c7a910.4b5ab8","type": "csv","z": "648f70b0.d1af8","name": "csv解析方式","sep": ",","hdrin": true,"hdrout": "none","multi": "one","ret": "\\n","temp": "","skip": "0","strings": false,"include_empty_strings": "","include_null_values": "","x": 850,"y": 1600,"wires": [["6248b363.ecf8cc"]]},{"id": "60b8a9c4.b90b98","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1410,"y": 1660,"wires": []},{"id": "f2cf6364.15c36","type": "file in","z": "648f70b0.d1af8","name": "文件路径及名称","filename": "","format": "lines","chunk": false,"sendError": false,"encoding": "utf8","x": 700,"y": 1680,"wires": [["a2c7a910.4b5ab8"]]},{"id": "39df6d58.17fe72","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "if (msg.csvData == null || msg.payload == null) {\n return;\n}\n\nlet checkId = msg.csvData.checkID;\nlet checkTime = msg.csvData.checkTime + msg.csvData.checkMSecond;\nlet robotId = msg.csvData.checkRobotID;\nlet axisId = msg.csvData.checkAxisID;\nlet alarmPos = msg.csvData.alarmPos;\nlet alarmRan = msg.csvData.alarmRan;\nlet alarmType = msg.csvData.alarmType;\nlet alarmLevel = msg.csvData.alarmLevel;\nlet normalPtnId = msg.csvData.normalPtnTaktID;\nlet ptnId;\nif (msg.payload.length == 0) {\n ptnId = 1;\n node.warn(\"checkID=\" + checkId + \" RobotID=\" + robotId + \" AxisID=\" + axisId + \" checkTime=\" + checkTime + \"\\n\" + msg.query);\n} else {\n ptnId = msg.payload[0].data_index; //msg.csvData.ptn\n}\n\nfunction getTimeStamp(str) {\n return new Date(str).getTime() * 1000000;\n}\n\nmsg.payload = [\n {\n measurement: \"bd_alarm\",\n fields: {\n alarm_pos: alarmPos,\n alarm_ran: alarmRan,\n alarm_type: alarmType,\n alarm_level: alarmLevel,\n ptn_no: ptnId\n },\n tags:{\n robot_id: robotId,\n cs_id: \"cs001\",\n check_axis_id: axisId, //通道\n check_id: checkId,\n check_time: checkTime,\n act_date: flow.get(\"date\"),\n normal_ptn_takt_id: normalPtnId\n },\n timestamp: getTimeStamp(checkTime)\n }\n];\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1220,"y": 1600,"wires": [["60b8a9c4.b90b98","af31ccc8.941d2"]]},{"id": "af31ccc8.941d2","type": "influxdb batch","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","precision": "","retentionPolicy": "","name": "bd_alarm","database": "influxdb1","precisionV18FluxV20": "ns","retentionPolicyV18Flux": "autogen","org": "","bucket": "","x": 1400,"y": 1600,"wires": []},{"id": "887a6a3d.a08788","type": "comment","z": "648f70b0.d1af8","name": "BD_ALARM数据写入","info": "","x": 160,"y": 1560,"wires": []},{"id": "a9eec31d.a0fe1","type": "function","z": "648f70b0.d1af8","name": "","func": "//msg.filename = \"C:/temp/data/bd_alarm/p2_7_20210604rms_bda.csv\";\nmsg.filename = msg.payload;\n\n//解析文件名\n//let s = msg.filename.lastIndexOf(\"/\");\n//let splitStr = msg.filename.substr(s + 1).split(\"_\");\n//msg.robot_id = splitStr[0];\n//msg.axis_id = splitStr[1];\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 590,"y": 1600,"wires": [["f2cf6364.15c36"]]},{"id": "b046e723.f476d8","type": "delay","z": "648f70b0.d1af8","name": "","pauseType": "rate","timeout": "5","timeoutUnits": "seconds","rate": "1","nbRateUnits": "2","rateUnits": "second","randomFirst": "1","randomLast": "5","randomUnits": "seconds","drop": false,"outputs": 1,"x": 400,"y": 1600,"wires": [["a9eec31d.a0fe1"]]},{"id": "9cfd32cd.c2013","type": "fs-file-lister","z": "648f70b0.d1af8","name": "指定文件目录","start": "msg.localPath","pattern": "*.csv","folders": "*","hidden": false,"lstype": "files","path": true,"single": false,"depth": 0,"stat": false,"showWarnings": true,"x": 240,"y": 1680,"wires": [["b046e723.f476d8"]]},{"id": "f48e4d67.4eded","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = {\"start\":msg.localPath,\"pattern\":\"*.csv\",\"folders\":\"*\"};\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 110,"y": 1600,"wires": [["9cfd32cd.c2013"]]},{"id": "5e80430c.992ccc","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "list","remoteFilePath": "/home/ftpuser/cs001/Mod1/TAKT_RMS","remoteFilePathType": "str","localFilePath": "","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "文件一览(takt_rms)","x": 410,"y": 1960,"wires": [["cc9d82b9.9d905"]]},{"id": "cc9d82b9.9d905","type": "function","z": "648f70b0.d1af8","name": "取得前一天的文件","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet date = new Date();\nlet dateStr = date.getFullYear().toString();\ndateStr += prefixZero((date.getMonth() + 1), 2);\ndateStr += prefixZero((date.getDate() - 1), 2);\n\n//test data\ndateStr = \"20210613\";\n\nlet len = msg.payload.length;\nlet file = [];\nfor (let i = 0; i < len; i++) {\n if (msg.payload[i].indexOf(dateStr) != -1) {\n file.push(msg.payload[i]);\n }\n}\nmsg.remoteFiles = file;\nflow.set(\"date\", dateStr);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 670,"y": 1960,"wires": [["f6f28f4a.607bd"]]},{"id": "f6f28f4a.607bd","type": "switch","z": "648f70b0.d1af8","name": "","property": "remoteFiles.length","propertyType": "msg","rules": [{"t": "eq","v": "0","vt": "num"},{"t": "gt","v": "0","vt": "num"}],"checkall": "true","repair": false,"outputs": 2,"x": 870,"y": 1960,"wires": [["9eba8011.89748"],["e95d0985.2f9048"]]},{"id": "a475ddd2.a2187","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1410,"y": 1900,"wires": []},{"id": "e95d0985.2f9048","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/rms_takt/\" + flow.get(\"date\");\nmsg.payload = \"create_time: \" + new Date();\nmsg.filename = msg.localPath + \"/data_info\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1040,"y": 2000,"wires": [["a5d1d7a0.ab0628"]]},{"id": "a5d1d7a0.ab0628","type": "file","z": "648f70b0.d1af8","name": "","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1230,"y": 1940,"wires": [["cbd684bc.9742d8"]]},{"id": "cbd684bc.9742d8","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "get","remoteFilePath": "remoteFiles","remoteFilePathType": "msg","localFilePath": "localPath","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "下载到本地","x": 1410,"y": 2000,"wires": [["aaaad24a.0459"]]},{"id": "bf3e53e5.546a7","type": "comment","z": "648f70b0.d1af8","name": "从SFTP下载数据(takt_rms)","info": "","x": 180,"y": 1920,"wires": []},{"id": "aaaad24a.0459","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = {\"start\":msg.localPath,\"pattern\":\"*.csv\",\"folders\":\"*\"};\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 110,"y": 2100,"wires": [["45eb5c68.d144b4"]]},{"id": "45eb5c68.d144b4","type": "fs-file-lister","z": "648f70b0.d1af8","name": "指定文件目录","start": "msg.localPath","pattern": "*.csv","folders": "*","hidden": false,"lstype": "files","path": true,"single": false,"depth": 0,"stat": false,"showWarnings": true,"x": 220,"y": 2180,"wires": [["6a7600df.0ac16"]]},{"id": "7d07c0d9.c7c79","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天5:30执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "30 05 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 2480,"wires": [["1e04d895.b9bba7"]]},{"id": "1e04d895.b9bba7","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "list","remoteFilePath": "/home/ftpuser/cs001/Mod1/OneTaktOneRow","remoteFilePathType": "str","localFilePath": "","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "文件一览(takt_ptn)","x": 410,"y": 2480,"wires": [["880b87d6.8950a8"]]},{"id": "880b87d6.8950a8","type": "function","z": "648f70b0.d1af8","name": "取得前一天的文件","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet date = new Date();\nlet dateStr = date.getFullYear().toString();\ndateStr += prefixZero((date.getMonth() + 1), 2);\ndateStr += prefixZero((date.getDate() - 1), 2);\n\n//test data\ndateStr = \"20210613\";\n\nlet len = msg.payload.length;\nlet file = [];\nfor (let i = 0; i < len; i++) {\n if (msg.payload[i].indexOf(dateStr) != -1) {\n file.push(msg.payload[i]);\n }\n}\nmsg.remoteFiles = file;\nmsg.date = dateStr\nflow.set(\"date\", dateStr)\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 670,"y": 2480,"wires": [["1e63f311.bb6aed"]]},{"id": "1e63f311.bb6aed","type": "switch","z": "648f70b0.d1af8","name": "","property": "remoteFiles.length","propertyType": "msg","rules": [{"t": "eq","v": "0","vt": "num"},{"t": "gt","v": "0","vt": "num"}],"checkall": "true","repair": false,"outputs": 2,"x": 870,"y": 2480,"wires": [["919b6e6c.47484"],["e6481b72.501cc8"]]},{"id": "4130f5af.7063bc","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1410,"y": 2420,"wires": []},{"id": "e6481b72.501cc8","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/takt_ptn/\" + msg.date;\nmsg.payload = \"create_time: \" + new Date();\nmsg.filename = msg.localPath + \"/data_info\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1040,"y": 2500,"wires": [["82a9504c.2130d"]]},{"id": "82a9504c.2130d","type": "file","z": "648f70b0.d1af8","name": "","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1230,"y": 2460,"wires": [["57461667.f797f8"]]},{"id": "57461667.f797f8","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "get","remoteFilePath": "remoteFiles","remoteFilePathType": "msg","localFilePath": "localPath","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "下载到本地","x": 1410,"y": 2500,"wires": [["736b2a9a.722a24"]]},{"id": "f80dfb5.d066108","type": "comment","z": "648f70b0.d1af8","name": "从SFTP下载数据(takt_ptn)","info": "","x": 180,"y": 2440,"wires": []},{"id": "53b6f3f2.d9291c","type": "comment","z": "648f70b0.d1af8","name": "######################################################################----------TAKT_PTN----------################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 2380,"wires": []},{"id": "736b2a9a.722a24","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = {\"start\":msg.localPath,\"pattern\":\"*.csv\",\"folders\":\"*\"};\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 110,"y": 2640,"wires": [["f4797cc9.1cf6f"]]},{"id": "f4797cc9.1cf6f","type": "fs-file-lister","z": "648f70b0.d1af8","name": "指定文件目录","start": "msg.localPath","pattern": "*.csv","folders": "*","hidden": false,"lstype": "files","path": true,"single": false,"depth": 0,"stat": false,"showWarnings": true,"x": 240,"y": 2720,"wires": [["8607526c.fe58c"]]},{"id": "f9b4d7dc.b45908","type": "function","z": "648f70b0.d1af8","name": "","func": "//msg.filename = \"C:/temp/data/takt_ptn/p2_1_20210601.csv\";\nmsg.filename = msg.payload;\n//解析文件名\nlet s = msg.filename.lastIndexOf(\"\\\\\");\nlet splitStr = msg.filename.substr(s + 1).split(\"_\");\nflow.set(\"robot_id\", splitStr[0]);\nflow.set(\"axis_id\", splitStr[1]);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 610,"y": 2720,"wires": [["4d476239.558e9c"]]},{"id": "aaf20f27.d0f05","type": "comment","z": "648f70b0.d1af8","name": "######################################################################----------RMS_TAKT----------################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 1860,"wires": []},{"id": "4cbd6e6b.e3879","type": "comment","z": "648f70b0.d1af8","name": "######################################################################----------BD_ALARM----------################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 1300,"wires": []},{"id": "ceb21553.e1dec8","type": "comment","z": "648f70b0.d1af8","name": "######################################################################----------NORMAL_PTN----------################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 770,"y": 2900,"wires": []},{"id": "aeb120e6.cf309","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天5:00执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "00 05 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 3000,"wires": [["3d501c8.e7579e4"]]},{"id": "3d501c8.e7579e4","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "list","remoteFilePath": "/home/ftpuser/cs001/Mod1/PTN","remoteFilePathType": "str","localFilePath": "","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "文件一览(takt_ptn)","x": 410,"y": 3000,"wires": [["549cd5f4.9ca7ec"]]},{"id": "549cd5f4.9ca7ec","type": "function","z": "648f70b0.d1af8","name": "取得前一天的文件","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet date = new Date();\nlet dateStr = date.getFullYear().toString();\ndateStr += prefixZero((date.getMonth() + 1), 2);\ndateStr += prefixZero((date.getDate() - 1), 2);\n\n//test data\ndateStr = \"20210613\";\n\nlet len = msg.payload.length;\nlet file = [];\nfor (let i = 0; i < len; i++) {\n if (msg.payload[i].indexOf(dateStr) != -1) {\n file.push(msg.payload[i]);\n }\n}\nmsg.remoteFiles = file;\nflow.set(\"date\", dateStr);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 670,"y": 3000,"wires": [["69d1b07d.c6ce4"]]},{"id": "69d1b07d.c6ce4","type": "switch","z": "648f70b0.d1af8","name": "","property": "remoteFiles.length","propertyType": "msg","rules": [{"t": "eq","v": "0","vt": "num"},{"t": "gt","v": "0","vt": "num"}],"checkall": "true","repair": false,"outputs": 2,"x": 870,"y": 3000,"wires": [["4fcf6764.974948"],["1469daa7.0060a5"]]},{"id": "2eb22c28.cffbf4","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 1410,"y": 2940,"wires": []},{"id": "1469daa7.0060a5","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/normal_ptn/\" + flow.get(\"date\");\nmsg.payload = \"create_time: \" + new Date();\nmsg.filename = msg.localPath + \"/data_info\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1040,"y": 3020,"wires": [["6d2b18b0.74bb68"]]},{"id": "6d2b18b0.74bb68","type": "file","z": "648f70b0.d1af8","name": "","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1230,"y": 2980,"wires": [["d26c2756.8b4798"]]},{"id": "d26c2756.8b4798","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "get","remoteFilePath": "remoteFiles","remoteFilePathType": "msg","localFilePath": "localPath","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "下载到本地","x": 1410,"y": 3020,"wires": [["18118e2d.0a5912"]]},{"id": "7e38d583.8132fc","type": "comment","z": "648f70b0.d1af8","name": "从SFTP下载数据(normal_ptn)","info": "","x": 190,"y": 2960,"wires": []},{"id": "18118e2d.0a5912","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = {\"start\":msg.localPath,\"pattern\":\"*.csv\",\"folders\":\"*\"};\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 110,"y": 3160,"wires": [["ab5e9c6f.ff64e"]]},{"id": "ab5e9c6f.ff64e","type": "fs-file-lister","z": "648f70b0.d1af8","name": "指定文件目录","start": "msg.localPath","pattern": "*.csv","folders": "*","hidden": false,"lstype": "files","path": true,"single": false,"depth": 0,"stat": false,"showWarnings": true,"x": 220,"y": 3240,"wires": [["eb9e84f2.d60098"]]},{"id": "b621af95.8c6d","type": "function","z": "648f70b0.d1af8","name": "","func": "//msg.filename = \"C:/temp/data/normal_ptn/ptn_p2_1_20200529.csv\";\nmsg.filename = msg.payload;\n\n//解析文件名\nlet s = msg.filename.lastIndexOf(\"\\\\\");\nlet splitStr = msg.filename.substr(s + 1).split(\"_\");\nflow.set(\"robot_id\", splitStr[1]);\nflow.set(\"axis_id\", splitStr[2]);\n// ptn_no\nlet e = msg.filename.lastIndexOf(\"_\");\nflow.set(\"ptn_no\", msg.filename.substring(s + 1, e));\n\n//删除旧的标准PTN数据\nmsg.query = \"delete from bd_ptn_normal where robot_id = '\" + splitStr[1] + \n \"' and moto_num = '\" + splitStr[2] + \"'\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 570,"y": 3160,"wires": [["1f16287a.d8db98"]]},{"id": "e1a07114.2cfca","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 1160,"wires": []},{"id": "90419061.6f85a","type": "comment","z": "648f70b0.d1af8","name": "################################################################# 下载数据并保存到DB ########################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 1200,"wires": []},{"id": "234528a8.a5f5e8","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 1240,"wires": []},{"id": "5347666c.e740e8","type": "inject","z": "648f70b0.d1af8","d": true,"name": "","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "1","crontab": "","once": false,"onceDelay": 0.1,"topic": "","payload": "[170,0,0,8,0,0,0,0,3,3,16,16,16,16,0,255]","payloadType": "bin","x": 130,"y": 200,"wires": [["cb0c97b1.617cf8"]]},{"id": "40ddbcce.6972d4","type": "serial out","z": "648f70b0.d1af8","d": true,"name": "","serial": "25f44ffa.156ed","x": 910,"y": 200,"wires": []},{"id": "cb0c97b1.617cf8","type": "function","z": "648f70b0.d1af8","name": "","func": "var temp= new Buffer([0x01,0x03,0x00,0x00,0x00,0x02,0xC4,0x0B]);\nmsg.payload = temp;\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 510,"y": 200,"wires": [["40ddbcce.6972d4","af00c902.581078"]]},{"id": "3edb396a.d5d456","type": "serial in","z": "648f70b0.d1af8","d": true,"name": "","serial": "25f44ffa.156ed","x": 110,"y": 360,"wires": [["f5c05094.3b92e"]]},{"id": "10d86fcb.0e9f7","type": "debug","z": "648f70b0.d1af8","name": "","active": false,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 610,"y": 420,"wires": []},{"id": "af00c902.581078","type": "debug","z": "648f70b0.d1af8","name": "","active": false,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 930,"y": 260,"wires": []},{"id": "f5c05094.3b92e","type": "function","z": "648f70b0.d1af8","name": "","func": "// 补0操作\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet rtnVal = msg.payload;\nlet humidity = \"0x\" + rtnVal[3].toString(16) + prefixZero(rtnVal[4].toString(16), 2);\nhumidity = parseInt(humidity, 16) / 10;\nlet temperature = \"0x\" + rtnVal[5].toString(16) + prefixZero(rtnVal[6].toString(16), 2);\ntemperature = parseInt(temperature, 16) / 10;\nmsg.payload = [humidity, temperature];\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 350,"y": 360,"wires": [["10d86fcb.0e9f7","cb8c2d22.cda7a"]]},{"id": "cb8c2d22.cda7a","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let d1 = msg.payload[0];\nlet d2 = msg.payload[1];\n\nmsg.payload = [\n {\n measurement: \"bd_current_data\",\n fields: {\n data1: d1,\n data2: d2\n },\n tags:{\n index: \"001\",\n robot_id: \"DEV1\",\n cs_id: \"cs01\",\n moto_num: \"1\",\n data_index: \"5\",\n day_mark: \"0\"\n }\n }];\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 600,"y": 360,"wires": [["cb17ffea.ec229"]]},{"id": "cb17ffea.ec229","type": "influxdb batch","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","precision": "","retentionPolicy": "","name": "influxdb1","database": "influxdb1","precisionV18FluxV20": "ns","retentionPolicyV18Flux": "autogen","org": "","bucket": "","x": 920,"y": 360,"wires": []},{"id": "846135f2.c015f8","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 60,"wires": []},{"id": "c45a7c0c.67df","type": "comment","z": "648f70b0.d1af8","name": "################################################################# 实时数据取得并保存 ########################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 100,"wires": []},{"id": "9ef535bd.fdc398","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 140,"wires": []},{"id": "aedee7f3.a66da8","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 620,"wires": []},{"id": "d2ec06eb.1d7f88","type": "comment","z": "648f70b0.d1af8","name": "################################################################# 从DB取出数据并上传 ########################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 660,"wires": []},{"id": "c7fd4177.d73f4","type": "comment","z": "648f70b0.d1af8","name": "############################################################################################################################################################################","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 760,"y": 700,"wires": []},{"id": "c29eda28.3561d8","type": "comment","z": "648f70b0.d1af8","name": "读取DB数据并生成CSV","info": "","x": 160,"y": 780,"wires": []},{"id": "2a30de65.cc8632","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天0:01执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "01 00 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 820,"wires": [["e692b994.5c52e8"]]},{"id": "e692b994.5c52e8","type": "function","z": "648f70b0.d1af8","name": "查询语句","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\n/**\n * 取得过去日期,格式yyyy-MM-dd\n * @param n: 过去天数\n */\nfunction getBeforeDate(n) {\n let day = new Date();\n day.setTime(day.getTime()-24*60*60*1000*n);\n let formatedDate = day.getFullYear() + \"-\" + prefixZero((day.getMonth() + 1), 2) + \"-\" + prefixZero(day.getDate(), 2);\n return formatedDate;\n}\n\nconst TIME = \"T16:00:00Z\";\nlet startTime = getBeforeDate(2) + TIME;\nlet yestoday = getBeforeDate(1);\nlet endTime = yestoday + TIME;\nmsg.query = \"SELECT * from bd_current_data WHERE time >= '\" + startTime + \"' AND time <= '\" + endTime + \"'\";\nmsg.notifyDate = yestoday;\nmsg.date = yestoday.replaceAll(\"-\",\"\"); //后面要用到\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 340,"y": 820,"wires": [["e65c2e04.5407c"]]},{"id": "a38ed121.def7f","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/current_data/\" + msg.date;\nmsg.csvfile = msg.robotId + \"_\" + msg.date + \"_\" + \"temperature.csv\";\nmsg.filename = msg.localPath + \"/\" + msg.csvfile;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1160,"y": 820,"wires": [["ba743a19.4ac0e8"]]},{"id": "6de0eac2.027864","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = \"BD_ALARM: 指定日期(\" + flow.get(\"date\") + \")没有数据。\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1050,"y": 1360,"wires": [["50e30eb6.bf8da"]]},{"id": "9eba8011.89748","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = \"RMS_TAKT: 指定日期(\" + flow.get(\"date\") + \")没有数据。\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1030,"y": 1900,"wires": [["a475ddd2.a2187"]]},{"id": "919b6e6c.47484","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = \"TAKT_PTN: 指定日期(\" + msg.date + \")没有数据。\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1030,"y": 2420,"wires": [["4130f5af.7063bc"]]},{"id": "4fcf6764.974948","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = \"NORMAL_PTN: 指定日期(\" + flow.get(\"date\") + \")没有数据。\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1030,"y": 2940,"wires": [["2eb22c28.cffbf4"]]},{"id": "fc0987cb.1f1c18","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_ptn_takt","measurement": "bd_ptn_takt","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 1410,"y": 2640,"wires": []},{"id": "ecf9e410.459b38","type": "function","z": "648f70b0.d1af8","name": "生成notify文件","func": "//node.warn(msg.payload);\nlet result = [];\nresult[0] = msg.notifyDate;\nresult[1] = msg.remotePath + \"/\" + msg.csvfile;\n\nmsg.payload = result;\n\nreturn msg;\n","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 580,"y": 980,"wires": [["594964e8.56125c"]]},{"id": "594964e8.56125c","type": "csv","z": "648f70b0.d1af8","name": "csv属性设置","sep": ",","hdrin": true,"hdrout": "once","multi": "one","ret": "\\r\\n","temp": "通知日期,原始数据","skip": "0","strings": false,"include_empty_strings": false,"include_null_values": false,"x": 790,"y": 980,"wires": [["b3522263.1cfa7"]]},{"id": "b3522263.1cfa7","type": "function","z": "648f70b0.d1af8","name": "本地路径","func": "msg.localPath = \"C:/temp/data/current_data/\" + msg.date;\n//msg.payload = \"create_time: \" + new Date();\nmsg.filename = msg.localPath + \"/\" + msg.robotId + \"_notify_\" + msg.date + \".csv\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 980,"y": 980,"wires": [["40dc1daa.c11494"]]},{"id": "40dc1daa.c11494","type": "file","z": "648f70b0.d1af8","name": "文件path","filename": "","appendNewline": false,"createDir": true,"overwriteFile": "true","encoding": "utf8","x": 1160,"y": 920,"wires": [["650edbba.1994b4"]]},{"id": "650edbba.1994b4","type": "SFTP-main","z": "648f70b0.d1af8","path": "/","method": "put","remoteFilePath": "/home/ftpuser/cs001/notify","remoteFilePathType": "str","localFilePath": "filename","localFilePathType": "msg","server": "42aee480.a1f85c","outputs": 1,"debug": false,"name": "SFTP设置","x": 1350,"y": 980,"wires": [[]]},{"id": "ad6004.2445e","type": "influxdb in","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_takt_rms","query": "","rawOutput": false,"precision": "","retentionPolicy": "","org": "organisation","x": 1130,"y": 1680,"wires": [["39df6d58.17fe72"]]},{"id": "5f940f1f.3f32","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_takt_rms","measurement": "bd_takt_rms","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 1370,"y": 2100,"wires": []},{"id": "6248b363.ecf8cc","type": "function","z": "648f70b0.d1af8","name": "","func": "if (msg.payload == null) {\n return;\n}\n\nfunction convertTime(str){\n\tlet date1 = new Date(str);\n\treturn date1.getTime() * 1000000;\n}\n\nlet checkTime = msg.payload.checkTime + msg.payload.checkMSecond;\ncheckTime = convertTime(checkTime);\n\n//解析文件名\nlet s = msg.filename.lastIndexOf(\"\\\\\");\nlet splitStr = msg.filename.substr(s + 1).split(\"_\");\nlet robotId = splitStr[0];\nlet axisId = splitStr[1];\n\n//查询数据库,取出索引\nmsg.query = \"select time, data_index from bd_takt_rms where robot_id = '\" + robotId + \n \"' and moto_num = '\" + axisId + \n \"' and act_date = '\" + flow.get(\"date\") + \n \"' and time < \" + checkTime + \n \" order by time desc limit 1\";\n//node.warn(msg.query);\n\nmsg.csvData = msg.payload;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 1030,"y": 1600,"wires": [["ad6004.2445e"]]},{"id": "fb61e2c4.86601","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_ptn_normal","measurement": "bd_ptn_normal","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 1380,"y": 3160,"wires": []},{"id": "8607526c.fe58c","type": "delay","z": "648f70b0.d1af8","name": "","pauseType": "rate","timeout": "5","timeoutUnits": "seconds","rate": "1","nbRateUnits": "90","rateUnits": "second","randomFirst": "1","randomLast": "5","randomUnits": "seconds","drop": false,"outputs": 1,"x": 440,"y": 2640,"wires": [["f9b4d7dc.b45908"]]},{"id": "a4bd4a15.51a958","type": "comment","z": "648f70b0.d1af8","name": "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~保存设备数据信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 720,"y": 3400,"wires": []},{"id": "ce0ae552.82e978","type": "inject","z": "648f70b0.d1af8","name": "","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 130,"y": 3460,"wires": [["b035f6fb.1fa848"]]},{"id": "b035f6fb.1fa848","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let timeStamp = new Date().getTime();\n\nlet res = [];\n//定义轴数\nconst axisCount = 7;\n//定义机器人数量\nconst robots = [\"p1\", \"p2\"];\n\nlet index = 1;\nfor (let i = 0; i < robots.length; i++) {\n for (let j = 1; j <= axisCount; j++) {\n let obj = [];\n // fields\n obj[0] = {\n plc_no: \"0\",\n st_index: \"0\",\n status: \"normal\",\n time: (timeStamp + index) * 1000000\n };\n // tags\n obj[1] = {\n robot_id: robots[i],\n cs_id: \"cs001\",\n axis_id: j,\n };\n \n res[index - 1] = obj;\n index++;\n }\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 320,"y": 3460,"wires": [["a3a973ed.a5f18"]]},{"id": "a3a973ed.a5f18","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_dev","measurement": "bd_dev","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 540,"y": 3500,"wires": []},{"id": "6a7600df.0ac16","type": "delay","z": "648f70b0.d1af8","name": "","pauseType": "rate","timeout": "5","timeoutUnits": "seconds","rate": "1","nbRateUnits": "1","rateUnits": "second","randomFirst": "1","randomLast": "5","randomUnits": "seconds","drop": false,"outputs": 1,"x": 410,"y": 2100,"wires": [["2e93c280.2cc70e"]]},{"id": "8e4db390.4f458","type": "comment","z": "648f70b0.d1af8","name": "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~日期管理~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 690,"y": 3660,"wires": []},{"id": "831c2a56.faeab8","type": "inject","z": "648f70b0.d1af8","d": true,"name": "每天0:01执行","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "00 00 * * *","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 160,"y": 3720,"wires": [["612b461a.c55928"]]},{"id": "612b461a.c55928","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "/**\n* 自定义函数名:PrefixZero\n* @param num: 被操作数\n* @param n: 固定的总位数\n*/\nfunction prefixZero(num, n) {\n return (Array(n).join(0) + num).slice(-n);\n}\n\nlet date = new Date();\nlet dateStr = date.getFullYear().toString();\ndateStr += prefixZero((date.getMonth() + 1), 2);\nlet yestoday = dateStr + prefixZero((date.getDate() - 1), 2);\nlet today = dateStr + prefixZero(date.getDate(), 2);\n//test data\n//yestoday = \"20210623\";\n//today = \"20210624\";\n\nlet obj = [];\n // fields\n obj[0] = {\n date: yestoday,\n time: new Date()\n };\n // tags\n obj[1] = {\n now_date: today\n };\n\nmsg.payload = obj;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 360,"y": 3720,"wires": [["94d3afb9.92ddc","bf5c6295.8a877"]]},{"id": "94d3afb9.92ddc","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_date","measurement": "bd_date","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 600,"y": 3720,"wires": []},{"id": "bf5c6295.8a877","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 610,"y": 3780,"wires": []},{"id": "c62b4b13.b3e498","type": "function","z": "648f70b0.d1af8","name": "测试数据","func": "let timeStamp = new Date().getTime();\n\nlet res = [];\n//定义轴数\nconst axisCount = 1;\n//定义机器人数量\nconst robots = [\"h1\"];\n\nlet index = 1;\nfor (let i = 0; i < robots.length; i++) {\n for (let j = 1; j <= axisCount; j++) {\n let obj = [];\n // fields\n obj[0] = {\n plc_no: \"0\",\n st_index: \"0\",\n status: \"normal\",\n time: (timeStamp + index) * 1000000\n };\n // tags\n obj[1] = {\n robot_id: robots[i],\n cs_id: \"cs001\",\n axis_id: j,\n };\n \n res[index - 1] = obj;\n index++;\n }\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 320,"y": 3540,"wires": [["a3a973ed.a5f18"]]},{"id": "43bde28d.154a5c","type": "inject","z": "648f70b0.d1af8","name": "","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 130,"y": 3540,"wires": [["c62b4b13.b3e498"]]},{"id": "b6042bbe.11d9c8","type": "delay","z": "648f70b0.d1af8","name": "","pauseType": "rate","timeout": "5","timeoutUnits": "seconds","rate": "200","nbRateUnits": "1","rateUnits": "second","randomFirst": "1","randomLast": "5","randomUnits": "seconds","drop": false,"outputs": 1,"x": 1100,"y": 2720,"wires": [["635f943c.04c5dc"]]},{"id": "1be218a6.09b5b7","type": "inject","z": "648f70b0.d1af8","name": "","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 130,"y": 4160,"wires": [["4774f4e3.a5878c"]]},{"id": "ce68bbb1.4a2bb8","type": "debug","z": "648f70b0.d1af8","name": "test001","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 780,"y": 4160,"wires": []},{"id": "2ca356d1.09af3a","type": "complete","z": "648f70b0.d1af8","name": "","scope": ["ce68bbb1.4a2bb8"],"uncaught": false,"x": 130,"y": 4280,"wires": [["d7114c74.24a46"]]},{"id": "5f650ae4.e27c24","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 590,"y": 4280,"wires": []},{"id": "d7114c74.24a46","type": "function","z": "648f70b0.d1af8","name": "","func": "msg.payload = flow.get(\"t1\");\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 330,"y": 4280,"wires": [["5f650ae4.e27c24"]]},{"id": "4cdf3e60.f26f6","type": "influxdb in","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "","query": "","rawOutput": false,"precision": "","retentionPolicy": "","org": "organisation","x": 360,"y": 4160,"wires": [["786c977c.5fb108"]]},{"id": "786c977c.5fb108","type": "function","z": "648f70b0.d1af8","name": "","func": "flow.set(\"t1\", 333);\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 570,"y": 4160,"wires": [["ce68bbb1.4a2bb8"]]},{"id": "1f16287a.d8db98","type": "influxdb in","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_ptn_normal","query": "","rawOutput": false,"precision": "","retentionPolicy": "","org": "organisation","x": 700,"y": 3240,"wires": [["b69fb787.2b0648"]]},{"id": "4774f4e3.a5878c","type": "function","z": "648f70b0.d1af8","name": "","func": "var r = \"p1\";\nvar m = \"1\";\nmsg.query = \"delete from bd_ptn_normal where robot_id = '\" + r + \n \"' and moto_num = '\" + m + \"'\";\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 230,"y": 4080,"wires": [["4cdf3e60.f26f6"]]},{"id": "cfc6f50b.d4a328","type": "comment","z": "648f70b0.d1af8","name": "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~删除数据~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 690,"y": 4020,"wires": []},{"id": "adbe799a.91ad38","type": "comment","z": "648f70b0.d1af8","name": "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~插入offset~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~","info": "1\n2\n3\n4\n5\n6\n7\n8\n9","x": 690,"y": 4400,"wires": []},{"id": "c4fdddba.3fed","type": "function","z": "648f70b0.d1af8","name": "数据转换","func": "let res = [];\nconst MAX_TAKT_NUM = 1800; //1天数据量,每隔48秒1个值,最多有1800\nconst INTERVAL = 30; //取得takt index前后30条数据,offset要设为taktIdx-30*2400\nconst PTN_NUMS = 2400;\n\n\nfor (let i = 1; i <= MAX_TAKT_NUM; i++) {\n let obj = [];\n let offsetValue = 0;\n if (i > INTERVAL) {\n offsetValue = (i - INTERVAL) * PTN_NUMS;\n }\n \n // fields\n obj[0] = {\n offset_pos: offsetValue,\n };\n // tags\n obj[1] = {\n takt_idx: i\n };\n \n res[i - 1] = obj;\n}\n\nmsg.payload = res;\n\nreturn msg;","outputs": 1,"noerr": 0,"initialize": "","finalize": "","libs": [],"x": 380,"y": 4460,"wires": [["aa1666bb.d037e8","c366c55b.572b38"]]},{"id": "aa1666bb.d037e8","type": "influxdb out","z": "648f70b0.d1af8","influxdb": "f97c94dc.166388","name": "bd_offset","measurement": "bd_offset","precision": "","retentionPolicy": "","database": "database","precisionV18FluxV20": "ms","retentionPolicyV18Flux": "","org": "organisation","bucket": "bucket","x": 620,"y": 4460,"wires": []},{"id": "c366c55b.572b38","type": "debug","z": "648f70b0.d1af8","name": "","active": true,"tosidebar": true,"console": false,"tostatus": false,"complete": "payload","targetType": "msg","statusVal": "","statusType": "auto","x": 630,"y": 4520,"wires": []},{"id": "81a93bd2.31b038","type": "inject","z": "648f70b0.d1af8","name": "","props": [{"p": "payload"},{"p": "topic","vt": "str"}],"repeat": "","crontab": "","once": false,"onceDelay": 0.1,"topic": "","payload": "","payloadType": "date","x": 150,"y": 4460,"wires": [["c4fdddba.3fed"]]},{"id": "f97c94dc.166388","type": "influxdb","z": "648f70b0.d1af8","hostname": "127.0.0.1","port": "8086","protocol": "http","database": "influxdb1","name": "influxdb1","usetls": false,"tls": "","influxdbVersion": "1.x","url": "http://localhost:8086","rejectUnauthorized": true},{"id": "42aee480.a1f85c","type": "SFTP-credentials","host": "118.190.53.60","port": "22","username": "root","password": "HCR&D1234"},{"id": "25f44ffa.156ed","type": "serial-port","serialport": "COM4","serialbaud": "4800","databits": "8","parity": "none","stopbits": "1","waitfor": "","dtr": "none","rts": "none","cts": "none","dsr": "none","newline": "0","bin": "bin","out": "time","addchar": "","responsetimeout": "10000"}]
