Skip to content

Commit

Permalink
Merge pull request #7 from sebdei/Trend-Arrows
Browse files Browse the repository at this point in the history
Trend Arrows
  • Loading branch information
timoschlueter authored Jan 12, 2022
2 parents 83a47aa + 40d973b commit 5a4ad16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
});
Expand Down Expand Up @@ -155,6 +157,7 @@ async function uploadToNightscout(measurementData) {
"type": "sgv",
"dateString": measurementDate.toISOString(),
"date": measurementDate.getTime(),
"direction": mapTrendArrow(glucoseMeasurement.TrendArrow),
"sgv": glucoseMeasurement.Value
});

Expand Down Expand Up @@ -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 = {};
}
Expand Down
17 changes: 17 additions & 0 deletions nightscoutTrendArrows.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5a4ad16

Please sign in to comment.