-
Notifications
You must be signed in to change notification settings - Fork 1
/
MovIt.json
1 lines (1 loc) · 93.6 KB
/
MovIt.json
1
[{"id":"ed0c995d.e2e7f8","type":"tab","label":"entré MQTT","disabled":false,"info":""},{"id":"62e9dd9c.3ec8b4","type":"tab","label":"Login","disabled":false,"info":""},{"id":"c6f5a9d0.2bf118","type":"tab","label":"Simulation basic","disabled":false,"info":""},{"id":"79c89fe4.873e6","type":"tab","label":"get info","disabled":false,"info":""},{"id":"b9daa40a.159ce8","type":"tab","label":"Recommandations","disabled":false,"info":""},{"id":"1dab1279.d003ee","type":"tab","label":"Sortie MQTT","disabled":false,"info":""},{"id":"23a30f9a.261b6","type":"tab","label":"Create Files","disabled":false,"info":""},{"id":"988214cb.995018","type":"tab","label":"Send File","disabled":false,"info":""},{"id":"da4609d5.3036c8","type":"tab","label":"testing","disabled":false,"info":""},{"id":"4e4dbcc2.17d054","type":"subflow","name":"vérify token","info":"","in":[{"x":140,"y":320,"wires":[{"id":"e29f42ca.a113c"}]}],"out":[{"x":1220,"y":260,"wires":[{"id":"db0ceff6.603c","port":0}]}]},{"id":"335e86e1.c431da","type":"subflow","name":"keep_alive_watcher","info":"","in":[{"x":60,"y":140,"wires":[{"id":"402e62db.9318dc"}]}],"out":[{"x":1140,"y":140,"wires":[{"id":"54e3eb5e.a5e6a4","port":0}]}]},{"id":"857ac83c.e099a8","type":"subflow","name":"GetDayBack","info":"","in":[{"x":140,"y":220,"wires":[{"id":"3dd32ccf.927104"}]}],"out":[{"x":900,"y":220,"wires":[{"id":"298646f7.89adea","port":0}]}]},{"id":"6c6d0616.a7df98","type":"subflow","name":"GetMonthBack","info":"","in":[{"x":80,"y":160,"wires":[{"id":"2f8401b2.bbf70e"}]}],"out":[{"x":860,"y":160,"wires":[{"id":"f111a7e3.1e91e8","port":0}]}]},{"id":"a30d48d8.f609e8","type":"subflow","name":"SittingTime","info":"","in":[{"x":80,"y":160,"wires":[{"id":"6741ff25.d9c22"}]}],"out":[{"x":740,"y":160,"wires":[{"id":"b93200a.1a5ad","port":0}]}]},{"id":"d9e2e631.4f8778","type":"subflow","name":"GravityCenter","info":"","in":[{"x":60,"y":140,"wires":[{"id":"3c4a40e1.a66fd"}]}],"out":[{"x":720,"y":140,"wires":[{"id":"dcb6fbac.be34a8","port":0}]}]},{"id":"36e4ab73.495fb4","type":"subflow","name":"GetDayBouts","info":"","in":[{"x":100,"y":140,"wires":[{"id":"3f7667f.e5d5098"}]}],"out":[{"x":820,"y":140,"wires":[{"id":"c702805e.c0646","port":0}]}]},{"id":"dad69f2b.73de2","type":"subflow","name":"GetLastDate","info":"","in":[{"x":140,"y":100,"wires":[{"id":"4bbf0aa9.4b6fa4"}]}],"out":[{"x":1060,"y":100,"wires":[{"id":"e8beda5d.a7d618","port":0}]}]},{"id":"533bc41.d9a0d3c","type":"subflow","name":"GetDaysWithData","info":"","in":[{"x":160,"y":180,"wires":[{"id":"86fe7f00.16238"}]}],"out":[{"x":1040,"y":180,"wires":[{"id":"50f7a05b.0dc76","port":0}]}]},{"id":"ad7d8d1c.cafbf","type":"subflow","name":"GetMonthsWithData","info":"","in":[{"x":100,"y":140,"wires":[{"id":"ceaf94f8.7481b8"}]}],"out":[{"x":1060,"y":140,"wires":[{"id":"5b97c3d3.15a01c","port":0}]}]},{"id":"858faa30.bafbe8","type":"subflow","name":"GetMonthBouts","info":"","in":[{"x":80,"y":260,"wires":[{"id":"4f7cda4a.29fa14"}]}],"out":[{"x":940,"y":260,"wires":[{"id":"6a46e855.cdd708","port":0}]}]},{"id":"3ba2a49e.7ce77c","type":"mongodb","z":"","hostname":"127.0.0.1","port":"27017","db":"MovIt","name":""},{"id":"311fce6b.a3ffd2","type":"mongodb2","name":""},{"id":"c2e023a5.ad0b","type":"mongodb2","z":"","uri":"mongodb://127.0.0.1:27017/MovIt","name":"MovIt","options":"","parallelism":"-1"},{"id":"94e4b2c8.735b8","type":"mongodb2","z":"","uri":"","name":"","options":"","parallelism":"-1"},{"id":"2b8661c7.194ede","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"ba331956.2c3558","type":"ftp","z":"","host":"192.168.2.228","port":"22","secureOptions":"","user":"pi","connTimeout":"","pasvTimeout":"","keepalive":"","password":"raspberry"},{"id":"e61fab25.c40b38","type":"sftp","z":"","host":"192.168.2.228","port":"22","username":"pi","password":"raspberry","hmac":"hmac-sha2-256,hmac-sha2-512,hmac-sha1","cipher":"aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm"},{"id":"9c42017f.b5ed3","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"back angle","topic":"data/current_back_rest_angle","qos":"0","broker":"2b8661c7.194ede","x":80,"y":120,"wires":[["d353cbdb.5d4f58"]]},{"id":"1904009e.5a81df","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"pressure","topic":"data/current_center_of_pressure","qos":"0","broker":"2b8661c7.194ede","x":80,"y":220,"wires":[["1c01fe0f.4afed2"]]},{"id":"c8f58011.f27ef","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"someone","topic":"data/current_is_someone_there","qos":"0","broker":"2b8661c7.194ede","x":80,"y":300,"wires":[["d710158.344d1e8"]]},{"id":"e9a4e134.0416a","type":"http in","z":"62e9dd9c.3ec8b4","name":"","url":"/login","method":"post","upload":false,"swaggerDoc":"","x":90,"y":140,"wires":[["d7376764.918e88"]]},{"id":"c0aafdb5.90b58","type":"mongodb2 in","z":"62e9dd9c.3ec8b4","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find user","collection":"User","operation":"findOne","x":580,"y":140,"wires":[["33c4d6e7.62eb2a"]]},{"id":"d7376764.918e88","type":"function","z":"62e9dd9c.3ec8b4","name":"get Username","func":"msg.payload= '{\"username\":\"'+msg.req.body.username+'\"}';\nvar crypto = context.global.cryptojs;\nmsg.pw = crypto.SHA256( msg.req.body.password).toString();\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":140,"wires":[["8386b3b8.afc4d"]]},{"id":"8386b3b8.afc4d","type":"json","z":"62e9dd9c.3ec8b4","name":"","property":"payload","action":"obj","pretty":false,"x":450,"y":140,"wires":[["c0aafdb5.90b58"]]},{"id":"33c4d6e7.62eb2a","type":"function","z":"62e9dd9c.3ec8b4","name":"validate Password","func":"if(msg.payload.password == msg.pw){\n var token = context.global.cryptojs.lib.WordArray.random(32).toString();\n msg.result ='{\"result\":0,\"token\":\"'+token+'\"}';\n msg.payload.token= token;\n msg.query ={\"username\":msg.payload.username}\n msg.value= {\"username\":msg.payload.username,\"password\":msg.payload.password,\"token\":msg.payload.token};\n msg.payload = [];\n msg.payload[0]= msg.query;\n msg.payload[1]=msg.value;\n}\nelse\n msg.result = '{\"result\":401}';\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":140,"wires":[["89587608.3c4368"]]},{"id":"f787b8dd.85b708","type":"switch","z":"62e9dd9c.3ec8b4","name":"","property":"result.result","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"neq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1070,"y":140,"wires":[["a7bcd925.e25508"],["4b672da8.cf9b54"]]},{"id":"a7bcd925.e25508","type":"mongodb2 in","z":"62e9dd9c.3ec8b4","service":"_ext_","configNode":"c2e023a5.ad0b","name":"create token","collection":"User","operation":"findOneAndUpdate","x":1210,"y":80,"wires":[["4b672da8.cf9b54"]]},{"id":"a306472a.48f6f8","type":"http response","z":"62e9dd9c.3ec8b4","name":"","statusCode":"","headers":{},"x":1410,"y":140,"wires":[]},{"id":"4b672da8.cf9b54","type":"function","z":"62e9dd9c.3ec8b4","name":"send result","func":"msg.payload = msg.result;\nreturn msg;","outputs":1,"noerr":0,"x":1250,"y":140,"wires":[["a306472a.48f6f8"]]},{"id":"89587608.3c4368","type":"json","z":"62e9dd9c.3ec8b4","name":"","property":"result","action":"obj","pretty":false,"x":930,"y":140,"wires":[["f787b8dd.85b708"]]},{"id":"176575a7.f0811a","type":"function","z":"c6f5a9d0.2bf118","name":"creation test","func":"var times = 0;\nvar timeStamps = 1517439600000;\nvar angles =0 ;\nvar docs=[];\nvar k =0;\nfor(j=0;j<62;j++){\n for(i=0;i<300;i++){\n var date = new Date(timeStamps);\n\n var document = {date:date ,timestamp:timeStamps, angle:angles, fake:\"1\"};\n\n docs[k] =document;\n \n timeStamps +=288000;\n angles = Math.round(Math.random()*45);\n k++;\n }\n timeStamps +=288000;\n angles = Math.round(Math.random()*45);\n}\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":300,"wires":[["3be155d4.aa209a"]]},{"id":"3be155d4.aa209a","type":"mongodb2 in","z":"c6f5a9d0.2bf118","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"back_angle","operation":"insertMany","x":740,"y":260,"wires":[["bbb4df43.97676"]]},{"id":"b11fb1c5.774ca","type":"http in","z":"79c89fe4.873e6","name":"getDaysWithData","url":"/daysWithData","method":"get","upload":false,"swaggerDoc":"","x":140,"y":200,"wires":[["93bd1535.1e8c98"]]},{"id":"768a845d.26bf5c","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"speed","topic":"data/current_chair_speed","qos":"0","broker":"2b8661c7.194ede","x":70,"y":480,"wires":[["195ec0a8.18333f"]]},{"id":"cefddfdf.eda88","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"var flowContext = this.context.flow;\nif(flowContext.isSitting==null){\n flowContext.isSitting=0;\n}\nvar angles =msg.payload.angle;\nif( flowContext.isSitting==1){\n var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\n msg.payload = {date:date ,timestamp:date.getTime(), angle:angles,isSitting:1, fake:\"0\"};\n}\nelse{\n msg.payload=null;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":80,"wires":[["14d35acb.066145"]]},{"id":"6c4c2373.39613c","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"var flowContext = this.context.flow;\nif(flowContext.isSitting==null){\n flowContext.isSitting=0;\n}\nvar angles =msg.payload.angle;\nif( flowContext.isSitting==1){\n var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\n msg.payload = {date:date ,timestamp:date.getTime(), posX:msg.payload.pos_x, posY:msg.payload.pos_y, fake:\"0\"};\n}\nelse{\n msg.payload=null;\n}\n\nreturn msg;return msg;","outputs":1,"noerr":0,"x":390,"y":180,"wires":[["23b75a55.df6646"]]},{"id":"51301068.f29e4","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"var flowContext = this.context.flow;\nflowContext.isSitting=msg.payload.IsSomeoneThere;\n\n var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\n msg.payload = {date:date ,timestamp:date.getTime(), isSitting:msg.payload.IsSomeoneThere};\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":300,"wires":[["eda9ac1f.df1a1"]]},{"id":"f48b2a1f.dced18","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"var flowContext = this.context.flow;\nif(flowContext.isSitting==null){\n flowContext.isSitting=0;\n}\nif( flowContext.isSitting==1){\n var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\n msg.payload = {date:date ,timestamp:date.getTime(), isMoving:msg.payload.isMoving, isSitting:1};\n}\nelse{\n msg.payload=null;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":420,"wires":[["7e30b952.5c6758"]]},{"id":"334fcbeb.acd7d4","type":"http in","z":"79c89fe4.873e6","name":"getMonthWithData","url":"/monthsWithData","method":"get","upload":false,"swaggerDoc":"","x":150,"y":280,"wires":[["10b52e7e.2bc7c2"]]},{"id":"32438d51.b44d62","type":"http in","z":"79c89fe4.873e6","name":"getOneDay","url":"oneDay","method":"get","upload":false,"swaggerDoc":"","x":130,"y":400,"wires":[["6b826591.36243c"]]},{"id":"3da51abc.07fb96","type":"http response","z":"79c89fe4.873e6","name":"","statusCode":"","headers":{},"x":1230,"y":340,"wires":[]},{"id":"ca539df1.75ecd","type":"http in","z":"79c89fe4.873e6","name":"getOneMonth","url":"oneMonth","method":"get","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["33bd490c.876dc6"]]},{"id":"4f683f01.f5d7b","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Config","operation":"update","x":760,"y":240,"wires":[["cde0e0b7.51abe"]]},{"id":"a43529ef.0b78e8","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/recommandation","method":"post","upload":false,"swaggerDoc":"","x":160,"y":120,"wires":[["7175b2c6.867acc"]]},{"id":"a4c9917.ff2247","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload =[{Value:\"Recommandation\"},{$set:msg.req.body}];\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":120,"wires":[["4f683f01.f5d7b","bfc51cf3.e973d","bc4ffd47.e98ef","90ec26da.c27468"]]},{"id":"b7688e63.a3feb","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/recommandation","method":"get","upload":false,"swaggerDoc":"","x":160,"y":320,"wires":[["b2976bf.98f7398"]]},{"id":"2467611c.c8d24e","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find one","collection":"Config","operation":"findOne","x":680,"y":320,"wires":[["cde0e0b7.51abe"]]},{"id":"84788a39.0cd168","type":"function","z":"b9daa40a.159ce8","name":"","func":"var request = [{\"Value\":\"Recommandation\"},msg.payload];\nmsg.payload= request;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":320,"wires":[["2467611c.c8d24e"]]},{"id":"6746226d.b4a8bc","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Config","operation":"update","x":720,"y":380,"wires":[["cde0e0b7.51abe"]]},{"id":"78242cb6.902cc4","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/configuration","method":"post","upload":false,"swaggerDoc":"","x":150,"y":380,"wires":[["4e6cdb3b.56f734"]]},{"id":"ae2b8f3e.6f948","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload =[{Value:\"Configuration\"},{$set:msg.req.body}];\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":380,"wires":[["6746226d.b4a8bc"]]},{"id":"f174eb43.da87c8","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/configuration","method":"get","upload":false,"swaggerDoc":"","x":150,"y":440,"wires":[["731097f.979cb68"]]},{"id":"3b0d1f38.77ada","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find one","collection":"Config","operation":"findOne","x":680,"y":440,"wires":[["cde0e0b7.51abe"]]},{"id":"a68c4468.5fdad8","type":"function","z":"b9daa40a.159ce8","name":"","func":"var request = [{\"Value\":\"Configuration\"},msg.payload];\nmsg.payload= request;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":440,"wires":[["3b0d1f38.77ada"]]},{"id":"d312ac17.d8c2b","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Current_State","operation":"update","x":1240,"y":320,"wires":[[]]},{"id":"26cb4eca.2d7212","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"isSitting\":msg.payload.IsSomeoneThere}},{ upsert: true }];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":360,"wires":[["d312ac17.d8c2b"]]},{"id":"12901cff.5ea7e3","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"isMoving\":msg.payload.isMoving}}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":480,"wires":[["d312ac17.d8c2b"]]},{"id":"5a9da3b1.d44cfc","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"currentPosX\":msg.payload.pos_x, \"currentPosY\":msg.payload.pos_y}}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":220,"wires":[["d312ac17.d8c2b"]]},{"id":"d7a5edc4.a355e","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"currentAngle\":msg.payload.angle}},{ upsert: true }];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":120,"wires":[["d312ac17.d8c2b"]]},{"id":"a2119568.f267a8","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"back_angle","operation":"insert","x":880,"y":80,"wires":[[]]},{"id":"d710158.344d1e8","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":300,"wires":[["26cb4eca.2d7212","ada903e8.cfb9e","a364a037.f5813"]]},{"id":"d353cbdb.5d4f58","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":120,"wires":[["d7a5edc4.a355e","725194f8.7f551c"]]},{"id":"1c01fe0f.4afed2","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":220,"wires":[["5a9da3b1.d44cfc","6c4c2373.39613c"]]},{"id":"195ec0a8.18333f","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":480,"wires":[["f48b2a1f.dced18","12901cff.5ea7e3"]]},{"id":"14d35acb.066145","type":"switch","z":"ed0c995d.e2e7f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":80,"wires":[["a2119568.f267a8"]]},{"id":"eda9ac1f.df1a1","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"sitting_time","operation":"insert","x":800,"y":300,"wires":[[]]},{"id":"128731b6.446e4e","type":"http in","z":"c6f5a9d0.2bf118","name":"","url":"/simulate","method":"post","upload":false,"swaggerDoc":"","x":300,"y":300,"wires":[["176575a7.f0811a","92a4d674.266a18"]]},{"id":"bbb4df43.97676","type":"http response","z":"c6f5a9d0.2bf118","name":"","statusCode":"","headers":{},"x":940,"y":200,"wires":[]},{"id":"bd8218c8.55a0f8","type":"http in","z":"79c89fe4.873e6","name":"","url":"/sittingTime","method":"get","upload":false,"swaggerDoc":"","x":140,"y":540,"wires":[["1bcf1c7a.a04914"]]},{"id":"92a4d674.266a18","type":"function","z":"c6f5a9d0.2bf118","name":"creation test","func":"var times = 0;\nvar timeStamps = 1517439600000;\nvar angles =0 ;\nvar docs=[];\nvar k =0;\nfor(j=0;j<62;j++){\n for(i=0;i<300;i++){\n var date = new Date(timeStamps);\n\n var document = {date:date ,timestamp:timeStamps, isSitting:angles};\n\n docs[k] =document;\n \n timeStamps +=288000;\n angles = Math.round(Math.random()*1);\n k++;\n }\n timeStamps +=288000;\n angles = Math.round(Math.random()*1);\n}\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":380,"wires":[["729ba250.f752ec"]]},{"id":"729ba250.f752ec","type":"mongodb2 in","z":"c6f5a9d0.2bf118","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"sitting_time","operation":"insertMany","x":760,"y":440,"wires":[[]]},{"id":"6bad49a4.0bd018","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":1517484102,\"angle\":35}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["c3b9ff8c.8355c"]]},{"id":"c3b9ff8c.8355c","type":"mqtt out","z":"da4609d5.3036c8","name":"angle","topic":"data/current_back_rest_angle","qos":"","retain":"","broker":"2b8661c7.194ede","x":330,"y":60,"wires":[]},{"id":"7803a8bb.c23928","type":"mqtt out","z":"da4609d5.3036c8","name":"sitt","topic":"data/current_is_someone_there","qos":"","retain":"","broker":"2b8661c7.194ede","x":330,"y":140,"wires":[]},{"id":"c81137a9.218838","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-02-04:23:00:00\",\"IsSomeoneThere\":0}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":120,"wires":[["7803a8bb.c23928"]]},{"id":"dc3b7f24.e70ef","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-02-04:23:00:00\",\"IsSomeoneThere\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["7803a8bb.c23928"]]},{"id":"cd524360.4301b","type":"function","z":"da4609d5.3036c8","name":"creation test angle","func":"\nvar docs=[\n{date:new Date(\"2018-02-01T08:00:00.000Z\"), timestamp:\"1517439600000\",angle:35,isSitting:1},\n{date:new Date(\"2018-02-01T12:00:00.000Z\"), timestamp:\"1517439600000\",angle:12,isSitting:1},\n{date:new Date(\"2018-02-01T12:30:00.000Z\"), timestamp:\"1517439600000\",angle:20,isSitting:1},\n{date:new Date(\"2018-02-01T16:00:00.000Z\"), timestamp:\"1517439600000\",angle:35,isSitting:1},\n{date:new Date(\"2018-02-01T20:00:00.000Z\"), timestamp:\"1517439600000\",angle:46,isSitting:1},\n{date:new Date(\"2018-02-01T23:00:00.000Z\"), timestamp:\"1517439600000\",angle:46,isSitting:0},\n{date:new Date(\"2018-02-02T10:00:00.000Z\"), timestamp:\"1517439600000\",angle:15,isSitting:1},\n{date:new Date(\"2018-02-02T18:00:00.000Z\"), timestamp:\"1517439600000\",angle:15,isSitting:0},\n{date:new Date(\"2018-02-04T09:00:00.000Z\"), timestamp:\"1517439600000\",angle:35,isSitting:1},\n{date:new Date(\"2018-02-04T12:00:00.000Z\"), timestamp:\"1517439600000\",angle:12,isSitting:1},\n{date:new Date(\"2018-02-04T12:30:00.000Z\"), timestamp:\"1517439600000\",angle:35,isSitting:1},\n{date:new Date(\"2018-02-04T23:00:00.000Z\"), timestamp:\"1517439600000\",angle:35,isSitting:0}\n];\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":300,"wires":[["4376acd7.2d9024"]]},{"id":"4376acd7.2d9024","type":"mongodb2 in","z":"da4609d5.3036c8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"back_angle","operation":"insertMany","x":460,"y":300,"wires":[[]]},{"id":"c52426ed.6c2d08","type":"function","z":"da4609d5.3036c8","name":"creation test sitting","func":"var docs=[\n{date:new Date(\"2018-02-01T08:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:1},\n{date:new Date(\"2018-02-01T23:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:0},\n{date:new Date(\"2018-02-02T10:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:1},\n{date:new Date(\"2018-02-02T18:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:0},\n{date:new Date(\"2018-02-04T09:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:1},\n{date:new Date(\"2018-02-04T23:00:00.000Z\"), timestamp:\"1517439600000\",isSitting:0}\n];\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":500,"wires":[["d4c89718.1e4bd8"]]},{"id":"d4c89718.1e4bd8","type":"mongodb2 in","z":"da4609d5.3036c8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"sitting_time","operation":"insertMany","x":460,"y":500,"wires":[[]]},{"id":"dd1eeedc.1048f","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-03-11:13:01:02\",\"IsSomeoneThere\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":300,"wires":[["cd524360.4301b"]]},{"id":"e720d2bb.dc388","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"LastTime","collection":"back_angle","operation":"aggregate.toArray","x":800,"y":260,"wires":[["607e252.184dddc"]]},{"id":"ce696998.b38988","type":"function","z":"ed0c995d.e2e7f8","name":"","func":" var flowContext = this.context.flow;\nflowContext.isSitting=msg.payload.IsSomeoneThere;\n var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\nmsg.back = {date:date ,timestamp:date.getTime(), isSitting:msg.payload.IsSomeoneThere};\n msg.payload =[[\n {\n \"$sort\":{date: 1}\n },\n {\n \"$group\":{\n \"_id\":null,\n // \"date\":{$last:\"$date\"},\n \"angle\":{$last:\"$angle\"}\n }\n }\n ]];\n\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":260,"wires":[["e720d2bb.dc388"]]},{"id":"607e252.184dddc","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload={\n angle:msg.payload[0].angle, date:msg.back.date,timestamp:parseInt(msg.back.timestamp),sitting:msg.back.isSitting\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":970,"y":260,"wires":[["a663d635.c9a558"]]},{"id":"ada903e8.cfb9e","type":"switch","z":"ed0c995d.e2e7f8","name":"sitting=0","property":"payload.IsSomeoneThere","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":260,"wires":[["ce696998.b38988"]]},{"id":"a663d635.c9a558","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"back_angle","operation":"insert","x":1140,"y":260,"wires":[[]]},{"id":"68930c4.adc52f4","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-03-11:13:01:02\",\"IsSomeoneThere\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":500,"wires":[["c52426ed.6c2d08"]]},{"id":"922360f7.46ec","type":"json","z":"4e4dbcc2.17d054","name":"","property":"payload","action":"obj","pretty":false,"x":430,"y":320,"wires":[["445de54c.95801c"]]},{"id":"16daffa2.467b7","type":"mongodb2 in","z":"4e4dbcc2.17d054","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find one","collection":"User","operation":"findOne","x":760,"y":340,"wires":[["b0d913b4.e7c34"]]},{"id":"b0d913b4.e7c34","type":"switch","z":"4e4dbcc2.17d054","name":"result","property":"payload","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":340,"wires":[["50caa40d.80abec"],["db0ceff6.603c"]]},{"id":"445de54c.95801c","type":"function","z":"4e4dbcc2.17d054","name":"","func":"msg.payload = {token:msg.payload.authorization};\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":340,"wires":[["16daffa2.467b7"]]},{"id":"aba7736e.afb03","type":"http response","z":"4e4dbcc2.17d054","name":"","statusCode":"","headers":{},"x":1290,"y":340,"wires":[]},{"id":"e29f42ca.a113c","type":"function","z":"4e4dbcc2.17d054","name":"get body","func":"msg.backup=msg.payload ;\nmsg.payload = msg.req.headers;\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":320,"wires":[["922360f7.46ec"]]},{"id":"db0ceff6.603c","type":"function","z":"4e4dbcc2.17d054","name":"get body","func":"msg.payload=msg.backup ;\nreturn msg;","outputs":1,"noerr":0,"x":1080,"y":300,"wires":[[]]},{"id":"93bd1535.1e8c98","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":200,"wires":[["2465d36d.b4433c"]]},{"id":"10b52e7e.2bc7c2","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":280,"wires":[["4d07edfe.46c584"]]},{"id":"6b826591.36243c","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":400,"wires":[["65edf301.deb70c"]]},{"id":"33bd490c.876dc6","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":460,"wires":[["b5de3bd6.ecc668"]]},{"id":"1bcf1c7a.a04914","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":540,"wires":[["cb186131.b222"]]},{"id":"fca36f1b.c400a","type":"mqtt out","z":"1dab1279.d003ee","name":"","topic":"data/set_alarm","qos":"","retain":"","broker":"2b8661c7.194ede","x":840,"y":180,"wires":[]},{"id":"a8fe4166.90a7b","type":"function","z":"1dab1279.d003ee","name":"","func":"msg.payload= msg.payload.State ===\"on\" ? 1 :0;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":180,"wires":[["fca36f1b.c400a"]]},{"id":"90869b6d.636e88","type":"http in","z":"1dab1279.d003ee","name":"","url":"/alert","method":"get","upload":false,"swaggerDoc":"","x":220,"y":180,"wires":[["55cf64d2.e7931c"]]},{"id":"4c76740e.843a4c","type":"mqtt out","z":"1dab1279.d003ee","name":"","topic":"config/calib_pressure_mat","qos":"","retain":"","broker":"2b8661c7.194ede","x":870,"y":260,"wires":[]},{"id":"68b6df65.8696d","type":"http in","z":"1dab1279.d003ee","name":"","url":"/calibrate","method":"get","upload":false,"swaggerDoc":"","x":230,"y":260,"wires":[["7a6176f3.bdbe58"]]},{"id":"4db2b363.77881c","type":"function","z":"1dab1279.d003ee","name":"","func":"msg.payload= 1\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":260,"wires":[["4c76740e.843a4c"]]},{"id":"55cf64d2.e7931c","type":"subflow:4e4dbcc2.17d054","z":"1dab1279.d003ee","x":430,"y":180,"wires":[["a8fe4166.90a7b","7e115d8f.58b764"]]},{"id":"7a6176f3.bdbe58","type":"subflow:4e4dbcc2.17d054","z":"1dab1279.d003ee","x":430,"y":260,"wires":[["4db2b363.77881c","17359388.23940c"]]},{"id":"d3adfe9c.210ea","type":"http response","z":"1dab1279.d003ee","name":"","statusCode":"","headers":{},"x":810,"y":320,"wires":[]},{"id":"17359388.23940c","type":"template","z":"1dab1279.d003ee","name":"return erreur ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"result\":\"ok\"}","output":"str","x":630,"y":320,"wires":[["d3adfe9c.210ea"]]},{"id":"7e115d8f.58b764","type":"template","z":"1dab1279.d003ee","name":"return erreur ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"result\":\"ok\"}","output":"str","x":650,"y":140,"wires":[["37358c65.cbeb74"]]},{"id":"37358c65.cbeb74","type":"http response","z":"1dab1279.d003ee","name":"","statusCode":"","headers":{},"x":810,"y":140,"wires":[]},{"id":"23b75a55.df6646","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"gravity_Center","operation":"insert","x":680,"y":180,"wires":[[]]},{"id":"c4236f86.ae4f2","type":"mqtt out","z":"1dab1279.d003ee","name":"","topic":"config/calib_imu","qos":"","retain":"","broker":"2b8661c7.194ede","x":840,"y":400,"wires":[]},{"id":"e468a5e2.16d5f8","type":"http in","z":"79c89fe4.873e6","name":"","url":"/gravityCenter","method":"get","upload":false,"swaggerDoc":"","x":150,"y":620,"wires":[["acab6567.a37208"]]},{"id":"acab6567.a37208","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":620,"wires":[["45ba2c72.373494"]]},{"id":"a4d60f98.27b73","type":"function","z":"da4609d5.3036c8","name":"creation test centre pression","func":"\nvar docs=[\n{date:new Date(\"2018-02-01T08:00:00.000Z\"), timestamp:\"1517439600000\",posX:0, posY:0},\n{date:new Date(\"2018-02-01T12:00:00.000Z\"), timestamp:\"1517439600000\",posX:-1.2, posY:-5.2},\n{date:new Date(\"2018-02-01T12:30:00.000Z\"), timestamp:\"1517439600000\",posX:-3.3, posY:-4.3},\n{date:new Date(\"2018-02-01T16:00:00.000Z\"), timestamp:\"1517439600000\",posX:2.4, posY:-3.0},\n{date:new Date(\"2018-02-01T20:00:00.000Z\"), timestamp:\"1517439600000\",posX:4.1, posY:2.3},\n{date:new Date(\"2018-02-01T23:00:00.000Z\"), timestamp:\"1517439600000\",posX:1.7, posY:1.1},\n{date:new Date(\"2018-02-02T10:00:00.000Z\"), timestamp:\"1517439600000\",posX:-3.8, posY:6.5},\n{date:new Date(\"2018-02-02T18:00:00.000Z\"), timestamp:\"1517439600000\",posX:2.5, posY:3.6},\n{date:new Date(\"2018-02-04T09:00:00.000Z\"), timestamp:\"1517439600000\",posX:3.1, posY:0.6},\n{date:new Date(\"2018-02-04T12:00:00.000Z\"), timestamp:\"1517439600000\",posX:1.6, posY:-3.5},\n{date:new Date(\"2018-02-04T12:30:00.000Z\"), timestamp:\"1517439600000\",posX:0.3, posY:-5.1},\n{date:new Date(\"2018-02-04T23:00:00.000Z\"), timestamp:\"1517439600000\",posX:-0.4, posY:1}\n]\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":580,"wires":[["19a47f60.544fc1"]]},{"id":"19a47f60.544fc1","type":"mongodb2 in","z":"da4609d5.3036c8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"gravity_Center","operation":"insertMany","x":540,"y":580,"wires":[[]]},{"id":"acae8973.72fab8","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-03-11:13:01:02\",\"IsSomeoneThere\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":580,"wires":[["a4d60f98.27b73"]]},{"id":"d58ab2a6.9d44e","type":"http in","z":"62e9dd9c.3ec8b4","name":"","url":"/changePassword","method":"post","upload":false,"swaggerDoc":"","x":120,"y":280,"wires":[["2837a1dc.2d708e"]]},{"id":"2837a1dc.2d708e","type":"function","z":"62e9dd9c.3ec8b4","name":"get Username","func":"msg.payload= '{\"username\":\"'+msg.req.body.username+'\"}';\nvar crypto = context.global.cryptojs;\nmsg.pw = crypto.SHA256( msg.req.body.password).toString();\nmsg.newPassword = crypto.SHA256( msg.req.body.newPassword).toString();\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":280,"wires":[["9ea82417.491cb8"]]},{"id":"9e80e969.bc5eb8","type":"mongodb2 in","z":"62e9dd9c.3ec8b4","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find user","collection":"User","operation":"findOne","x":660,"y":280,"wires":[["5c9515bf.c1de6c"]]},{"id":"9ea82417.491cb8","type":"json","z":"62e9dd9c.3ec8b4","name":"","property":"payload","action":"obj","pretty":false,"x":530,"y":280,"wires":[["9e80e969.bc5eb8"]]},{"id":"5c9515bf.c1de6c","type":"function","z":"62e9dd9c.3ec8b4","name":"validate Password","func":"if(msg.payload.password == msg.pw){\n msg.payload =[{username:msg.payload.username},{$set:{\"password\":msg.newPassword}}];\n msg.result = '{\"result\":\"0\"}';\n}\nelse\n msg.result = '{\"result\":401}';\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":280,"wires":[["1ee344bd.f16f0b"]]},{"id":"1ee344bd.f16f0b","type":"json","z":"62e9dd9c.3ec8b4","name":"","property":"result","action":"obj","pretty":false,"x":1010,"y":280,"wires":[["88f93e56.526c5"]]},{"id":"88f93e56.526c5","type":"switch","z":"62e9dd9c.3ec8b4","name":"","property":"result.result","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"neq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1150,"y":280,"wires":[["d56ef679.fb5018"],["1ac988a8.1b48e7"]]},{"id":"d56ef679.fb5018","type":"mongodb2 in","z":"62e9dd9c.3ec8b4","service":"_ext_","configNode":"c2e023a5.ad0b","name":"change password","collection":"User","operation":"update","x":1290,"y":220,"wires":[["1ac988a8.1b48e7"]]},{"id":"bd8c13e2.e69f6","type":"http response","z":"62e9dd9c.3ec8b4","name":"","statusCode":"","headers":{},"x":1490,"y":280,"wires":[]},{"id":"1ac988a8.1b48e7","type":"function","z":"62e9dd9c.3ec8b4","name":"send result","func":"msg.payload = msg.result;\nreturn msg;","outputs":1,"noerr":0,"x":1330,"y":280,"wires":[["bd8c13e2.e69f6"]]},{"id":"f2bfa75e.b30838","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"config response","topic":"config/calibration_response","qos":"0","broker":"2b8661c7.194ede","x":100,"y":560,"wires":[["5e6bf631.0b5378"]]},{"id":"f527aeb6.769e2","type":"http in","z":"1dab1279.d003ee","name":"","url":"/calibrateIMU","method":"get","upload":false,"swaggerDoc":"","x":250,"y":400,"wires":[["7acd0e4b.bda97"]]},{"id":"4418021e.cc065c","type":"function","z":"1dab1279.d003ee","name":"","func":"msg.payload= 1\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":400,"wires":[["c4236f86.ae4f2"]]},{"id":"7acd0e4b.bda97","type":"subflow:4e4dbcc2.17d054","z":"1dab1279.d003ee","x":430,"y":400,"wires":[["4418021e.cc065c","d7c8408e.974c7"]]},{"id":"d7c8408e.974c7","type":"template","z":"1dab1279.d003ee","name":"return erreur ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"result\":\"ok\"}","output":"str","x":630,"y":460,"wires":[["d9f03d00.c36cf"]]},{"id":"d9f03d00.c36cf","type":"http response","z":"1dab1279.d003ee","name":"","statusCode":"","headers":{},"x":810,"y":460,"wires":[]},{"id":"d4b4059c.39ef68","type":"http in","z":"da4609d5.3036c8","name":"","url":"/testBackEnd","method":"get","upload":false,"swaggerDoc":"","x":150,"y":360,"wires":[["62ea1e9e.647d8","d72b3f20.3cc26"]]},{"id":"3ac333ac.96148c","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"7200000\":{\"x\":-1.2,\"y\":-5.2},\"9000000\":{\"x\":-3.3,\"y\":-4.3},\"21600000\":{\"x\":2.4,\"y\":-3},\"36000000\":{\"x\":4.1,\"y\":2.3},\"46800000\":{\"x\":1.7,\"y\":1.1}};\nif(JSON.stringify(msg.payload)===JSON.stringify(expected)){\n msg.payload= {result:0,message:'Gravity Center -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Gravity Center -10: \\nValeur attendu: '+JSON.stringify(expected)+' \\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;\n","outputs":1,"noerr":0,"x":1290,"y":480,"wires":[["1cac304e.5eec9"]]},{"id":"d2fbd461.d36b08","type":"http response","z":"da4609d5.3036c8","name":"","statusCode":"","headers":{},"x":1830,"y":360,"wires":[]},{"id":"8ae3a664.809648","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"28800000\":{\"x\":0,\"y\":0},\"43200000\":{\"x\":-1.2,\"y\":-5.2},\"45000000\":{\"x\":-3.3,\"y\":-4.3},\"57600000\":{\"x\":2.4,\"y\":-3},\"72000000\":{\"x\":4.1,\"y\":2.3},\"82800000\":{\"x\":1.7,\"y\":1.1}};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Gravity Center 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Gravity Center 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":180,"wires":[["1cac304e.5eec9"]]},{"id":"1cac304e.5eec9","type":"join","z":"da4609d5.3036c8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"14","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1550,"y":360,"wires":[["98039178.c317c"]]},{"id":"98039178.c317c","type":"sort","z":"da4609d5.3036c8","name":"","order":"descending","as_num":true,"target":"payload","targetType":"msg","msgKey":"result","msgKeyType":"jsonata","seqKey":"payload","seqKeyType":"msg","x":1690,"y":360,"wires":[["d2fbd461.d36b08"]]},{"id":"e70f4e44.d8da7","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":780,\"2\":480,\"3\":60,\"4\":780,\"5\":0,\"6\":0,\"7\":0,\"8\":0,\"9\":0,\"10\":0,\"11\":0,\"12\":0,\"13\":0,\"14\":0,\"15\":0,\"16\":0,\"17\":0,\"18\":0,\"19\":0,\"20\":0,\"21\":0,\"22\":0,\"23\":0,\"24\":0,\"25\":0,\"26\":0,\"27\":0,\"28\":0,\"29\":0,\"30\":0};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Sitting time -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message: 'Sitting time -10: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":440,"wires":[["1cac304e.5eec9"]]},{"id":"19857de6.7b4462","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":900,\"2\":480,\"3\":0,\"4\":840,\"5\":0,\"6\":0,\"7\":0,\"8\":0,\"9\":0,\"10\":0,\"11\":0,\"12\":0,\"13\":0,\"14\":0,\"15\":0,\"16\":0,\"17\":0,\"18\":0,\"19\":0,\"20\":0,\"21\":0,\"22\":0,\"23\":0,\"24\":0,\"25\":0,\"26\":0,\"27\":0,\"28\":0,\"29\":0,\"30\":0};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Sitting time 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Sitting time 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":140,"wires":[["1cac304e.5eec9"]]},{"id":"d2e09292.64e08","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"2018\":[2]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Month with data time 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Month with data 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":340,"wires":[["1cac304e.5eec9"]]},{"id":"7a928942.66a808","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"2018\":[2,1]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Month with data -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Month with data -10: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":640,"wires":[["1cac304e.5eec9"]]},{"id":"4a2bc940.d459d8","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"2018\":{\"1\":[31],\"2\":[4,3,2,1]}};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Day with data -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Day with data -10: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":600,"wires":[["1cac304e.5eec9"]]},{"id":"3839e354.b00c1c","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"2018\":{\"2\":[4,2,1]}};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Day with data 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Day with data 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":300,"wires":[["1cac304e.5eec9"]]},{"id":"cde0e0b7.51abe","type":"http response","z":"b9daa40a.159ce8","name":"","statusCode":"","headers":{},"x":1170,"y":380,"wires":[]},{"id":"21ca71e5.fbb5fe","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/goal","method":"get","upload":false,"swaggerDoc":"","x":120,"y":500,"wires":[["380d1904.c4e1d6"]]},{"id":"fd58072b.243318","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find one","collection":"Config","operation":"findOne","x":680,"y":500,"wires":[["cde0e0b7.51abe"]]},{"id":"e995576.05dbaa8","type":"function","z":"b9daa40a.159ce8","name":"","func":"var request = [{\"Value\":\"Goal\"},msg.payload];\nmsg.payload= request;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":500,"wires":[["fd58072b.243318"]]},{"id":"c4e4138e.9e1be","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":[0,1800000,12600000,14400000,10800000],\"2\":[0,0,28800000,0,0],\"3\":[0,0,0,3599999,0],\"4\":[0,1800000,0,37800000,0],\"5\":[],\"6\":[],\"7\":[],\"8\":[],\"9\":[],\"10\":[],\"11\":[],\"12\":[],\"13\":[],\"14\":[],\"15\":[],\"16\":[],\"17\":[],\"18\":[],\"19\":[],\"20\":[],\"21\":[],\"22\":[],\"23\":[],\"24\":[],\"25\":[],\"26\":[],\"27\":[],\"28\":[]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'one month -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message: 'one Month -10: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":400,"wires":[["1cac304e.5eec9"]]},{"id":"f4ee485f.c665c8","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":[0,1800000,12600000,28800000,10800000],\"2\":[0,0,28800000,0,0],\"3\":[],\"4\":[0,1800000,0,48600000,0],\"5\":[],\"6\":[],\"7\":[],\"8\":[],\"9\":[],\"10\":[],\"11\":[],\"12\":[],\"13\":[],\"14\":[],\"15\":[],\"16\":[],\"17\":[],\"18\":[],\"19\":[],\"20\":[],\"21\":[],\"22\":[],\"23\":[],\"24\":[],\"25\":[],\"26\":[],\"27\":[],\"28\":[]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'one month 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'one month 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":100,"wires":[["1cac304e.5eec9"]]},{"id":"7445ce75.719e8","type":"http in","z":"79c89fe4.873e6","name":"lastDate","url":"/lastDate","method":"get","upload":false,"swaggerDoc":"","x":120,"y":120,"wires":[["1ab23a65.f2c4c6"]]},{"id":"1ab23a65.f2c4c6","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":120,"wires":[["370a31ba.e85e9e","29e49b13.4a6054"]]},{"id":"2b4014f9.e62f9c","type":"http in","z":"b9daa40a.159ce8","name":"","url":"/goal","method":"post","upload":false,"swaggerDoc":"","x":120,"y":180,"wires":[["19092c9d.73cff3"]]},{"id":"c2165ebd.f4e88","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload =[{Value:\"Goal\"},{$set:msg.req.body}];\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":180,"wires":[["62d22b6c.9fe194","bfc51cf3.e973d","bc4ffd47.e98ef","90ec26da.c27468"]]},{"id":"62d22b6c.9fe194","type":"mongodb2 in","z":"b9daa40a.159ce8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Config","operation":"update","x":760,"y":280,"wires":[["cde0e0b7.51abe"]]},{"id":"bfc51cf3.e973d","type":"switch","z":"b9daa40a.159ce8","name":"","property":"req.body.reduceWeight.tiltLength","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":100,"wires":[["93182639.f79078"]]},{"id":"bc4ffd47.e98ef","type":"switch","z":"b9daa40a.159ce8","name":"","property":"req.body.reduceWeight.tiltFrequecy","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":140,"wires":[["a8656620.abd478"]]},{"id":"90ec26da.c27468","type":"switch","z":"b9daa40a.159ce8","name":"","property":"req.body.reduceWeight.tiltAngle","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":180,"wires":[["cb4cd9c8.e54b98"]]},{"id":"cb4cd9c8.e54b98","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload=msg.req.body.reduceWeight.tiltAngle;\nreturn msg;","outputs":1,"noerr":0,"x":1050,"y":180,"wires":[["7a4cfa59.f0ec44"]]},{"id":"a8656620.abd478","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload=msg.req.body.reduceWeight.tiltFrequecy;\nreturn msg;","outputs":1,"noerr":0,"x":1050,"y":140,"wires":[["1520ac2f.896894"]]},{"id":"93182639.f79078","type":"function","z":"b9daa40a.159ce8","name":"","func":"msg.payload=msg.req.body.reduceWeight.tiltLength;\nreturn msg;","outputs":1,"noerr":0,"x":1043,"y":100,"wires":[["3b96d32b.1a480c"]]},{"id":"3b96d32b.1a480c","type":"mqtt out","z":"b9daa40a.159ce8","name":"","topic":"data/required_duration","qos":"","retain":"","broker":"2b8661c7.194ede","x":1320,"y":100,"wires":[]},{"id":"1520ac2f.896894","type":"mqtt out","z":"b9daa40a.159ce8","name":"","topic":"data/required_period","qos":"","retain":"","broker":"2b8661c7.194ede","x":1320,"y":140,"wires":[]},{"id":"7a4cfa59.f0ec44","type":"mqtt out","z":"b9daa40a.159ce8","name":"","topic":"data/required_back_rest_angle","qos":"","retain":"","broker":"2b8661c7.194ede","x":1350,"y":180,"wires":[]},{"id":"1bbfa625.d3672a","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected=1517749200000;\nif(JSON.stringify(msg.payload)===JSON.stringify(expected)){\n msg.payload= {result:0,message:'last Date -10: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'last Date -10: \\nValeur attendu: '+JSON.stringify(expected)+' \\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;\n","outputs":1,"noerr":0,"x":1290,"y":560,"wires":[["1cac304e.5eec9"]]},{"id":"5c9aef57.edd67","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected=1517785200000;\nif(JSON.stringify(msg.payload)===JSON.stringify(expected)){\n msg.payload= {result:0,message:'last date 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'lastdate 0: \\nValeur attendu: '+JSON.stringify(expected)+' \\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;\n","outputs":1,"noerr":0,"x":1290,"y":260,"wires":[["1cac304e.5eec9"]]},{"id":"d02973b1.307ca","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"currentCalib\":msg.payload.calibState}}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":560,"wires":[["d312ac17.d8c2b"]]},{"id":"5e6bf631.0b5378","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":560,"wires":[["d02973b1.307ca"]]},{"id":"2fe9866.fd70c7a","type":"http in","z":"79c89fe4.873e6","name":"isCalibrating","url":"/isCalibrating","method":"get","upload":false,"swaggerDoc":"","x":130,"y":340,"wires":[["d691dbf2.6ec1e8"]]},{"id":"d691dbf2.6ec1e8","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":340,"wires":[["c78dfd15.05695"]]},{"id":"c78dfd15.05695","type":"function","z":"79c89fe4.873e6","name":"get month ","func":" msg.payload =[[{ \"$match\": { Value: \"CurrentState\" } },\n { \"$project\": { \n \"currentCalib\": \"$currentCalib\"\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":340,"wires":[["d80d7d9b.e24bd"]]},{"id":"d80d7d9b.e24bd","type":"mongodb2 in","z":"79c89fe4.873e6","service":"_ext_","configNode":"c2e023a5.ad0b","name":"getCalibState","collection":"Current_State","operation":"aggregate.toArray","x":720,"y":340,"wires":[["2aa866ce.a6e74a"]]},{"id":"2aa866ce.a6e74a","type":"function","z":"79c89fe4.873e6","name":"format result","func":"msg.payload = {result:msg.payload[0].currentCalib};\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":340,"wires":[["3da51abc.07fb96"]]},{"id":"ac97c3c0.f2bd2","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"","topic":"data/keep_alive","qos":"0","broker":"2b8661c7.194ede","x":100,"y":700,"wires":[["d12cc21f.4a64f"]]},{"id":"50caa40d.80abec","type":"function","z":"4e4dbcc2.17d054","name":"","func":" msg.statusCode = 401\n\nreturn msg;","outputs":1,"noerr":0,"x":1090,"y":360,"wires":[["aba7736e.afb03"]]},{"id":"89a5da6.88b7a28","type":"http in","z":"1dab1279.d003ee","name":"","url":"/SelectWifi","method":"post","upload":false,"swaggerDoc":"","x":240,"y":540,"wires":[["518e2ad0.0e5764"]]},{"id":"f7ef3d11.bd494","type":"function","z":"1dab1279.d003ee","name":"","func":"msg.payload =msg.req.body.ssid +\";\"+msg.req.body.psk;\nreturn msg;\n","outputs":1,"noerr":0,"x":610,"y":540,"wires":[["a5856f74.a34ee","c1a557ed.fb9858"]]},{"id":"c1a557ed.fb9858","type":"mqtt out","z":"1dab1279.d003ee","name":"","topic":"config/wifi","qos":"","retain":"","broker":"2b8661c7.194ede","x":820,"y":540,"wires":[]},{"id":"a5856f74.a34ee","type":"debug","z":"1dab1279.d003ee","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":740,"y":600,"wires":[]},{"id":"d12cc21f.4a64f","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":700,"wires":[["c7b9b484.9a2c98"]]},{"id":"baf28c9e.7239c","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"keepAlive\":msg.payload}}];\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":700,"wires":[["d312ac17.d8c2b"]]},{"id":"402e62db.9318dc","type":"json","z":"335e86e1.c431da","name":"","property":"payload","action":"obj","pretty":false,"x":170,"y":140,"wires":[["d2a339de.094b78"]]},{"id":"d2a339de.094b78","type":"function","z":"335e86e1.c431da","name":"","func":" msg.backup=msg.payload;\n\n msg.payload =[[{ \"$match\": { Value: \"CurrentState\" } },\n { \"$project\": { \n \"keepAlive\": \"$keepAlive\"\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":140,"wires":[["bb89477c.b47ab8"]]},{"id":"bb89477c.b47ab8","type":"mongodb2 in","z":"335e86e1.c431da","service":"_ext_","configNode":"c2e023a5.ad0b","name":"getKeepAlive","collection":"Current_State","operation":"aggregate.toArray","x":470,"y":140,"wires":[["2ab055df.86637a"]]},{"id":"2ab055df.86637a","type":"function","z":"335e86e1.c431da","name":"get body","func":"msg.keepAlive =msg.payload[0].keepAlive;\n\nif((msg.backup.datetime - msg.keepAlive) > 900)\n msg.result =0;\nelse\n msg.result=1;\nmsg.payload =msg.backup;\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":140,"wires":[["1bef11f.97294ee"]]},{"id":"1bef11f.97294ee","type":"switch","z":"335e86e1.c431da","name":"","property":"result","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":140,"wires":[["4618534d.db9b9c"],["54e3eb5e.a5e6a4"]]},{"id":"1c8dfbb9.335e14","type":"mongodb2 in","z":"335e86e1.c431da","service":"_ext_","configNode":"c2e023a5.ad0b","name":"LastTime","collection":"back_angle","operation":"aggregate.toArray","x":400,"y":340,"wires":[["cbec3b20.10a8e8"]]},{"id":"cbec3b20.10a8e8","type":"function","z":"335e86e1.c431da","name":"","func":"//timestamp = msg.payload[0].date.getTime()+900000;\n//msg.payload={\n// angle:msg.payload[0].angle, date:new Date(timestamp),timestamp:parseInt(timestamp),sitting:0\n//}\n\nmsg.payload =[{date:msg.payload[0].date},{$set:{\"isSitting\":0}}];\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":340,"wires":[["338ef8ef.ab3eb8","ca2109b4.2d07a8"]]},{"id":"338ef8ef.ab3eb8","type":"mongodb2 in","z":"335e86e1.c431da","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"back_angle","operation":"update","x":740,"y":340,"wires":[["54e3eb5e.a5e6a4"]]},{"id":"4618534d.db9b9c","type":"function","z":"335e86e1.c431da","name":"","func":"var date = new Date(msg.payload.datetime*1000);\n date.setUTCMinutes(date.getMinutes()-date.getTimezoneOffset());\n msg.payload =[[\n {\n \"$sort\":{date: 1}\n },\n {\n \"$group\":{\n \"_id\":null,\n \"date\":{$last:\"$date\"},\n \"angle\":{$last:\"$angle\"}\n }\n }\n ]];\n\nreturn msg;","outputs":1,"noerr":0,"x":210,"y":340,"wires":[["1c8dfbb9.335e14"]]},{"id":"54e3eb5e.a5e6a4","type":"function","z":"335e86e1.c431da","name":"","func":"msg.payload = msg.backup;\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":260,"wires":[[]]},{"id":"725194f8.7f551c","type":"subflow:335e86e1.c431da","z":"ed0c995d.e2e7f8","name":"","x":430,"y":80,"wires":[["cefddfdf.eda88"]]},{"id":"ca2109b4.2d07a8","type":"mongodb2 in","z":"335e86e1.c431da","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"sitting_time","operation":"update","x":740,"y":400,"wires":[[]]},{"id":"ec7805e0.a34e58","type":"mqtt out","z":"da4609d5.3036c8","name":"","topic":"data/keep_alive","qos":"","retain":"","broker":"2b8661c7.194ede","x":800,"y":80,"wires":[]},{"id":"8b1839dc.afd8b8","type":"inject","z":"da4609d5.3036c8","name":"should change","topic":"","payload":"1517424102","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":600,"y":40,"wires":[["ec7805e0.a34e58"]]},{"id":"67b86a91.9b85c4","type":"inject","z":"da4609d5.3036c8","name":"no change","topic":"","payload":"1517484102","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":580,"y":100,"wires":[["ec7805e0.a34e58"]]},{"id":"61117a27.59df04","type":"inject","z":"da4609d5.3036c8","name":"test keepalive","topic":"","payload":"{\"datetime\":1517484102,\"angle\":35}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":590,"y":160,"wires":[["b3f833ed.80965"]]},{"id":"b3f833ed.80965","type":"mqtt out","z":"da4609d5.3036c8","name":"angle","topic":"data/current_back_rest_angle","qos":"","retain":"","broker":"2b8661c7.194ede","x":790,"y":160,"wires":[]},{"id":"a364a037.f5813","type":"subflow:335e86e1.c431da","z":"ed0c995d.e2e7f8","name":"","x":430,"y":300,"wires":[["51301068.f29e4"]]},{"id":"7962af2f.daf11","type":"function","z":"23a30f9a.261b6","name":"","func":" msg.backup=msg.payload;\n msg.payload =[[{ \"$match\": { Value: \"CurrentState\" } },\n { \"$project\": { \n \"keepAlive\": \"$keepAlive\",\n \"offSet\": \"$offSet\"\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":280,"wires":[["7b8c893.bbed078"]]},{"id":"7b8c893.bbed078","type":"mongodb2 in","z":"23a30f9a.261b6","service":"_ext_","configNode":"c2e023a5.ad0b","name":"getKeepAlive","collection":"Current_State","operation":"aggregate.toArray","x":310,"y":280,"wires":[["1aac1ec3.ef0981"]]},{"id":"d6c4abec.7af3d8","type":"link in","z":"23a30f9a.261b6","name":"get_Keep_Alive","links":["c7b9b484.9a2c98"],"x":40,"y":280,"wires":[["7962af2f.daf11"]]},{"id":"c7b9b484.9a2c98","type":"link out","z":"ed0c995d.e2e7f8","name":"receive_Keep_Alive","links":["d6c4abec.7af3d8"],"x":375,"y":700,"wires":[]},{"id":"1aac1ec3.ef0981","type":"function","z":"23a30f9a.261b6","name":"","func":"var offset = msg.payload[0].offSet;\nmsg.offset = parseInt(offset)*60*60*1000;\nvar last=new Date(parseInt(msg.payload[0].keepAlive*1000+msg.offset));\nvar current=new Date(parseInt(msg.backup*1000+msg.offset));\n\nmsg.last =msg.payload[0].keepAlive;\nif(current.getDate() > last.getDate())\n msg.result =1;\nelse \n msg.result =0;\nmsg.payload = {};\nmsg.payload.Day = msg.last*1000;\nmsg.payload.Offset = offset;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":280,"wires":[["4cd4f177.c58f5"]]},{"id":"c5154a0b.9dddf8","type":"mongodb2 in","z":"79c89fe4.873e6","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Current_State","operation":"update","x":960,"y":60,"wires":[[]]},{"id":"370a31ba.e85e9e","type":"function","z":"79c89fe4.873e6","name":"","func":"msg.payload =[{},{$set:{\"offSet\":msg.payload.Offset}}];\n\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":60,"wires":[["c5154a0b.9dddf8"]]},{"id":"4cd4f177.c58f5","type":"switch","z":"23a30f9a.261b6","name":"","property":"result","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":280,"wires":[["247b371d.8f7c68","7e1485c6.68876c","8dcd012d.f7da3","f00b63be.adfa5","1bc1f5f.8eda00a","5e99d393.df5d0c","6466ead6.8b8734"],["1bc1f5f.8eda00a"]]},{"id":"f3a88a6.490f578","type":"file","z":"23a30f9a.261b6","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","x":1210,"y":380,"wires":[]},{"id":"1bc1f5f.8eda00a","type":"function","z":"23a30f9a.261b6","name":"","func":"msg.payload = msg.backup;\nreturn msg;","outputs":1,"noerr":0,"x":1110,"y":260,"wires":[["caa9a252.3544d"]]},{"id":"caa9a252.3544d","type":"link out","z":"23a30f9a.261b6","name":"out_file_creation","links":["1ab0a757.282369"],"x":1255,"y":260,"wires":[]},{"id":"1ab0a757.282369","type":"link in","z":"ed0c995d.e2e7f8","name":"get_Keep_Alive","links":["caa9a252.3544d","18a379c8.b12376"],"x":475,"y":700,"wires":[["baf28c9e.7239c"]]},{"id":"c93f30c0.689fb","type":"inject","z":"da4609d5.3036c8","name":"no change","topic":"","payload":"1517594109","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":560,"y":220,"wires":[["ec7805e0.a34e58"]]},{"id":"3dd32ccf.927104","type":"function","z":"857ac83c.e099a8","name":"get day","func":"\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\nlet day=new Date(parseInt(msg.payload.Day));\nlet min=(day.setUTCHours(0,0,0,0))-offset;\nlet max = (day.setUTCHours(23,59,59,999))-offset;\n msg.payload =[[{ \"$match\": { date: {$gte:new Date(min), $lt:new Date(max)} } },\n { \"$project\": { \n \"date\": {$add:[\"$date\",offset]},\n \"angle\":\"$angle\",\n \"isSitting\":\"$isSitting\"\n }},\n { $sort: { date: 1}}\n ]];\n\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":220,"wires":[["2460826e.b365ee"]]},{"id":"2460826e.b365ee","type":"mongodb2 in","z":"857ac83c.e099a8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find day","collection":"back_angle","operation":"aggregate.toArray","x":520,"y":220,"wires":[["298646f7.89adea"]]},{"id":"298646f7.89adea","type":"function","z":"857ac83c.e099a8","name":"format result","func":"let minus=0;\nlet zero=0;\nlet fifteen=0;\nlet thirty=0;\nlet more=0;\n\nlet distinctTime= msg.payload;\nif(distinctTime.length>0){\n let previous = distinctTime[0];\n distinctTime.shift();\n if(distinctTime.length == 0 ){\n var lastTime=new Date(previous.date);\n if(previous.isSitting ==0){\n lastTime.setUTCHours(0,0,0,0);\n if (previous.angle<0)\n minus+= previous.date.getTime() - lastTime.getTime()+1;\n else if (15>previous.angle & previous.angle>=0)\n zero+= previous.date.getTime() - lastTime.getTime()+1;\n else if (30>previous.angle & previous.angle>=15)\n fifteen+= previous.date.getTime() - lastTime.getTime()+1;\n else if (45>=previous.angle & previous.angle>=30)\n thirty+= previous.date.getTime() - lastTime.getTime()+1;\n else if (45<previous.angle)\n more+= previous.date.getTime() - lastTime.getTime()+1;\n }\n else{\n lastTime.setUTCHours(23,59,59,999);\n if (previous.angle<0)\n minus+= lastTime.getTime()-previous.date.getTime();\n else if (15>previous.angle & previous.angle>=0)\n zero+= lastTime.getTime()-previous.date.getTime();\n else if (30>previous.angle & previous.angle>=15)\n fifteen+= lastTime.getTime()-previous.date.getTime();\n else if (45>=previous.angle & previous.angle>=30)\n thirty+= lastTime.getTime()-previous.date.getTime();\n else if (45<previous.angle)\n more+= lastTime.getTime()-previous.date.getTime();\n }\n }\n else{\n if(previous.isSitting==0){\n var lastTime=new Date(previous.date);\n lastTime.setUTCHours(0,0,0,0);\n if (previous.angle<0)\n minus+= previous.date.getTime() - lastTime.getTime()+1;\n else if (15>previous.angle & previous.angle>=0)\n zero+= previous.date.getTime() - lastTime.getTime()+1;\n else if (30>previous.angle & previous.angle>=15)\n fifteen+= previous.date.getTime() - lastTime.getTime()+1;\n else if (45>=previous.angle & previous.angle>=30)\n thirty+= previous.date.getTime() - lastTime.getTime()+1;\n else if (45<previous.angle)\n more+= previous.date.getTime() - lastTime.getTime()+1;\n }\n for(let time of distinctTime){\n if(previous.isSitting!=0){\n if (previous.angle<0)\n minus+= time.date.getTime() - previous.date.getTime();\n else if (15>previous.angle & previous.angle>=0)\n zero+= time.date.getTime() - previous.date.getTime();\n else if (30>previous.angle & previous.angle>=15)\n fifteen+= time.date.getTime() - previous.date.getTime();\n else if (45>=previous.angle & previous.angle>=30)\n thirty+= time.date.getTime() - previous.date.getTime();\n else if (45<previous.angle)\n more+= time.date.getTime() - previous.date.getTime();\n }\n previous = time;\n }\n if(previous.isSitting !=0){\n var lastTime=new Date(previous.date);\n lastTime.setUTCHours(23,59,59,999);\n if (previous.angle<0)\n minus+= lastTime.getTime() - previous.date.getTime();\n else if (15>previous.angle & previous.angle>=0)\n zero+= lastTime.getTime() - previous.date.getTime();\n else if (30>previous.angle & previous.angle>=15)\n fifteen+= lastTime.getTime() - previous.date.getTime();\n else if (45>=previous.angle & previous.angle>=30)\n thirty+= lastTime.getTime() - previous.date.getTime();\n else if (45<previous.angle)\n more+= lastTime.getTime() - previous.date.getTime();\n }\n }\n}\nmsg.payload = [minus,zero,fifteen,thirty,more];\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":220,"wires":[[]]},{"id":"65edf301.deb70c","type":"subflow:857ac83c.e099a8","z":"79c89fe4.873e6","name":"","x":590,"y":400,"wires":[["3da51abc.07fb96"]]},{"id":"3051e934.aaa456","type":"function","z":"23a30f9a.261b6","name":"","func":"if(msg.payload == null)\n msg.payload= \"[0,0,0,0,0]\";\n\nvar moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('DD-MM-YYYY')+\"_DayBackAngle.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":300,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]},{"id":"247b371d.8f7c68","type":"subflow:857ac83c.e099a8","z":"23a30f9a.261b6","name":"","x":770,"y":300,"wires":[["3051e934.aaa456"]]},{"id":"7e1485c6.68876c","type":"subflow:6c6d0616.a7df98","z":"23a30f9a.261b6","x":780,"y":340,"wires":[["8f1acae.a282c38"]]},{"id":"b5de3bd6.ecc668","type":"subflow:6c6d0616.a7df98","z":"79c89fe4.873e6","x":600,"y":460,"wires":[["3da51abc.07fb96"]]},{"id":"6741ff25.d9c22","type":"function","z":"a30d48d8.f609e8","name":"get month ","func":"\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\nmsg.offset=offset;\nvar moment = context.global.momentjs;\nlet min=new Date(parseInt(msg.payload.Day));\nmin.setDate(1);\nmin.setUTCHours(0,0,0,0);\nvar momentMin =moment(min);\nmomentMin.add(-offset,\"ms\");\nvar max=moment(momentMin);\nmax.add(1, 'months');\n msg.payload =[[{ \"$match\": { date: {$gte:new Date(momentMin), $lt:new Date(max)} } },\n { \"$project\": { \n \"date\": {$add:[\"$date\",offset]},\n \"isSitting\":\"$isSitting\"\n }},\n { $sort: { date: 1}}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":200,"y":160,"wires":[["7e29cd83.6a17d4"]]},{"id":"7e29cd83.6a17d4","type":"mongodb2 in","z":"a30d48d8.f609e8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find month","collection":"sitting_time","operation":"aggregate.toArray","x":390,"y":160,"wires":[["b93200a.1a5ad"]]},{"id":"b93200a.1a5ad","type":"function","z":"a30d48d8.f609e8","name":"format result","func":"let previous = msg.payload[0];\nvar retour={};\nmsg.payload.shift();\nretour[previous.date.getUTCDate()]=0\nif(!previous.isSitting){\n temp = new Date(previous.date);\n temp.setUTCHours(0,0,0,0);\n retour[previous.date.getUTCDate()]+=Math.round((previous.date.getTime()-temp.getTime())/60000);\n}\n\nfor(let time of msg.payload){\n if(retour[time.date.getUTCDate()]==null)\n retour[time.date.getUTCDate()]=0\n if(time.date.getUTCDate()==previous.date.getUTCDate()){\n if(previous.isSitting & !time.isSitting){\n retour[previous.date.getUTCDate()]+=Math.round((time.date.getTime()-previous.date.getTime())/60000);\n }\n }\n else{\n if(previous.isSitting){\n var temp = new Date(previous.date);\n temp.setUTCHours(23,59,59,999);\n retour[previous.date.getUTCDate()]+=Math.round((temp.getTime()-previous.date.getTime())/60000);\n temp = new Date(time.date);\n temp.setUTCHours(0,0,0,0);\n retour[time.date.getUTCDate()]+=Math.round((time.date.getTime()-temp.getTime())/60000);\n }\n }\n previous=time;\n}\nvar numberDays=0;\nif([0,2,4,6,8,9,11].includes(previous.date.getMonth())){\n numberDays =31;\n}\nelse if(previous.date.getMonth()==1){\n numberDays =30;\n}\nelse{\n if(previous.date.getFullYear()%4==0)\n numberDays=29;\n else \n numberDays=28\n}\nfor(var i=1;i<=numberDays;i++){\n retour[i] = retour[i] || 0;\n}\nmsg.payload= retour;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":160,"wires":[[]]},{"id":"cb186131.b222","type":"subflow:a30d48d8.f609e8","z":"79c89fe4.873e6","x":590,"y":540,"wires":[["3da51abc.07fb96"]]},{"id":"3c4a40e1.a66fd","type":"function","z":"d9e2e631.4f8778","name":"get day ","func":"\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\nlet day=new Date(parseInt(msg.payload.Day));\nlet min=(day.setUTCHours(0,0,0,0))-offset;\nlet max = (day.setUTCHours(23,59,59,999))-offset;\n msg.payload =[[{ \"$match\": { date: {$gte:new Date(min), $lt:new Date(max)} } },\n { \"$project\": { \n \"date\": {$add:[\"$date\",offset]},\n \"x\":\"$posX\",\n \"y\":\"$posY\"\n }},\n { $sort: { date: 1}}\n ]];\n\nreturn msg;","outputs":1,"noerr":0,"x":200,"y":140,"wires":[["44d6b343.41b0dc"]]},{"id":"44d6b343.41b0dc","type":"mongodb2 in","z":"d9e2e631.4f8778","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find day","collection":"gravity_Center","operation":"aggregate.toArray","x":380,"y":140,"wires":[["dcb6fbac.be34a8"]]},{"id":"dcb6fbac.be34a8","type":"function","z":"d9e2e631.4f8778","name":"format result","func":"var finalOutput ={};\nlet distinctTime= msg.payload;\nif(distinctTime!=null){\n for(let time of distinctTime){\n var lastTime=new Date(time.date);\n lastTime.setUTCHours(0,0,0,0);\n finalOutput[time.date.getTime()-lastTime.getTime()]={x:time.x,y:time.y};\n console.log(time);\n }\n}\nmsg.payload = finalOutput;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":140,"wires":[[]]},{"id":"45ba2c72.373494","type":"subflow:d9e2e631.4f8778","z":"79c89fe4.873e6","x":600,"y":620,"wires":[["3da51abc.07fb96"]]},{"id":"8dcd012d.f7da3","type":"subflow:a30d48d8.f609e8","z":"23a30f9a.261b6","x":770,"y":380,"wires":[["f33f1eb7.bf40e"]]},{"id":"f00b63be.adfa5","type":"subflow:d9e2e631.4f8778","z":"23a30f9a.261b6","x":780,"y":420,"wires":[["83c99adc.fb6028"]]},{"id":"8f1acae.a282c38","type":"function","z":"23a30f9a.261b6","name":"","func":"var moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('MM-YYYY')+\"_MonthBackAngle.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":340,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]},{"id":"f33f1eb7.bf40e","type":"function","z":"23a30f9a.261b6","name":"","func":"var moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('MM-YYYY')+\"_SittingTime.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":380,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]},{"id":"83c99adc.fb6028","type":"function","z":"23a30f9a.261b6","name":"","func":"var moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('DD-MM-YYYY')+\"_GravityCenter.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":420,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]},{"id":"24a0114f.4eddfe","type":"function","z":"988214cb.995018","name":"","func":"var data = msg.payload;\nmsg.payload = {};\nmsg.payload.filename = msg.backup[0];\nmsg.payload.filedata = data;\nreturn msg;","outputs":1,"noerr":0,"x":1050,"y":360,"wires":[["f95fb818.a0b4a8"]]},{"id":"e56bdf7e.cd655","type":"file in","z":"988214cb.995018","name":"","filename":"","format":"","chunk":false,"sendError":false,"x":890,"y":360,"wires":[["24a0114f.4eddfe"]]},{"id":"f95fb818.a0b4a8","type":"sftp in","z":"988214cb.995018","sftp":"e61fab25.c40b38","operation":"put","filename":"","localFilename":"","fileContents":"","fileExtension":".txt","workdir":"","savedir":"","name":"","x":1190,"y":360,"wires":[["da06e91c.513718","5d5c3422.7f832c"]]},{"id":"e96cb47.8cee348","type":"fs-file-lister","z":"988214cb.995018","name":"","start":"FileToSend","pattern":"*","path":false,"single":true,"depth":0,"stat":false,"x":560,"y":360,"wires":[["228bfcf5.1a7e14"]]},{"id":"228bfcf5.1a7e14","type":"function","z":"988214cb.995018","name":"","func":"msg.backup = msg.payload;\nmsg.filename = \"FileToSend/\"+ msg.payload[0];\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":360,"wires":[["e56bdf7e.cd655"]]},{"id":"da06e91c.513718","type":"function","z":"988214cb.995018","name":"","func":"msg.backup.shift();\nmsg.payload = msg.backup;\nreturn msg;","outputs":1,"noerr":0,"x":1370,"y":360,"wires":[["bec36af7.f55868"]]},{"id":"bec36af7.f55868","type":"switch","z":"988214cb.995018","name":"","property":"payload.length","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1510,"y":360,"wires":[["228bfcf5.1a7e14"]]},{"id":"90fe5af4.b11068","type":"comment","z":"988214cb.995018","name":"Loop to send all file","info":"","x":730,"y":260,"wires":[]},{"id":"5d5c3422.7f832c","type":"file","z":"988214cb.995018","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"delete","x":1370,"y":440,"wires":[]},{"id":"f9ff8f31.fba99","type":"mqtt in","z":"ed0c995d.e2e7f8","name":"config wifi","topic":"config/wifi_connected","qos":"0","broker":"2b8661c7.194ede","x":80,"y":640,"wires":[["2916689a.f64da8"]]},{"id":"d062dc13.20f13","type":"function","z":"ed0c995d.e2e7f8","name":"","func":"msg.payload =[{},{$set:{\"isConnected\":msg.payload.isConnected}}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":640,"wires":[["322ecf84.f72cb"]]},{"id":"2916689a.f64da8","type":"json","z":"ed0c995d.e2e7f8","name":"","property":"payload","action":"obj","pretty":false,"x":250,"y":640,"wires":[["d062dc13.20f13"]]},{"id":"d09f72ba.89afe","type":"function","z":"988214cb.995018","name":"","func":" msg.backup=msg.payload;\n msg.payload =[[{ \"$match\": { Value: \"CurrentState\" } },\n { \"$project\": { \n \"isConnected\": \"$isConnected\"\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":360,"wires":[["bee494c.2e03268"]]},{"id":"bee494c.2e03268","type":"mongodb2 in","z":"988214cb.995018","service":"_ext_","configNode":"c2e023a5.ad0b","name":"getKeepAlive","collection":"Current_State","operation":"aggregate.toArray","x":290,"y":360,"wires":[["4e6063bf.0e1ebc"]]},{"id":"4e6063bf.0e1ebc","type":"switch","z":"988214cb.995018","name":"","property":"payload[0].isConnected","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":360,"wires":[["e96cb47.8cee348"]]},{"id":"7b46a49e.ec9a5c","type":"link in","z":"988214cb.995018","name":"try_send_file","links":["c1a9ace2.8b12f","7827b669.929e78"],"x":35,"y":360,"wires":[["d09f72ba.89afe"]]},{"id":"c1a9ace2.8b12f","type":"link out","z":"23a30f9a.261b6","name":"","links":["7b46a49e.ec9a5c"],"x":1255,"y":340,"wires":[]},{"id":"7827b669.929e78","type":"link out","z":"ed0c995d.e2e7f8","name":"","links":["7b46a49e.ec9a5c"],"x":855,"y":640,"wires":[]},{"id":"322ecf84.f72cb","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"Current_State","operation":"update","x":620,"y":640,"wires":[["7827b669.929e78"]]},{"id":"e34cdcfe.00e06","type":"mqtt out","z":"988214cb.995018","name":"","topic":"config/wifi_connected","qos":"","retain":"","broker":"2b8661c7.194ede","x":440,"y":580,"wires":[]},{"id":"b0a1f158.c39c3","type":"inject","z":"988214cb.995018","name":"should change","topic":"","payload":"{\"isConnected\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":540,"wires":[["e34cdcfe.00e06"]]},{"id":"f5aef74e.f30718","type":"join","z":"23a30f9a.261b6","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"6","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1150,"y":340,"wires":[["c1a9ace2.8b12f"]]},{"id":"af6643a3.2c681","type":"http in","z":"79c89fe4.873e6","name":"","url":"/sittingTime","method":"get","upload":false,"swaggerDoc":"","x":140,"y":700,"wires":[["c8a2607e.8c43c"]]},{"id":"c8a2607e.8c43c","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":700,"wires":[["ff05080b.b24c08"]]},{"id":"ff05080b.b24c08","type":"subflow:a30d48d8.f609e8","z":"79c89fe4.873e6","x":590,"y":700,"wires":[["3da51abc.07fb96"]]},{"id":"3d6746ae.4cceda","type":"http in","z":"79c89fe4.873e6","name":"","url":"/Bouts","method":"get","upload":false,"swaggerDoc":"","x":130,"y":760,"wires":[["19e3e31.38cb01d"]]},{"id":"19e3e31.38cb01d","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":760,"wires":[["c40500eb.cfa89"]]},{"id":"7e30b952.5c6758","type":"mongodb2 in","z":"ed0c995d.e2e7f8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"Moving","operation":"insert","x":540,"y":420,"wires":[[]]},{"id":"3f7667f.e5d5098","type":"function","z":"36e4ab73.495fb4","name":"get day","func":"\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\nlet day=new Date(parseInt(msg.payload.Day));\nlet min=(day.setUTCHours(0,0,0,0))-offset;\nlet max = (day.setUTCHours(23,59,59,999))-offset;\n msg.payload =[[{ \"$match\": { date: {$gte:new Date(min), $lt:new Date(max)} } },\n { \"$project\": { \n \"date\": {$add:[\"$date\",offset]},\n \"isMoving\":\"$isMoving\"\n }},\n { $sort: { date: 1}}\n ]];\n\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":140,"wires":[["fc23407f.725d1"]]},{"id":"fc23407f.725d1","type":"mongodb2 in","z":"36e4ab73.495fb4","service":"_ext_","configNode":"c2e023a5.ad0b","name":"find day","collection":"Moving","operation":"aggregate.toArray","x":480,"y":140,"wires":[["c702805e.c0646"]]},{"id":"c702805e.c0646","type":"function","z":"36e4ab73.495fb4","name":"format result","func":"\nlet returnValue = [];\nlet distinctTime= msg.payload;\nif(distinctTime.length>0){\n let previous = distinctTime[0];\n distinctTime.shift();\n var index =0;\n if(distinctTime.length == 0 ){\n if( previous.isMoving ==0){\n var lastTime=new Date(previous.date);\n lastTime.setUTCHours(0,0,0,0);\n if((previous.date.getTime() - lastTime.getTime()) >= 180000){\n returnValue[index] = {start:lastTime.getTime(),end:previous.date.getTime()};\n index++;\n }\n }\n }\n else{\n var moveStart = false;\n var startTime = null;\n if( previous.isMoving ==0){\n var lastTime=new Date(previous.date);\n lastTime.setUTCHours(0,0,0,0);\n if((previous.date.getTime() - lastTime.getTime()) >= 180000){\n startTime=lastTime.getTime();\n moveStart = true;\n }\n }\n for(let time of distinctTime){\n if(time.isMoving==0){\n if(!moveStart){\n var lastTime=new Date(previous.date);\n if((time.date.getTime() - lastTime.getTime()) >= 180000){\n startTime=lastTime.getTime();\n moveStart = true;\n }\n }\n }\n else{\n if(moveStart){\n if((time.date.getTime() - new Date(previous.date).getTime()) > 120000){\n moveStart = false;\n returnValue[index] = {start:startTime,end:previous.date.getTime()};\n index++;\n }\n }\n }\n previous = time;\n }\n if(moveStart){\n if((new Date(previous.date).getTime() - startTime ) >= 180000){\n moveStart = false;\n returnValue[index] = {start:startTime,end:previous.date.getTime()};\n index++;\n }\n }\n if( previous.isMoving ==1){\n var lastTime=new Date(previous.date);\n lastTime.setUTCHours(23,59,59,999);\n returnValue[index] = {start:previous.date.getTime(),end:lastTime.getTime()};\n }\n }\n}\nmsg.payload = returnValue;\nreturn msg;\n\n ","outputs":1,"noerr":0,"x":680,"y":140,"wires":[[]]},{"id":"ff19b6cb.b91028","type":"function","z":"da4609d5.3036c8","name":"creation test moving","func":"var docs=[\n{date:new Date(\"2018-02-01T08:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-01T08:30:00.000Z\"), timestamp:\"1517439600000\",isMoving:0},\n{date:new Date(\"2018-02-01T09:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-01T09:01:00.000Z\"), timestamp:\"1517439600000\",isMoving:0},\n{date:new Date(\"2018-02-01T09:30:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-01T10:30:00.000Z\"), timestamp:\"1517439600000\",isMoving:0},\n{date:new Date(\"2018-02-01T10:31:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-01T23:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:0},\n{date:new Date(\"2018-02-01T23:30:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-02T01:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:0},\n{date:new Date(\"2018-02-04T09:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:1},\n{date:new Date(\"2018-02-04T23:00:00.000Z\"), timestamp:\"1517439600000\",isMoving:0}\n];\nmsg.payload=[docs];\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":640,"wires":[["c9c910ce.46596"]]},{"id":"c9c910ce.46596","type":"mongodb2 in","z":"da4609d5.3036c8","service":"_ext_","configNode":"c2e023a5.ad0b","name":"insert test","collection":"Moving","operation":"insertMany","x":460,"y":640,"wires":[[]]},{"id":"8402f367.0e142","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"{\"datetime\":\"2018-03-11:13:01:02\",\"IsSomeoneThere\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":640,"wires":[["ff19b6cb.b91028"]]},{"id":"62ea1e9e.647d8","type":"function","z":"da4609d5.3036c8","name":"offset 0","func":"msg.payload = {};\nmsg.payload.Day = 1517484102000;\n//msg.payload.Day = 1517734102000;\n\n\nmsg.payload.Offset = 0;\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":340,"wires":[["ce01afe3.aef9c","b892d41d.f66908","ce0855d9.623558","ac341e64.99de9","975c2ba.3f695d8","99422190.8cdcf","2fcbb2d0.70b7ce"]]},{"id":"c40500eb.cfa89","type":"subflow:36e4ab73.495fb4","z":"79c89fe4.873e6","x":590,"y":760,"wires":[["3da51abc.07fb96"]]},{"id":"b892d41d.f66908","type":"subflow:6c6d0616.a7df98","z":"da4609d5.3036c8","name":"","x":1100,"y":100,"wires":[["f4ee485f.c665c8"]]},{"id":"ce01afe3.aef9c","type":"subflow:a30d48d8.f609e8","z":"da4609d5.3036c8","x":1090,"y":140,"wires":[["19857de6.7b4462"]]},{"id":"ce0855d9.623558","type":"subflow:d9e2e631.4f8778","z":"da4609d5.3036c8","x":1100,"y":180,"wires":[["8ae3a664.809648"]]},{"id":"d72b3f20.3cc26","type":"function","z":"da4609d5.3036c8","name":"offset -10","func":"msg.payload = {};\nmsg.payload.Day = 1517484102000;\nmsg.payload.Offset = -10;\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":480,"wires":[["ec4fbb89.2cb778","a5624210.91dc7","e1e20314.0a047","735f4ae.78911b4","78e67dda.c99694","3a94b788.f71d18","70e6da1e.b7d164"]]},{"id":"a5624210.91dc7","type":"subflow:6c6d0616.a7df98","z":"da4609d5.3036c8","name":"","x":1100,"y":400,"wires":[["c4e4138e.9e1be"]]},{"id":"ec4fbb89.2cb778","type":"subflow:a30d48d8.f609e8","z":"da4609d5.3036c8","x":1090,"y":440,"wires":[["e70f4e44.d8da7"]]},{"id":"e1e20314.0a047","type":"subflow:d9e2e631.4f8778","z":"da4609d5.3036c8","x":1100,"y":480,"wires":[["3ac333ac.96148c"]]},{"id":"4bbf0aa9.4b6fa4","type":"function","z":"dad69f2b.73de2","name":"getMinMax","func":"\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\n msg.payload =[[{ \"$sort\": { date: 1 } },\n { \"$group\": { \n \"_id\": null, \n \"lastDate\":{\"$last\": {$add:[\"$date\",offset]} }\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":100,"wires":[["25f5d0c6.3f54a"]]},{"id":"25f5d0c6.3f54a","type":"mongodb2 in","z":"dad69f2b.73de2","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"back_angle","operation":"aggregate.toArray","x":610,"y":100,"wires":[["e8beda5d.a7d618"]]},{"id":"e8beda5d.a7d618","type":"function","z":"dad69f2b.73de2","name":"FormatData","func":"var date = new Date(msg.payload[0].lastDate);\nmsg.payload =date.getTime();\nconsole.log(date);\nconsole.log(date.getTime());\n\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":100,"wires":[[]]},{"id":"86fe7f00.16238","type":"function","z":"533bc41.d9a0d3c","name":"getMinMax","func":"let min=0;\nlet max=9999999999999;\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\nif(msg.payload.Min !=null){\n min = parseInt(msg.payload.Min);\n}\nif(msg.payload.Max !=null){\n max = parseInt(msg.payload.Max);\n}\n msg.payload =[[{ \"$match\": { date: {$gte: new Date(min-offset), $lt: new Date(max-offset)} } },\n { \"$project\": { \n \"date\":\"$date\"\n }},\n { \"$group\": { \n \"_id\": null, \n \"distinctDate\":{\"$addToSet\": { \"year\":{\"$year\":[{$add:[\"$date\",offset]}]}, \"month\":{\"$month\":[{$add:[\"$date\",offset]}]},\"day\": {\"$dayOfMonth\":[{$add:[\"$date\",offset]}]} }}\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":180,"wires":[["1b4bbbd.4ae1844"]]},{"id":"1b4bbbd.4ae1844","type":"mongodb2 in","z":"533bc41.d9a0d3c","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"back_angle","operation":"aggregate.toArray","x":630,"y":180,"wires":[["50f7a05b.0dc76"]]},{"id":"50f7a05b.0dc76","type":"function","z":"533bc41.d9a0d3c","name":"FormatData","func":"// msg.payload=msg.payload.map((element) => {\n// const splitDate = element.split(\"/\");\n// return {day:splitDate[2],month:splitDate[1],year:splitDate[0]};\n// })\nvar finalOutput={};\nvar distinctDates= msg.payload[0].distinctDate;\nfor(let date of distinctDates) {\n if (finalOutput[date.year]) {\n if (finalOutput[date.year][date.month]) {\n finalOutput[date.year][date.month].push(date.day);\n } else {\n finalOutput[date.year][date.month] = [date.day];\n }\n } else {\n finalOutput[date.year] = {\n [date.month]: [date.day]\n };\n }\n}\nmsg.payload=finalOutput;\n\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":180,"wires":[[]]},{"id":"ceaf94f8.7481b8","type":"function","z":"ad7d8d1c.cafbf","name":"getMinMax","func":"let min=0;\nlet max=9999999999999;\nlet offset =0;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\n\nif(msg.payload.Min !=null){\n min = parseInt(msg.payload.Min);\n}\nif(msg.payload.Max !=null){\n max = parseInt(msg.payload.Max);\n}\n msg.payload =[[{ \"$match\": { date: {$gte:new Date(min-offset), $lt:new Date(max-offset)} } },\n { \"$project\": { \n \"date\": \"$date\" \n }},\n { \"$group\": { \n \"_id\": null, \n \"distinctDate\":{\"$addToSet\": { \"year\":{\"$year\":[{$add:[\"$date\",offset]}]}, \"month\":{\"$month\":[{$add:[\"$date\",offset]}]} }}\n }}\n ]];\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":140,"wires":[["2d03a3cf.2e6cdc"]]},{"id":"2d03a3cf.2e6cdc","type":"mongodb2 in","z":"ad7d8d1c.cafbf","service":"_ext_","configNode":"c2e023a5.ad0b","name":"","collection":"back_angle","operation":"aggregate.toArray","x":610,"y":140,"wires":[["5b97c3d3.15a01c"]]},{"id":"5b97c3d3.15a01c","type":"function","z":"ad7d8d1c.cafbf","name":"FormatData","func":"// msg.payload=msg.payload.map((element) => {\n// const splitDate = element.split(\"/\");\n// return {day:splitDate[2],month:splitDate[1],year:splitDate[0]};\n// })\nvar finalOutput={};\nvar distinctDates= msg.payload[0].distinctDate;\nfor (let date of distinctDates) {\n if (finalOutput[date.year]) {\n finalOutput[date.year].push(date.month)\n } else {\n finalOutput[date.year] = [date.month];\n }\n}\nmsg.payload=finalOutput;\n\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":140,"wires":[[]]},{"id":"29e49b13.4a6054","type":"subflow:dad69f2b.73de2","z":"79c89fe4.873e6","x":590,"y":120,"wires":[["3da51abc.07fb96"]]},{"id":"2465d36d.b4433c","type":"subflow:533bc41.d9a0d3c","z":"79c89fe4.873e6","name":"","x":610,"y":200,"wires":[["3da51abc.07fb96"]]},{"id":"4d07edfe.46c584","type":"subflow:ad7d8d1c.cafbf","z":"79c89fe4.873e6","x":610,"y":280,"wires":[["3da51abc.07fb96"]]},{"id":"ac341e64.99de9","type":"subflow:dad69f2b.73de2","z":"da4609d5.3036c8","name":"","x":1090,"y":260,"wires":[["5c9aef57.edd67"]]},{"id":"975c2ba.3f695d8","type":"subflow:533bc41.d9a0d3c","z":"da4609d5.3036c8","x":1110,"y":300,"wires":[["3839e354.b00c1c"]]},{"id":"99422190.8cdcf","type":"subflow:ad7d8d1c.cafbf","z":"da4609d5.3036c8","x":1120,"y":340,"wires":[["d2e09292.64e08"]]},{"id":"735f4ae.78911b4","type":"subflow:dad69f2b.73de2","z":"da4609d5.3036c8","name":"","x":1090,"y":560,"wires":[["1bbfa625.d3672a"]]},{"id":"78e67dda.c99694","type":"subflow:533bc41.d9a0d3c","z":"da4609d5.3036c8","x":1110,"y":600,"wires":[["4a2bc940.d459d8"]]},{"id":"3a94b788.f71d18","type":"subflow:ad7d8d1c.cafbf","z":"da4609d5.3036c8","x":1120,"y":640,"wires":[["7a928942.66a808"]]},{"id":"f46312b4.3eb7b","type":"inject","z":"da4609d5.3036c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":440,"wires":[["d72b3f20.3cc26"]]},{"id":"518e2ad0.0e5764","type":"subflow:4e4dbcc2.17d054","z":"1dab1279.d003ee","name":"","x":430,"y":540,"wires":[["f7ef3d11.bd494","4373d430.f6141c"]]},{"id":"88d601a3.61c56","type":"http response","z":"1dab1279.d003ee","name":"","statusCode":"","headers":{},"x":810,"y":660,"wires":[]},{"id":"4373d430.f6141c","type":"template","z":"1dab1279.d003ee","name":"return erreur ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"result\":\"ok\"}","output":"str","x":630,"y":660,"wires":[["88d601a3.61c56"]]},{"id":"4f7cda4a.29fa14","type":"function","z":"858faa30.bafbe8","name":"get day","func":"var moment = context.global.momentjs;\nlet offset =0;\nmsg.backup = msg.payload;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\nmsg.return = {};\nvar momentMin =moment(new Date(parseInt(msg.payload.Day)));\nmomentMin.add(-offset,\"ms\");\nvar max=moment(momentMin);\nmax.endOf(\"month\");\nmsg.max = max;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":260,"wires":[["9ae8304b.9d75"]]},{"id":"9ae8304b.9d75","type":"subflow:36e4ab73.495fb4","z":"858faa30.bafbe8","x":430,"y":260,"wires":[["e543a6ea.578c08"]]},{"id":"e543a6ea.578c08","type":"function","z":"858faa30.bafbe8","name":"","func":"var moment = context.global.momentjs;\nvar day=moment(msg.backup.Day);\nmsg.return[day.date()] = msg.payload;\nmsg.payload = msg.backup;\nvar oldDate = day.date();\nday.add(1, 'days');\nif(day.date() < oldDate){\n msg.payload = msg.return;\n msg.result = 1;\n}\nelse{\n msg.payload ={}\n msg.payload.Offset = msg.backup.Offset;\n msg.payload.Day = new Date(day).getTime();\n msg.result = 0;\n msg.backup =msg.payload;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":260,"wires":[["6a46e855.cdd708"]]},{"id":"6a46e855.cdd708","type":"switch","z":"858faa30.bafbe8","name":"","property":"result","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":260,"wires":[[],["9ae8304b.9d75"]]},{"id":"2f8401b2.bbf70e","type":"function","z":"6c6d0616.a7df98","name":"get day","func":"var moment = context.global.momentjs;\nlet offset =0;\nmsg.backup = msg.payload;\nif(msg.payload.Offset !=null)\n offset = parseInt(msg.payload.Offset)*60*60*1000;\nmsg.return = {};\nvar momentMin =moment(new Date(parseInt(msg.payload.Day)));\nmomentMin.add(-offset,\"ms\");\nvar max=moment(momentMin);\nmax.endOf(\"month\");\nmsg.max = max;\nreturn msg;","outputs":1,"noerr":0,"x":200,"y":160,"wires":[["757f2c7a.87d5a4"]]},{"id":"43375f15.569e5","type":"function","z":"6c6d0616.a7df98","name":"","func":"var moment = context.global.momentjs;\nvar day=moment(msg.backup.Day);\nif(JSON.stringify(msg.payload) != \"[0,0,0,0,0]\")\n msg.return[day.date()] = msg.payload;\nelse\n msg.return[day.date()] = [];\n\nmsg.payload = msg.backup;\nvar oldDate = day.date();\nday.add(1, 'days');\nif(day.date() < oldDate){\n msg.payload = msg.return;\n msg.result = 1;\n}\nelse{\n msg.payload ={}\n msg.payload.Offset = msg.backup.Offset;\n msg.payload.Day = new Date(day).getTime();\n msg.result = 0;\n msg.backup =msg.payload;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":160,"wires":[["f111a7e3.1e91e8"]]},{"id":"f111a7e3.1e91e8","type":"switch","z":"6c6d0616.a7df98","name":"","property":"result","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":160,"wires":[[],["757f2c7a.87d5a4"]]},{"id":"757f2c7a.87d5a4","type":"subflow:857ac83c.e099a8","z":"6c6d0616.a7df98","x":390,"y":160,"wires":[["43375f15.569e5"]]},{"id":"5e99d393.df5d0c","type":"subflow:36e4ab73.495fb4","z":"23a30f9a.261b6","x":770,"y":460,"wires":[["56422b45.7b4944"]]},{"id":"6466ead6.8b8734","type":"subflow:858faa30.bafbe8","z":"23a30f9a.261b6","x":780,"y":500,"wires":[["daadb906.e91978"]]},{"id":"2fcbb2d0.70b7ce","type":"subflow:858faa30.bafbe8","z":"da4609d5.3036c8","x":1100,"y":220,"wires":[["2cb9fef3.2ef6e2"]]},{"id":"70e6da1e.b7d164","type":"subflow:858faa30.bafbe8","z":"da4609d5.3036c8","name":"","x":1100,"y":520,"wires":[["878ad1c2.ce1"]]},{"id":"2cb9fef3.2ef6e2","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":[{start:1517472000000, end:1517473800000},{start:1517477400000,end:1517526000000},{start:1517527800000, end:1517529599999}],\"2\":[{start:1517529600000, end:1517533200000}],\"3\":[],\"4\":[{start:1517734800000, end:1517785200000}],\"5\":[],\"6\":[],\"7\":[],\"8\":[],\"9\":[],\"10\":[],\"11\":[],\"12\":[],\"13\":[],\"14\":[],\"15\":[],\"16\":[],\"17\":[],\"18\":[],\"19\":[],\"20\":[],\"21\":[],\"22\":[],\"23\":[],\"24\":[],\"25\":[],\"26\":[],\"27\":[],\"28\":[]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Bouts month 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Bouts month 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":220,"wires":[["1cac304e.5eec9"]]},{"id":"878ad1c2.ce1","type":"function","z":"da4609d5.3036c8","name":"","func":"var expected={\"1\":[{start:1517443200000, end:1517490000000},{start:1517491800000,end:1517497200000}],\"2\":[],\"3\":[],\"4\":[{start:1517702400000, end:1517749200000}],\"5\":[],\"6\":[],\"7\":[],\"8\":[],\"9\":[],\"10\":[],\"11\":[],\"12\":[],\"13\":[],\"14\":[],\"15\":[],\"16\":[],\"17\":[],\"18\":[],\"19\":[],\"20\":[],\"21\":[],\"22\":[],\"23\":[],\"24\":[],\"25\":[],\"26\":[],\"27\":[],\"28\":[]};\nif(JSON.stringify(msg.payload).trim()===JSON.stringify(expected).trim()){\n msg.payload= {result:0,message:'Bouts month 0: ok'}; \n}\nelse{\n msg.payload= {result:1,message:'Bouts month 0: \\nValeur attendu: '+JSON.stringify(expected)+'\\nValeur obtenu : '+JSON.stringify(msg.payload)}; \n}\nreturn msg;","outputs":1,"noerr":0,"x":1290,"y":520,"wires":[["1cac304e.5eec9"]]},{"id":"b46ad18.0b4263","type":"http in","z":"79c89fe4.873e6","name":"","url":"/MonthBouts","method":"get","upload":false,"swaggerDoc":"","x":140,"y":820,"wires":[["9e992591.24c8e8"]]},{"id":"9e992591.24c8e8","type":"subflow:4e4dbcc2.17d054","z":"79c89fe4.873e6","name":"","x":350,"y":820,"wires":[["3eaea72f.9c3b28"]]},{"id":"3eaea72f.9c3b28","type":"subflow:858faa30.bafbe8","z":"79c89fe4.873e6","x":600,"y":820,"wires":[["3da51abc.07fb96"]]},{"id":"7175b2c6.867acc","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":120,"wires":[["a4c9917.ff2247"]]},{"id":"19092c9d.73cff3","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":180,"wires":[["c2165ebd.f4e88"]]},{"id":"b2976bf.98f7398","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":320,"wires":[["84788a39.0cd168"]]},{"id":"4e6cdb3b.56f734","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":380,"wires":[["ae2b8f3e.6f948"]]},{"id":"731097f.979cb68","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":440,"wires":[["a68c4468.5fdad8"]]},{"id":"380d1904.c4e1d6","type":"subflow:4e4dbcc2.17d054","z":"b9daa40a.159ce8","name":"","x":350,"y":500,"wires":[["e995576.05dbaa8"]]},{"id":"56422b45.7b4944","type":"function","z":"23a30f9a.261b6","name":"","func":"if(msg.payload == null)\n msg.payload= \"[]\";\n\nvar moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('DD-MM-YYYY')+\"_DayBouts.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":460,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]},{"id":"daadb906.e91978","type":"function","z":"23a30f9a.261b6","name":"","func":"var moment = context.global.momentjs;\nmsg.filename= \"FileToSend\\\\ID_\"+moment(msg.last*1000).format('MM-YYYY')+\"_MonthBouts.txt\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":500,"wires":[["f3a88a6.490f578","f5aef74e.f30718"]]}]