前言
Node-RED是一款基于Node.js的流程编排工具,可以通过拖拽方式组合出一条完整的数据流。而node-red-contrib-nostradamus则是一个提供未来数据预测功能的npm包,能够轻松在Node-RED中集成。
安装
在安装前,请确认您已经安装了Node-RED。
在命令行中输入以下指令进行安装:
npm install node-red-contrib-nostradamus
安装完成后,启动Node-RED并进入编辑器,即可在Node库中查找node-red-contrib-nostradamus包。
使用
在编辑器左侧的Node库中,找到node-red-contrib-nostradamus并拖入工作流中。
右侧会显示Node的配置界面,可对其进行个性化的设置。这里需要注意几个重要参数:
- Model:选择使用的预测模型,支持的模型有ARIMA、Prophet和SES三种。
- Data Sources:提供数据源,支持的格式有CSV和JSON。
- Prediction Duration:预测的时间范围,以天为单位。
配置完成后,保存并部署工作流。
示例
以下是一份基于node-red-contrib-nostradamus包的简易工作流示例:
[{"id":"a5d5fcef.c5f5a8","type":"inject","z":"beec83d.57d72c8","name":"设定起始时间","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\n \"start\":\"2021-01-01 00:00:00\",\n \"end\":\"2021-01-09 00:00:00\"\n}","payloadType":"json","x":170,"y":160,"wires":[["275f9d9a.1470d6"]]},{"id":"275f9d9a.1470d6","type":"nostradamus","z":"beec83d.57d72c8","name":"模型预测","model":"prophet","data":"sql","dataLocation":"testdata","dFormat":"json","x":410,"y":160,"wires":[["938d788f.910878"]]},{"id":"938d788f.910878","type":"debug","z":"beec83d.57d72c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":160,"wires":[]},{"id":"362b67be.0c329a","type":"file","z":"beec83d.57d72c8","name":"","filename":"testdata.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":590,"y":80,"wires":[[]]},{"id":"3c6b8e42.384064","type":"csv","z":"beec83d.57d72c8","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"x":450,"y":80,"wires":[["362b67be.0c329a"]]},{"id":"356a289.a1af706","type":"inject","z":"beec83d.57d72c8","name":"设定起始时间","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\n \"start\":\"2021-01-01 00:00:00\",\n \"end\":\"2021-01-09 00:00:00\"\n}","payloadType":"json","x":170,"y":80,"wires":[["3c6b8e42.384064"]]},{"id":"3f1292b6.834b6c","type":"comment","z":"beec83d.57d72c8","name":"将数据存储到testdata.csv数据源","info":"","x":230,"y":40,"wires":[]},{"id":"c38abd3a.f3a6e","type":"comment","z":"beec83d.57d72c8","name":"从存储系统中读取数据进行预测","info":"","x":240,"y":220,"wires":[]}]
该示例的作用是从CSV文件中读取数据,再使用Prophet模型进行未来数据预测,并将结果通过调试输出。
结论
node-red-contrib-nostradamus是一款方便高效的npm包,可以大大提高未来数据预测的工作效率。在Node-RED中的集成使用,也进一步增强了应用的可拓展性。
(本文完)
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60056bd581e8991b448e5772