-
Notifications
You must be signed in to change notification settings - Fork 15
/
exercise_log.json
1 lines (1 loc) · 4.11 KB
/
exercise_log.json
1
[{"id":"acd05c4e.aa563","type":"tab","label":"Exercise","disabled":false,"info":""},{"id":"97c2ea0e.fe4d68","type":"file","z":"acd05c4e.aa563","name":"","filename":"/home/mike/Documents/exerciselog.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":870,"y":360,"wires":[["b740d2f8.b6cf18"]]},{"id":"7117b8ed.1c3b28","type":"debug","z":"acd05c4e.aa563","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":400,"wires":[]},{"id":"80099d73.2d50d8","type":"function","z":"acd05c4e.aa563","name":"Date Formatter","func":"var date;\ndate = new Date();\nvar year = date.getFullYear();\nvar month = date.getMonth();\nmonth = (month < 9 ? '0' : '') + (month+1)\nvar day = date.getDate();\nday = (day < 10 ? '0' : '') + day\nmsg.payload = year + '-' + month + '-' + day;\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":360,"wires":[["7117b8ed.1c3b28","97c2ea0e.fe4d68"]]},{"id":"cd632328.6bb408","type":"ui_button","z":"acd05c4e.aa563","name":"","group":"24f75e84.298d62","order":0,"width":0,"height":0,"passthru":false,"label":"Mike Exercised!","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":240,"y":320,"wires":[["80099d73.2d50d8","fa38e73c.276a38"]]},{"id":"fa38e73c.276a38","type":"file","z":"acd05c4e.aa563","name":"","filename":"/home/mike/Documents/exerciselog-raw.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":890,"y":320,"wires":[[]]},{"id":"b740d2f8.b6cf18","type":"ui_toast","z":"acd05c4e.aa563","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":false,"topic":"Good Job! Added to log:","name":"","x":1170,"y":360,"wires":[["fbba0d1.01691f"]]},{"id":"9a0b941a.78917","type":"ui_gauge","z":"acd05c4e.aa563","name":"","group":"a0972b0.da6fc58","order":0,"width":0,"height":0,"gtype":"gage","title":"Exercise Over Last 7 Days","label":"Days","format":"{{value}}","min":0,"max":"7","colors":["#ff0000","#ffff00","#00ff00"],"seg1":"1","seg2":"3","x":1160,"y":560,"wires":[]},{"id":"fbba0d1.01691f","type":"file in","z":"acd05c4e.aa563","name":"","filename":"/home/mike/Documents/exerciselog-raw.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":600,"y":560,"wires":[["d5268b63.9acba8"]]},{"id":"5d6806b.9bb7678","type":"debug","z":"acd05c4e.aa563","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1110,"y":620,"wires":[]},{"id":"90f8d4f2.9db3a8","type":"inject","z":"acd05c4e.aa563","name":"","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"0.4","x":280,"y":560,"wires":[["fbba0d1.01691f"]]},{"id":"d5268b63.9acba8","type":"function","z":"acd05c4e.aa563","name":"Magic","func":"//Turn incoming timestamps log into an array:\nvar exercisearray = msg.payload.split(\"\\n\");\nif (exercisearray.slice(-1)[0] === \"\") exercisearray.length = exercisearray.length-1\n\n//Get timestamp for week ago to compare against\nvar thismorning = new Date()\nthismorning.setHours(0)\nthismorning.setMinutes(0)\nthismorning.setSeconds(0)\nthismorning.setMilliseconds(0)\nvar sixdays = 1000*60*60*24*6\nvar oneweekago = thismorning.getTime()-sixdays\nnode.warn(oneweekago)\n\n//Iterate and count past week of exercise\nvar count = 0\nvar secondsinday = 60*24*7\nfor (var i=1; i<8; i++) {\n if (i>exercisearray.length) break;\n var testval = parseInt(exercisearray.slice(-i)[0]);\n node.warn(i,testval); \n if (testval >= oneweekago) ++count;\n}\n\n//Store our answer as the payload and pass along\nmsg.payload = count;\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":560,"wires":[["5d6806b.9bb7678","9a0b941a.78917"]]},{"id":"24f75e84.298d62","type":"ui_group","z":"","name":"Exercise Log","tab":"ae02afd8.ac8d7","disp":true,"width":"6","collapse":false},{"id":"a0972b0.da6fc58","type":"ui_group","z":"","name":"Exercise readout","tab":"ae02afd8.ac8d7","disp":false,"width":"6","collapse":false},{"id":"ae02afd8.ac8d7","type":"ui_tab","z":"","name":"Exercise","icon":"dashboard","order":3,"disabled":false,"hidden":false}]