Skip to content

Commit

Permalink
more easy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Jul 1, 2015
1 parent fd58572 commit 320565b
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 105 deletions.
2 changes: 1 addition & 1 deletion bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sandbox: require('../lib/sandbox')()
};

console.info("Nightscout bundle ready", window.Nightscout);
console.info('Nightscout bundle ready', window.Nightscout);

})();

2 changes: 1 addition & 1 deletion lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function configure (app, wares) {
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';
return res.format({
html: function ( ) {
res.send("<h1>STATUS OK</h1>");
res.send('<h1>STATUS OK</h1>');
},
png: function ( ) {
res.redirect(302, badge + '.png');
Expand Down
22 changes: 12 additions & 10 deletions lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function init(env, ctx) {
data.sgvs = sgvs;
}
callback();
})
});
}, cal: function (callback) {
//FIXME: date $gte?????
var cq = {count: 1, find: {type: 'cal'}};
Expand Down Expand Up @@ -156,15 +156,15 @@ function init(env, ctx) {
data.devicestatus.uploaderBattery = result.uploaderBattery;
}
callback();
})
});
}
}, done);

};

data.calculateDelta = function calculateDelta(lastData) {
return data.calculateDeltaBetweenDatasets(lastData,data);
}
};

data.calculateDeltaBetweenDatasets = function calculateDeltaBetweenDatasets(oldData,newData) {

Expand All @@ -178,7 +178,7 @@ function init(env, ctx) {
var seen = {};
var l = oldArray.length;
for (var i = 0; i < l; i++) {
seen[oldArray[i].x] = true
seen[oldArray[i].x] = true;
}
var result = [];
l = newArray.length;
Expand Down Expand Up @@ -229,12 +229,14 @@ function init(env, ctx) {
var skippableObjects = ['profiles', 'devicestatus'];

for (var object in skippableObjects) {
var o = skippableObjects[object];
if (newData.hasOwnProperty(o)) {
if (JSON.stringify(newData[o]) != JSON.stringify(oldData[o])) {
console.log('delta changes found on', o);
changesFound = true;
delta[o] = newData[o];
if (skippableObjects.hasOwnProperty(object)) {
var o = skippableObjects[object];
if (newData.hasOwnProperty(o)) {
if (JSON.stringify(newData[o]) != JSON.stringify(oldData[o])) {
console.log('delta changes found on', o);
changesFound = true;
delta[o] = newData[o];
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function storage(env, ctx) {

// determine sort options
function sort ( ) {
return {"date": -1};
return {date: -1};
// return this.sort({"date": -1});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function configure(env, ctx) {
});

ctx.entries.create([ packet ], function empty(err, res) {
console.log('Download written to mongo: ', packet)
console.log('Download written to mongo: ', packet);
});


Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/ar2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function init() {
var result = {};

if (lastSGVEntry && Date.now() - lastSGVEntry.x < TEN_MINUTES) {
result = ar2.forcastAndCheck(sbx.data.sgvs)
result = ar2.forcastAndCheck(sbx.data.sgvs);
}

var usingRaw = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/boluswizardpreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function init() {
level: sbx.notifications.levels.URGENT
, lengthMills: snoozeLength
, debug: results
})
});
} else if (results.bolusEstimate > warnBWP) {
var level = results.bolusEstimate > urgentBWP ? sbx.notifications.levels.URGENT : sbx.notifications.levels.WARN;
var levelLabel = sbx.notifications.levels.toString(level);
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/cob.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function init() {
return {
netCarbImpact: netCarbImpact,
totalImpact: totalImpact
}
};
};

cob.cobCalc = function cobCalc(treatment, profile, lastDecayedBy, time) {
Expand Down Expand Up @@ -159,7 +159,7 @@ function init() {
if (prop.lastCarbs) {
var when = moment(new Date(prop.lastCarbs.created_at)).format('lll');
var amount = prop.lastCarbs.carbs + 'g';
info = [{label: 'Last Carbs', value: amount + ' @ ' + when }]
info = [{label: 'Last Carbs', value: amount + ' @ ' + when }];
}

sbx.pluginBase.updatePillText(sbx, {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/iob.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function init() {
if (prop && prop.lastBolus) {
var when = moment(new Date(prop.lastBolus.created_at)).format('lll');
var amount = sbx.roundInsulinForDisplayFormat(Number(prop.lastBolus.insulin)) + 'U';
info = [{label: 'Last Bolus', value: amount + ' @ ' + when }]
info = [{label: 'Last Bolus', value: amount + ' @ ' + when }];
}

sbx.pluginBase.updatePillText(iob, {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/pluginbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function init (majorPills, minorPills, statusPills, bgStatus, tooltip) {
} else if (plugin.pluginType == 'pill-alt') {
container = bgStatus;
} else {
container = minorPills
container = minorPills;
}

var pillName = 'span.pill.' + plugin.name;
Expand Down
23 changes: 11 additions & 12 deletions lib/profilefunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,45 @@ function init(profileData) {
}

return returnValue;
}
};

profile.getCurrentProfile = function getCurrentProfile() {
if (profile.hasData()) return profile.data[0];
return {};
}
return profile.hasData() ? profile.data[0] : {};
};

profile.hasData = function hasData() {
var rVal = false;
if (profile.data) rVal = true;
return (rVal);
}
};

profile.getDIA = function getDIA(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['dia']);
}
};

profile.getSensitivity = function getSensitivity(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['sens']);
}
};

profile.getCarbRatio = function getCarbRatio(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['carbratio']);
}
};

profile.getCarbAbsorptionRate = function getCarbAbsorptionRate(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['carbs_hr']);
}
};

profile.getLowBGTarget = function getLowBGTarget(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['target_low']);
}
};

profile.getHighBGTarget = function getHighBGTarget(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['target_high']);
}
};

profile.getBasal = function getBasal(time) {
return profile.getValueByTime(time,profile.getCurrentProfile()['basal']);
}
};


return profile();
Expand Down
4 changes: 3 additions & 1 deletion lib/treatments.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function storage (env, ctx) {
carbs: preBolusCarbs
};

if (obj.notes) pbTreat.notes = obj.notes;
if (obj.notes) {
pbTreat.notes = obj.notes;
}

api( ).insert(pbTreat, function() {
//nothing to do here
Expand Down
2 changes: 1 addition & 1 deletion lib/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function mgdlToMMOL(mgdl) {
function configure() {
return {
mgdlToMMOL: mgdlToMMOL
}
};
}

module.exports = configure;
10 changes: 0 additions & 10 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,6 @@ <h1 class="customTitle">Nightscout</h1>
<a id="useDefaults" class="pull-right" href="">Reset, and use defaults</a>
</div>

<fieldset class="experiments">
<legend>Experiments</legend>
<div style="text-align:center; vertical-align:middle;">
<b>Hamburger?</b><br />
<a class="glyphToggle tip" href="#" original-title="icon-menu"><i class="icon-menu"></i></a>
<a class="glyphToggle tip" href="#" original-title="icon-cog"><i class="icon-cog"></i></a>
</div>
</fieldset>

<fieldset id="about">
<legend>About</legend>
<div class="appName"></div>
Expand Down Expand Up @@ -266,6 +257,5 @@ <h1 class="customTitle">Nightscout</h1>
<script src="/bower_components/tipsy-jmalonzo/src/javascripts/jquery.tipsy.js"></script>
<script src="/js/ui-utils.js?v=0.7.0"></script>
<script src="/js/client.js?v=0.7.0"></script>
<script src="/js/experiments.js"></script>
</body>
</html>
23 changes: 14 additions & 9 deletions static/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
var lookbackTime = (lookback + 2) * FIVE_MINS_IN_MS + 2 * ONE_MIN_IN_MS;
nowData = nowData.filter(function(d) {
return d.date.getTime() >= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS - lookbackTime &&
d.date.getTime() <= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS
d.date.getTime() <= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS;
});

// sometimes nowData contains duplicates. uniq it.
Expand Down Expand Up @@ -505,7 +505,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
.attr('r', function (d) { return dotRadius(d.type); });

if (badData.length > 0) {
console.warn("Bad Data: isNaN(sgv)", badData);
console.warn('Bad Data: isNaN(sgv)', badData);
}

return sel;
Expand Down Expand Up @@ -974,7 +974,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
.attr('r', function (d) { return d.type == 'mbg' ? 4 : 2; });

if (badData.length > 0) {
console.warn("Bad Data: isNaN(sgv)", badData);
console.warn('Bad Data: isNaN(sgv)', badData);
}

return sel;
Expand Down Expand Up @@ -1121,7 +1121,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
console.info('found mismatched glucose units, converting ' + treatment.units + ' into ' + browserSettings.units, treatment);
if (treatment.units == 'mmol') {
//BG is in mmol and display in mg/dl
treatmentGlucose = Math.round(treatment.glucose * 18)
treatmentGlucose = Math.round(treatment.glucose * 18);
} else {
//BG is in mg/dl and display in mmol
treatmentGlucose = scaleBg(treatment.glucose);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
R3 = R2 + 8 / scale;

if (isNaN(R1) || isNaN(R3) || isNaN(R3)) {
console.warn("Bad Data: Found isNaN value in treatment", treatment);
console.warn('Bad Data: Found isNaN value in treatment', treatment);
return;
}

Expand All @@ -1172,8 +1172,13 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
arc_data[0].outlineOnly = !treatment.carbs;
arc_data[2].outlineOnly = !treatment.insulin;

if (treatment.carbs > 0) arc_data[1].element = Math.round(treatment.carbs) + ' g';
if (treatment.insulin > 0) arc_data[3].element = Math.round(treatment.insulin * 100) / 100 + ' U';
if (treatment.carbs > 0) {
arc_data[1].element = Math.round(treatment.carbs) + ' g';
}

if (treatment.insulin > 0) {
arc_data[3].element = Math.round(treatment.insulin * 100) / 100 + ' U';
}

var arc = d3.svg.arc()
.innerRadius(function (d) { return 5 * d.inner; })
Expand Down Expand Up @@ -1205,8 +1210,8 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
});
var arcs = treatmentDots.append('path')
.attr('class', 'path')
.attr('fill', function (d, i) { if (d.outlineOnly) return 'transparent'; else return d.color; })
.attr('stroke-width', function (d) {if (d.outlineOnly) return 1; else return 0; })
.attr('fill', function (d, i) { return d.outlineOnly ? 'transparent' : d.color; })
.attr('stroke-width', function (d) { return d.outlineOnly ? 1 : 0; })
.attr('stroke', function (d) { return d.color; })
.attr('id', function (d, i) { return 's' + i; })
.attr('d', arc);
Expand Down
28 changes: 0 additions & 28 deletions static/js/experiments.js

This file was deleted.

8 changes: 4 additions & 4 deletions static/js/ui-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function isTouch() {

function closeDrawer(id, callback) {
openDraw = null;
$("html, body").animate({ scrollTop: 0 });
$('html, body').animate({ scrollTop: 0 });
$(id).animate({right: '-300px'}, 300, function () {
$(id).css('display', 'none');
if (callback) { callback(); }
Expand All @@ -166,7 +166,7 @@ function toggleDrawer(id, openCallback, closeCallback) {
if (openDraw) {
closeDrawer(openDraw, callback);
} else {
callback()
callback();
}
}

Expand Down Expand Up @@ -242,7 +242,7 @@ function showNotification(note, type) {
}

function showLocalstorageError() {
var msg = '<b>Settings are disabled.</b><br /><br />Please enable cookies so you may customize your Nightscout site.'
var msg = '<b>Settings are disabled.</b><br /><br />Please enable cookies so you may customize your Nightscout site.';
$('.browserSettings').html('<legend>Settings</legend>'+msg+'');
$('#save').hide();
}
Expand Down Expand Up @@ -373,7 +373,7 @@ $('#notification').click(function(event) {

$('#save').click(function(event) {
function checkedPluginNames() {
var checkedPlugins = []
var checkedPlugins = [];
$('#show-plugins input:checked').each(function eachPluginCheckbox(index, checkbox) {
checkedPlugins.push($(checkbox).val());
});
Expand Down
Loading

0 comments on commit 320565b

Please sign in to comment.