Skip to content

Commit

Permalink
Merge pull request #231 from tidepool-org/release-1.14.0
Browse files Browse the repository at this point in the history
Release 1.14.0 to `develop`
  • Loading branch information
krystophv authored Sep 24, 2020
2 parents 1cb5aad + 4e86030 commit 2c31303
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tidepool/viz",
"version": "1.14.0-develop.1",
"version": "1.14.0",
"description": "Tidepool data visualization for diabetes device data.",
"keywords": [
"data visualization"
Expand Down
7 changes: 7 additions & 0 deletions src/utils/AggregationUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AggregationUtil {
moment.utc(this.initialActiveEndpoints.range[0]).tz(this.timezoneName).format('YYYY-MM-DD'),
moment.utc(this.initialActiveEndpoints.range[1]).tz(this.timezoneName).format('YYYY-MM-DD'),
];
this.excludedDevices = _.get(dataUtil, 'excludedDevices', []);

reductio.registerPostProcessor('postProcessBasalAggregations', this.postProcessBasalAggregations);
reductio.registerPostProcessor('postProcessBolusAggregations', this.postProcessBolusAggregations);
Expand All @@ -42,6 +43,7 @@ export class AggregationUtil {

aggregateBasals = group => {
this.dataUtil.filter.byType('basal');
this.dataUtil.filter.byDeviceIds(this.excludedDevices);

const reducer = reductio();
reducer.dataList(true);
Expand All @@ -60,6 +62,7 @@ export class AggregationUtil {

aggregateBoluses = group => {
this.dataUtil.filter.byType('bolus');
this.dataUtil.filter.byDeviceIds(this.excludedDevices);

const reducer = reductio();
reducer.dataList(true);
Expand All @@ -83,6 +86,7 @@ export class AggregationUtil {

aggregateFingersticks = group => {
this.dataUtil.filter.byType('smbg');
this.dataUtil.filter.byDeviceIds(this.excludedDevices);

let reducer = reductio();
reducer.dataList(true);
Expand Down Expand Up @@ -127,6 +131,7 @@ export class AggregationUtil {

aggregateSiteChanges = group => {
this.dataUtil.filter.byType('deviceEvent');
this.dataUtil.filter.byDeviceIds(this.excludedDevices);

const reducer = reductio();
reducer.dataList(true);
Expand All @@ -147,6 +152,7 @@ export class AggregationUtil {
aggregateDataByDate = group => {
const types = _.map(this.dataUtil.types, d => d.type);
this.dataUtil.filter.byTypes(types);
this.dataUtil.filter.byDeviceIds(this.excludedDevices);

const reducer = reductio();
reducer.dataList(true);
Expand All @@ -157,6 +163,7 @@ export class AggregationUtil {
};

aggregateStatsByDate = group => {
this.dataUtil.filter.byDeviceIds(this.excludedDevices);
const reducer = reductio();
reducer.dataList(true);

Expand Down
78 changes: 78 additions & 0 deletions src/utils/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class DataUtil {

this.bolusToWizardIdMap = this.bolusToWizardIdMap || {};
this.bolusDatumsByIdMap = this.bolusDatumsByIdMap || {};
this.deviceUploadMap = this.deviceUploadMap || {};
this.wizardDatumsByIdMap = this.wizardDatumsByIdMap || {};
this.latestDatumByType = this.latestDatumByType || {};

Expand Down Expand Up @@ -186,6 +187,23 @@ export class DataUtil {
if (d.type === 'bolus') {
this.bolusDatumsByIdMap[d.id] = d;
}

// Generate a map of devices by deviceId
if (!d.deviceId && _.get(d, 'origin.name') === 'com.apple.HealthKit') {
const HKdeviceId = ['HealthKit'];
if (_.get(d, 'origin.payload.sourceRevision.source.name')) {
HKdeviceId.push(_.get(d, 'origin.payload.sourceRevision.source.name'));
}
HKdeviceId.push(d.uploadId.slice(0, 6));
d.deviceId = HKdeviceId.join(' ');
}
if (!d.deviceId && _.get(d, 'payload.transmitterId', false)) {
const dexDeviceId = ['Dexcom', d.uploadId.slice(0, 6)];
d.deviceId = dexDeviceId.join(' ');
}
if (d.deviceId && !this.deviceUploadMap[d.deviceId]) {
this.deviceUploadMap[d.deviceId] = d.uploadId;
}
};

joinWizardAndBolus = d => {
Expand Down Expand Up @@ -476,10 +494,12 @@ export class DataUtil {
this.bolusDatumsByIdMap = {};
this.wizardDatumsByIdMap = {};
this.latestDatumByType = {};
this.deviceUploadMap = {};
delete this.bgSources;
delete this.bgPrefs;
delete this.timePrefs;
delete this.latestPumpUpload;
delete this.devices;
this.init();
}
};
Expand Down Expand Up @@ -538,6 +558,10 @@ export class DataUtil {
this.dimension.byType = this.data.dimension(d => d.type);
};

buildByDeviceIdDimension = () => {
this.dimension.byDeviceId = this.data.dimension(d => d.deviceId || '');
};

// N.B. May need to become smarter about creating and removing dimensions if we get above 8,
// which would introduce additional performance overhead as per crossfilter docs.
buildDimensions = () => {
Expand All @@ -549,6 +573,7 @@ export class DataUtil {
this.buildBySubTypeDimension();
this.buildByTimeDimension();
this.buildByTypeDimension();
this.buildByDeviceIdDimension();
this.endTimer('buildDimensions');
};

Expand Down Expand Up @@ -576,6 +601,8 @@ export class DataUtil {
return this.dimension.bySubType.filterExact(subType);
};

this.filter.byDeviceIds = (excludedDeviceIds = []) => this.dimension.byDeviceId.filterFunction(deviceId => !_.includes(excludedDeviceIds, deviceId));

this.filter.byId = id => this.dimension.byId.filterExact(id);
this.endTimer('buildFilters');
};
Expand All @@ -597,6 +624,7 @@ export class DataUtil {
this.dimension.bySubType.filterAll();
this.dimension.byId.filterAll();
this.dimension.byDayOfWeek.filterAll();
this.dimension.byDeviceId.filterAll();
this.endTimer('clearFilters');
};

Expand Down Expand Up @@ -707,6 +735,43 @@ export class DataUtil {
this.endTimer('setSize');
};

/* eslint-disable no-param-reassign */
setDevices = () => {
this.startTimer('setDevices');
const uploadsById = _.keyBy(this.sort.byTime(this.filter.byType('upload').top(Infinity)), 'uploadId');
this.devices = _.reduce(this.deviceUploadMap, (result, value, key) => {
const upload = uploadsById[value];
let device = { id: key };

if (upload) {
const isContinuous = _.get(upload, 'dataSetType') === 'continuous';
const deviceManufacturer = _.get(upload, 'deviceManufacturers.0', '');
const deviceModel = _.get(upload, 'deviceModel', '');
let label = key;
if (deviceManufacturer || deviceModel) {
if (deviceManufacturer === 'Dexcom' && isContinuous) {
label = 'Dexcom API';
} else {
label = [deviceManufacturer, deviceModel].join(' ');
}
}
device = {
bgm: _.includes(upload.deviceTags, 'bgm'),
cgm: _.includes(upload.deviceTags, 'cgm'),
id: key,
label,
pump: _.includes(upload.deviceTags, 'insulin-pump'),
serialNumber: upload.deviceSerialNumber,
};
}

result.push(device);
return result;
}, []);
this.endTimer('setDevices');
}
/* eslint-enable no-param-reassign */

setMetaData = () => {
this.startTimer('setMetaData');
this.setSize();
Expand All @@ -717,6 +782,7 @@ export class DataUtil {
this.setActiveDays();
this.setTypes();
this.setUploadMap();
this.setDevices();
this.setLatestPumpUpload();
this.setIncompleteSuspends();
this.endTimer('setMetaData');
Expand Down Expand Up @@ -910,6 +976,12 @@ export class DataUtil {
this.returnRawData = returnRaw;
};

setExcludedDevices = (deviceIds = []) => {
this.startTimer('setExcludedDevices');
this.excludedDevices = deviceIds;
this.endTimer('setExcludedDevices');
}

query = (query = {}) => {
this.log('Query', query);

Expand All @@ -928,6 +1000,7 @@ export class DataUtil {
timePrefs,
types,
raw,
excludedDevices,
} = query;

// N.B. Must ensure that we get the desired endpoints in UTC time so that when we display in
Expand All @@ -944,6 +1017,7 @@ export class DataUtil {
if (timePrefs) this.setTimePrefs(timePrefs);
this.setEndpoints(endpoints, nextDays, prevDays);
this.setActiveDays(activeDays);
this.setExcludedDevices(excludedDevices);

const data = {};

Expand All @@ -958,6 +1032,9 @@ export class DataUtil {
// Filter out any inactive days of the week
this.filter.byActiveDays(this.activeDays);

// Filter out any excluded devices
this.filter.byDeviceIds(this.excludedDevices);

// Generate the stats for current range
if (this.stats.length && rangeKey === 'current') {
data[rangeKey].stats = this.getStats(this.stats);
Expand Down Expand Up @@ -1111,6 +1188,7 @@ export class DataUtil {
'latestPumpUpload',
'patientId',
'size',
'devices',
];

const requestedMetaData = _.isString(metaData) ? _.map(metaData.split(','), _.trim) : metaData;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/StatUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class StatUtil {
_.each(bgData, d => this.dataUtil.normalizeDatumBgUnits(d));

const data = {
bgMax: _.maxBy(bgData, 'value').value,
bgMin: _.minBy(bgData, 'value').value,
bgMax: _.get(_.maxBy(bgData, 'value'), 'value', null),
bgMin: _.get(_.minBy(bgData, 'value'), 'value', null),
};

return data;
Expand Down
1 change: 1 addition & 0 deletions stories/data/DataUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ stories.add('Query Generator', (props) => {
bgSources: 'bgSources',
latestDatumByType: 'latestDatumByType',
latestPumpUpload: 'latestPumpUpload',
devices: 'devices',
size: 'size',
};

Expand Down
Loading

0 comments on commit 2c31303

Please sign in to comment.