Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip/bewest/dev #19

Merged
merged 20 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ To synchronize from Dexcom Share use the following variables.
Optional, `CONNECT_SHARE_REGION` and `CONNECT_SHARE_SERVER` do the same thing, only specify one.
* `CONNECT_SHARE_REGION=` `ous` or `us`. `us` is the default if nothing is
provided. Selecting `us` sets `CONNECT_SHARE_SERVER` to `share2.dexcom.com`.
Selecting `ous` here sets `CONNECT_SHARE_SERVER` to `shareous2.dexcom.com`.
Selecting `ous` here sets `CONNECT_SHARE_SERVER` to `shareous1.dexcom.com`.
* `CONNECT_SHARE_SERVER=` set the server domain to use.


Expand Down
14 changes: 11 additions & 3 deletions lib/outputs/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ function persistent (config, ctx) {
return;
}

function mills_or(thing, other) {
var entry = sbx.lastEntry(thing);
return entry
? entry.mills
: other
;
}

var last = {
entries: new Date(sbx.lastEntry(sbx.data.sgvs).mills),
entries: new Date(mills_or(sbx.data.sgvs, 0)),
sgvs: sbx.lastEntry(sbx.data.sgvs),
treatments: sbx.lastEntry(sbx.data.treatments),
devicestatus: sbx.lastEntry(sbx.data.devicestatus),
treatments: new Date(mills_or(sbx.data.treatments, 0)),
devicestatus: new Date(mills_or(sbx.data.devicestatus, 0)),
profile: sbx.lastEntry(sbx.data.profile)

};
Expand Down
2 changes: 1 addition & 1 deletion lib/sources/dexcomshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var software = require('../../package.json');
var user_agent_string = [software.name, `${software.name}@${software.version}`, '"Dexcom Share"', software.homepage].join(', ');

var _known_servers = {
ous: 'shareous2.dexcom.com',
ous: 'shareous1.dexcom.com',
us: 'share2.dexcom.com'
}

Expand Down
23 changes: 15 additions & 8 deletions lib/sources/librelinkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function linkUpSource (opts, axios) {
},
sessionFromAuth (auth) {
function isPatient (elem) {
return elem.patientId == opts.patientId;
return elem.patientId == opts.linkUpPatientId;
}
var token = auth.data.authTicket.token;
var headers = {
Expand Down Expand Up @@ -112,21 +112,25 @@ function linkUpSource (opts, axios) {
var headers = {
'Authorization': `Bearer ${token}`
};
http.get(graph_url, { headers }).then((resp) => {
return http.get(graph_url, { headers }).then((resp) => {
console.log("RECEIVED LIBRE GRAPH DATA", resp.status, resp.headers, resp.data);
return resp.data.data;
return resp.data;
});
},
transformGlucose (batch, last_known) {
transformGlucose (payload, last_known) {
var { status, data, ticket } = payload;
var batch = data;
// TODO: TRANSFORM
var last_updated = last_known.entries;
function is_newer (elem) {
if (!last_known) { return true; };
last_known.entries < new Date(elem.FactoryTimestamp);
return last_known.entries < new Date(elem.dateString);
}

function to_ns_sgv (elem) {
var dateTime = new Date(elem.FactoryTimestamp);
var offset = dateTime.getTimezoneOffset( ) * 60 * 1000;
dateTime.setTime(dateTime.getTime( ) - offset);
return {
type: 'sgv',
device: 'nightscout-connect-librelinkup',
Expand All @@ -137,9 +141,12 @@ function linkUpSource (opts, axios) {
};
}

var entries = batch.graphData.filter(is_newer).map(to_ns_sgv);
var entries = batch.graphData.map(to_ns_sgv).filter(is_newer);
var treatments = [ ];
var devicestatus = [ ];
var profiles = [ ];
console.log("TRANSFORMING LIBRE BATCH", batch);
return { entries };
return { entries, treatments, devicestatus, profiles };
},
align_to_glucose (last_known) {
console.log("LIBRELINKUP SOURCE DRIVER ALIGNMENT FOR GLUCOSE");
Expand All @@ -161,7 +168,7 @@ function linkUpSource (opts, axios) {
}
};
function tracker_for ( ) {
var AxiosTracer = require('../../trace-axios');
var AxiosTracer = require('../trace-axios');
var tracker = AxiosTracer(http);
return tracker;
}
Expand Down
Loading