Skip to content
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
17 changes: 15 additions & 2 deletions lib/profilefunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,27 @@ function init (profileData) {

for (var key in profile.data[0].store) {
if (profile.data[0].store.hasOwnProperty(key) && key !== current) {
if (key.indexOf('@@@@@') < 0)
profiles.push(key);
}
}
}
return profiles;
};



// get original store without added profiles fro profileSwitches
profile.getProfileStore = function getProfileStore () {
var newprofiledata = _.clone(profile.data[0]);
for (var key in profile.data[0].store) {
if (profile.data[0].store.hasOwnProperty(key)) {
if (key.indexOf('@@@@@') < 0)
store[key] = profile.data[0].store[key];
}
}
return store;
};


if (profileData) { profile.loadData(profileData); }
// init treatments array
profile.updateTreatments([], []);
Expand Down
104 changes: 81 additions & 23 deletions lib/report_plugins/daytoday.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,80 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options)
'translate(' + (xScale2(treatment.mills) + padding.left + 10) + ',' + (padding.top+yInsulinScale(treatment.insulin)) + ')')
.text(Number(treatment.insulin).toFixed(2)+'U');
}

// process the rest
if (treatment.insulin || treatment.carbs || treatment.eventType == 'Temp Basal' || treatment.eventType == 'Combo Bolus') {
// ignore
} else if (treatment.eventType === 'Profile Switch') {
// profile switch
appendProfileSwitch(context, treatment);
if (treatment.duration && !treatment.cuttedby) {
appendProfileSwitch(context, {
cutting: treatment.profile
, profile: client.profilefunctions.activeProfileToTime(times.mins(treatment.duration).msecs + treatment.mills + 1)
, mills: times.mins(treatment.duration).msecs + treatment.mills
, end: true
});
}
} else if (treatment.eventType === 'Exercise' && treatment.duration) {
context.append('rect')
.attr('x', xScale2(treatment.mills) + padding.left)
.attr('y', yScale2(client.utils.scaleMgdl(396)) + padding.top)
.attr('width', xScale2(treatment.mills + times.mins(treatment.duration).msecs) - xScale2(treatment.mills))
.attr('height', yScale2(client.utils.scaleMgdl(360)) - yScale2(client.utils.scaleMgdl(396)))
.attr('stroke-width', 1)
.attr('opacity', .2)
.attr('stroke', 'white')
.attr('fill', 'Violet');
context.append('text')
.style('font-size', '12px')
.style('font-weight', 'bold')
.attr('fill', 'Violet')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('y', yScale2(client.utils.scaleMgdl(378)) + padding.top)
.attr('x', xScale2(treatment.mills + times.mins(treatment.duration).msecs/2) + padding.left)
.text(treatment.notes);
} else if (treatment.eventType === 'Note' && treatment.duration) {
context.append('rect')
.attr('x', xScale2(treatment.mills) + padding.left)
.attr('y', yScale2(client.utils.scaleMgdl(360)) + padding.top)
.attr('width', xScale2(treatment.mills + times.mins(treatment.duration).msecs) - xScale2(treatment.mills))
.attr('height', yScale2(client.utils.scaleMgdl(324)) - yScale2(client.utils.scaleMgdl(360)))
.attr('stroke-width', 1)
.attr('opacity', .2)
.attr('stroke', 'white')
.attr('fill', 'Salmon');
context.append('text')
.style('font-size', '12px')
.style('font-weight', 'bold')
.attr('fill', 'Salmon')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('y', yScale2(client.utils.scaleMgdl(342)) + padding.top)
.attr('x', xScale2(treatment.mills + times.mins(treatment.duration).msecs/2) + padding.left)
.text(treatment.notes);
} else if (treatment.eventType === 'OpenAPS Offline' && treatment.duration) {
context.append('rect')
.attr('x', xScale2(treatment.mills) + padding.left)
.attr('y', yScale2(client.utils.scaleMgdl(324)) + padding.top)
.attr('width', xScale2(treatment.mills + times.mins(treatment.duration).msecs) - xScale2(treatment.mills))
.attr('height', yScale2(client.utils.scaleMgdl(288)) - yScale2(client.utils.scaleMgdl(324)))
.attr('stroke-width', 1)
.attr('opacity', .2)
.attr('stroke', 'white')
.attr('fill', 'Brown');
context.append('text')
.style('font-size', '12px')
.style('font-weight', 'bold')
.attr('fill', 'Brown')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('y', yScale2(client.utils.scaleMgdl(306)) + padding.top)
.attr('x', xScale2(treatment.mills + times.mins(treatment.duration).msecs/2) + padding.left)
.text(treatment.notes);
} else if (!treatment.duration) {
// other treatments without duration
if (!treatment.insulin && !treatment.carbs && !treatment.duration && treatment.eventType !== 'Temp Basal' && treatment.eventType !== 'Profile Switch') {
context.append('circle')
.attr('cx', xScale2(treatment.mills) + padding.left)
.attr('cy', yScale2(scaledTreatmentBG(treatment,data.sgv)) + padding.top)
Expand All @@ -648,42 +720,28 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options)
.attr('y', yScale2(scaledTreatmentBG(treatment,data.sgv)) + padding.top -10)
.attr('x', xScale2(treatment.mills) + padding.left + 10)
.text(translate(client.careportal.resolveEventName(treatment.eventType)));
}
} else if (treatment.duration) {
// other treatments with duration
if (!treatment.insulin && !treatment.carbs && treatment.duration && treatment.eventType !== 'Temp Basal' && treatment.eventType !== 'Profile Switch' && treatment.eventType !== 'Combo Bolus') {
context.append('rect')
.attr('x', xScale2(treatment.mills) + padding.left)
.attr('y', 0 + padding.top)
.attr('y', yScale2(client.utils.scaleMgdl(432)) + padding.top)
.attr('width', xScale2(treatment.mills + times.mins(treatment.duration).msecs) - xScale2(treatment.mills))
.attr('height', chartHeight)
//.attr('rx', 5)
//.attr('ry', 5)
.attr('height', yScale2(client.utils.scaleMgdl(396)) - yScale2(client.utils.scaleMgdl(432)))
.attr('stroke-width', 1)
.attr('opacity', .2)
.attr('stroke', 'white')
.attr('fill', treatment.eventType === 'Exercise' ? 'Violet' : (treatment.eventType === 'Note' ? 'Salmon' : 'black'));
.attr('fill', 'black');
context.append('text')
.style('font-size', '12px')
.style('font-weight', 'bold')
.attr('fill', treatment.eventType === 'Exercise' ? 'Violet' : (treatment.eventType === 'Note' ? 'Salmon' : 'black'))
.attr('fill', 'black')
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('y', foodtexts * 15 + 10 + padding.top)
.attr('y', yScale2(client.utils.scaleMgdl(414)) + padding.top)
.attr('x', xScale2(treatment.mills + times.mins(treatment.duration).msecs/2) + padding.left)
.text(treatment.notes);
foodtexts = (foodtexts + 1) % 6;
}
// profile switch
if (treatment.eventType === 'Profile Switch') {
appendProfileSwitch(context, treatment);
if (treatment.duration && !treatment.cuttedby) {
appendProfileSwitch(context, {
cutting: treatment.profile
, profile: client.profilefunctions.activeProfileToTime(times.mins(treatment.duration).msecs + treatment.mills + 1)
, mills: times.mins(treatment.duration).msecs + treatment.mills
, end: true
});
}
} else {
console.log("missed treatment", treatment);
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function init ( ) {

var profile = require('./profilefunctions')();
//Plugins will expect the right profile based on time
profile.loadData(ctx.ddata.profiles);
profile.loadData(_.cloneDeep(ctx.ddata.profiles));
profile.updateTreatments(ctx.ddata.profileTreatments, ctx.ddata.tempbasalTreatments, ctx.ddata.combobolusTreatments);
sbx.data.profile = profile;
delete sbx.data.profiles;
Expand Down
2 changes: 1 addition & 1 deletion static/profile/js/profileeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
records.push(defaultprofile);
}
client.profilefunctions.loadData(records); // do a conversion if needed
mongorecords = client.profilefunctions.data;
mongorecords = _.cloneDeep(client.profilefunctions.data);
// create new profile to be edited from last record
if (mongorecords.length) {
_.each(mongorecords, function eachMongoProfile (mongoprofile) {
Expand Down
17 changes: 13 additions & 4 deletions static/report/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
if (options.order === report_plugins.consts.ORDER_NEWESTONTOP) {
sorteddaystoshow.reverse();
}
loadProfileSwitch(function loadProfileSwitchCallback() {
loadProfileSwitch(from, function loadProfileSwitchCallback() {
loadProfiles(function loadProfilesCallback() {
$('#info > b').html('<b>' + translate('Rendering') + ' ...</b>');
window.setTimeout(function () {
Expand Down Expand Up @@ -629,6 +629,8 @@
}

function loadTreatmentData() {
if (!datastorage.profileSwitchTreatments)
datastorage.profileSwitchTreatments = [];
$('#info-' + day).html('<b>'+translate('Loading treatments data of')+' '+day+' ...</b>');
var tquery = '?find[created_at][$gte]='+new Date(from).toISOString()+'&find[created_at][$lt]='+new Date(to).toISOString();
return $.ajax('/api/v1/treatments.json'+tquery, {
Expand All @@ -649,6 +651,11 @@
data.tempbasalTreatments = data.treatments.filter(function filterTempBasals(t) {
return t.eventType === 'Temp Basal';
});
// filter profile switch treatments
var profileSwitch = data.treatments.filter(function filterProfileSwitch(t) {
return t.eventType === 'Profile Switch';
});
datastorage.profileSwitchTreatments = datastorage.profileSwitchTreatments.concat(profileSwitch);
}
});
}
Expand Down Expand Up @@ -682,9 +689,9 @@
});
}

function loadProfileSwitch(callback) {
function loadProfileSwitch(from, callback) {
$('#info > b').html('<b>'+translate('Loading profile switch data') + ' ...</b>');
var tquery = '?find[eventType]=Profile Switch';
var tquery = '?find[eventType]=Profile Switch' + '&find[created_at][$lte]=' + new Date(from).toISOString() + '&count=1';
$.ajax('/api/v1/treatments.json'+tquery, {
headers: client.headers()
, success: function (xhr) {
Expand All @@ -693,7 +700,9 @@
treatment.mills = timestamp.getTime();
return treatment;
});
datastorage.profileSwitchTreatments = treatmentData.slice();
if (!datastorage.profileSwitchTreatments)
datastorage.profileSwitchTreatments = [];
datastorage.profileSwitchTreatments = datastorage.profileSwitchTreatments.concat(treatmentData);
datastorage.profileSwitchTreatments.sort(function(a, b) { return a.mills - b.mills; });
}
}).done(function () {
Expand Down