diff --git a/index.js b/index.js index 3da8ad0..4de28c5 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,8 @@ const axios = require("axios"); const { createLogger, format, transports } = require("winston"); const { combine, timestamp, printf } = format; +const NIGHTSCOUT_TREND_ARROWS = require('./nightscoutTrendArrows'); + const logFormat = printf(({ level, message, timestamp }) => { return `${timestamp} [${level}]: ${message}`; }); @@ -155,6 +157,7 @@ async function uploadToNightscout(measurementData) { "type": "sgv", "dateString": measurementDate.toISOString(), "date": measurementDate.getTime(), + "direction": mapTrendArrow(glucoseMeasurement.TrendArrow), "sgv": glucoseMeasurement.Value }); @@ -185,6 +188,23 @@ async function uploadToNightscout(measurementData) { } } +function mapTrendArrow(libreTrendArrowRaw) { + switch (libreTrendArrowRaw) { + case 1: + return NIGHTSCOUT_TREND_ARROWS.singleDown + case 2: + return NIGHTSCOUT_TREND_ARROWS.fortyFiveDown + case 3: + return NIGHTSCOUT_TREND_ARROWS.flat + case 4: + return NIGHTSCOUT_TREND_ARROWS.fortyFiveUp + case 5: + return NIGHTSCOUT_TREND_ARROWS.singleUp + default: + return NIGHTSCOUT_TREND_ARROWS.notComputable + } +} + function deleteToken() { authTicket = {}; } diff --git a/nightscoutTrendArrows.js b/nightscoutTrendArrows.js new file mode 100644 index 0000000..419e350 --- /dev/null +++ b/nightscoutTrendArrows.js @@ -0,0 +1,17 @@ +// According to https://github.com/nightscout/cgm-remote-monitor/blob/46418c7ff275ae80de457209c1686811e033b5dd/lib/plugins/direction.js#L5 + +const NIGHTSCOUT_TREND_ARROWS = { + tripleUp: 'TripleUp', + doubleUp: 'DoubleUp', + singleUp: 'SingleUp', + fortyFiveUp: 'FortyFiveUp', + flat: 'Flat', + fortyFiveDown: 'FortyFiveDown', + singleDown: 'SingleDown', + tripleDown: 'TripleDown', + doubleDown: 'DoubleDown', + notComputable: 'NOT COMPUTABLE', + rateOutOfRange: 'RATE OUT OF RANGE' +} + +module.exports = NIGHTSCOUT_TREND_ARROWS