Created
December 17, 2021 17:22
-
-
Save aerobless/ed6d216e6ba8543625c1ff5e37d61b82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"a5733396e98a6fbf","type":"function","z":"e550f91e.577438","name":"insert metrics","func":"msg.payload = {\n\"data\" : {\n\"metrics\" : [\n{\n\"units\" : \"count\",\n\"data\" : [\n{\n\"qty\" : 5472,\n\"date\" : \"2021-12-11 00:00:00 -0500\"\n},\n{\n\"qty\" : 8169,\n\"date\" : \"2021-12-12 00:00:00 -0500\"\n},\n{\n\"date\" : \"2021-12-13 00:00:00 -0500\",\n\"qty\" : 3446\n},\n{\n\"date\" : \"2021-12-14 00:00:00 -0500\",\n\"qty\" : 4784\n},\n{\n\"date\" : \"2021-12-15 00:00:00 -0500\",\n\"qty\" : 4837.7652613770606\n},\n{\n\"qty\" : 4852,\n\"date\" : \"2021-12-16 00:00:00 -0500\"\n}\n],\n\"name\" : \"step_count\"\n}\n],\n\"workouts\" : [\n\n]\n}\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":220,"y":3440,"wires":[["aaeb804e202a0508"]]},{"id":"9513551692b17c69","type":"inject","z":"e550f91e.577438","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":3560,"wires":[["a5733396e98a6fbf"]]},{"id":"aaeb804e202a0508","type":"function","z":"e550f91e.577438","name":"map health metrics to influx measurement","func":"msg.payload = msg.payload.data.metrics.map(metric => {\n\n //e.g. measurement for 01.01.2020 of active_energy\n return metric.data.map(actualMeasurement =>\n ({\n measurement: metric.units, //kJ\n fields: {\n ...(actualMeasurement.qty && {value: actualMeasurement.qty}), //2500 default\n ...(actualMeasurement.Avg && {Avg: actualMeasurement.Avg}), //Heartrate special\n ...(actualMeasurement.Max && {Max: actualMeasurement.Max}), //Heartrate special\n ...(actualMeasurement.Min && {Min: actualMeasurement.Min}), //Heartrate special\n ...(actualMeasurement.inBed && {inBed: actualMeasurement.inBed}), //Bed special\n ...(actualMeasurement.asleep && {asleep: actualMeasurement.asleep}), //Bed special\n ...(actualMeasurement.heartRateVariation && { value: measurement.heartRateVariation.length }), //irregular heartrate special\n },\n tags:{\n entity_id: metric.name, //active_energy\n ...(actualMeasurement.sleepSource && {sleepSource: actualMeasurement.sleepSource}), //Bed special\n ...(actualMeasurement.inBedSource && {inBedSource: actualMeasurement.inBedSource}) //Bed special\n },\n timestamp: Date.parse(actualMeasurement.date) //2021-03-16 00:00:00 +0100\n }))\n })\n .flat() // we've created array for each metric consisting of array of measurements\n .filter(e => Object.keys(e.fields).length) // only return entries with fields\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":3440,"wires":[["c3ece44f2716a9b9"]]},{"id":"c3ece44f2716a9b9","type":"debug","z":"e550f91e.577438","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":3440,"wires":[]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment