Skip to content

Commit

Permalink
Merge pull request #8 from nightscout/master
Browse files Browse the repository at this point in the history
master
  • Loading branch information
samihusseingit authored Jun 27, 2022
2 parents 10e7b09 + 4750f13 commit 30cc5ca
Show file tree
Hide file tree
Showing 17 changed files with 1,022 additions and 978 deletions.
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ FROM node:14.15.3-alpine

LABEL maintainer="Nightscout Contributors"

RUN mkdir -p /opt/app
ADD . /opt/app
WORKDIR /opt/app
RUN chown -R node:node /opt/app
USER node
ADD . /opt/app

RUN npm install && \
# TODO: We should be able to do `RUN npm install --only=production`.
# For this to work, we need to copy only package.json and things needed for `npm`'s to succeed.
# TODO: Do we need to re-add `npm audit fix`? Or should that be part of a development process/stage?
RUN npm install --cache /tmp/empty-cache && \
npm run postinstall && \
npm run env && \
npm audit fix
rm -rf /tmp/*
# TODO: These should be added in the future to correctly cache express-minify content to disk
# Currently, doing this breaks the browser cache.
# mkdir /tmp/public && \
# chown node:node /tmp/public

USER node
EXPOSE 1337

CMD ["node", "lib/server/server.js"]
2 changes: 1 addition & 1 deletion lib/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"HTTP_BAD_REQUEST": 400,
"ENTRIES_DEFAULT_COUNT" : 10,
"PROFILES_DEFAULT_COUNT" : 10,
"MMOL_TO_MGDL": 18,
"MMOL_TO_MGDL": 18.018018018,
"ONE_DAY" : 86400000,
"TWO_DAYS" : 172800000,
"FIFTEEN_MINUTES": 900000,
Expand Down
47 changes: 43 additions & 4 deletions lib/plugins/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function bridged (entries) {
mostRecentRecord = glucose[i].date;
}
}
//console.log("DEXCOM: Most recent entry received; "+new Date(mostRecentRecord).toString());
}
entries.create(glucose, function stored (err) {
if (err) {
Expand All @@ -46,12 +47,12 @@ function options (env) {
, minutes: env.extendedSettings.bridge.minutes || 1440
};

var interval = env.extendedSettings.bridge.interval || 60000 * 2.5; // Default: 2.5 minutes
var interval = env.extendedSettings.bridge.interval || 60000 * 2.6; // Default: 2.6 minutes

if (interval < 1000 || interval > 300000) {
// Invalid interval range. Revert to default
console.error("Invalid interval set: [" + interval + "ms]. Defaulting to 2.5 minutes.")
interval = 60000 * 2.5 // 2.5 minutes
console.error("Invalid interval set: [" + interval + "ms]. Defaulting to 2.6 minutes.")
interval = 60000 * 2.6 // 2.6 minutes
}

return {
Expand All @@ -75,15 +76,53 @@ function create (env, bus) {

bridge.startEngine = function startEngine (entries) {


opts.callback = bridged(entries);

let last_run = new Date(0).getTime();
let last_ondemand = new Date(0).getTime();

function should_run() {
// Time we expect to have to collect again
const msRUN_AFTER = (300+20) * 1000;
const msNow = new Date().getTime();

const next_entry_expected = mostRecentRecord + msRUN_AFTER;

if (next_entry_expected > msNow) {
// we're not due to collect a new slot yet. Use interval
const ms_since_last_run = msNow - last_run;
if (ms_since_last_run < interval) {
return false;
}

last_run = msNow;
last_ondemand = new Date(0).getTime();
console.log("DEXCOM: Running poll");
return true;
}

const ms_since_last_run = msNow - last_ondemand;

if (ms_since_last_run < interval) {
return false;
}
last_run = msNow;
last_ondemand = msNow;
console.log("DEXCOM: Data due, running extra poll");
return true;
}

let timer = setInterval(function () {
if (!should_run()) return;


opts.fetch.minutes = parseInt((new Date() - mostRecentRecord) / 60000);
opts.fetch.maxCount = parseInt((opts.fetch.minutes / 5) + 1);
opts.firstFetchCount = opts.fetch.maxCount;
console.log("Fetching Share Data: ", 'minutes', opts.fetch.minutes, 'maxCount', opts.fetch.maxCount);
engine(opts);
}, interval);
}, 1000 /*interval*/);

if (bus) {
bus.on('teardown', function serverTeardown () {
Expand Down
2 changes: 1 addition & 1 deletion lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function init () {
};

sbx.displayBg = function displayBg (entry) {
var isDex = entry && (!entry.device || entry.device === 'dexcom');
var isDex = entry && (!entry.device || entry.device === 'dexcom' || entry.device === 'share2');
if (isDex && Number(entry.mgdl) === 39) {
return 'LOW';
} else if (isDex && Number(entry.mgdl) === 401) {
Expand Down
2 changes: 1 addition & 1 deletion lib/server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@
"securitySchemes": {
"api_secret": {
"type": "apiKey",
"name": "api_secret",
"name": "api-secret",
"in": "header",
"description": "The hash of the API_SECRET env var"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/server/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ components:
securitySchemes:
api_secret:
type: apiKey
name: api_secret
name: api-secret
in: header
description: The hash of the API_SECRET env var
token_in_url:
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "14.2.4",
"version": "14.2.5",
"description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.",
"license": "AGPL-3.0",
"author": "Nightscout Team",
Expand Down Expand Up @@ -36,7 +36,7 @@
"bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys",
"bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json",
"generate-keys": "node bin/generateRandomString.js >tmp/randomString",
"coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage",
"coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE",
"dev": "env-cmd -f ./my.env nodemon --inspect lib/server/server.js 0.0.0.0",
"dev-test": "env-cmd -f ./my.devtest.env nodemon --inspect lib/server/server.js 0.0.0.0",
"prod": "env-cmd -f ./my.prod.env node lib/server/server.js 0.0.0.0",
Expand Down Expand Up @@ -109,7 +109,7 @@
"lodash": "^4.17.20",
"memory-cache": "^0.2.0",
"mime": "^2.4.6",
"minimed-connect-to-nightscout": "^1.5.0",
"minimed-connect-to-nightscout": "^1.5.2",
"moment": "^2.27.0",
"moment-locales-webpack-plugin": "^1.2.0",
"moment-timezone": "^0.5.31",
Expand All @@ -125,7 +125,7 @@
"random-token": "0.0.8",
"request": "^2.88.2",
"semver": "^6.3.0",
"share2nightscout-bridge": "^0.2.5",
"share2nightscout-bridge": "^0.2.8",
"shiro-trie": "^0.4.9",
"simple-statistics": "^0.7.0",
"socket.io": "~2.4.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('bridge', function ( ) {
var opts = bridge.options(tooLowInterval);
should.exist(opts);

opts.interval.should.equal(150000);
opts.interval.should.equal(156000);
});

it('set too high bridge interval option from env', function () {
Expand All @@ -64,7 +64,7 @@ describe('bridge', function ( ) {
var opts = bridge.options(tooHighInterval);
should.exist(opts);

opts.interval.should.equal(150000);
opts.interval.should.equal(156000);
});

it('set no bridge interval option from env', function () {
Expand All @@ -77,7 +77,7 @@ describe('bridge', function ( ) {
var opts = bridge.options(noInterval);
should.exist(opts);

opts.interval.should.equal(150000);
opts.interval.should.equal(156000);
});

});
Loading

0 comments on commit 30cc5ca

Please sign in to comment.