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

Alarm / Threshold updates (and some other UI updates...) #305

Merged
merged 22 commits into from
Jan 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bd06646
read BG thresholds and alarm types from ENV and make them available t…
Dec 19, 2014
3e745f9
read BG thresholds from api; refactor init so that it happend after w…
Dec 19, 2014
b38fdab
emit alarms based on ENV ALARM_TYPES (simple and predict)
Dec 19, 2014
82d70a1
updated BG_HIGH default to 240
Dec 19, 2014
deb5e81
cleanup
Dec 19, 2014
da1ab49
preseve current behavior is new BG_* and ALARM_TYPES ENV isn't set
Dec 19, 2014
0df8650
draw 2 extra lines for the high/low thresholds; dispay normal alarms …
Dec 20, 2014
86c5af7
changed default of BG_HIGH to 260
Dec 20, 2014
f59b2bf
some more display adjustments for short-landscape mode
Dec 20, 2014
e66acdd
make an errorCode based alarm count as a low
Dec 20, 2014
86f9249
move tooltip div declatration up so it can be referenced as before
Dec 20, 2014
e9f1fb1
added tooltip for SGVs and MBGs in the focus area; different color ou…
Dec 21, 2014
bf87678
now using an updated version of @rnpenguin and @ldesboro treatment re…
Dec 21, 2014
fd9f02c
calc BG based on time of treatment, if it's not set; draw outlines fo…
Dec 22, 2014
5963534
added some validation and warnings when BG thresholds aren't stacked …
Dec 22, 2014
ae535ed
adjust size of focus dots based on screen size
Dec 22, 2014
eb3c63f
adjust the radius of the focus dots on transistion also (for rotate, …
Dec 23, 2014
de7ddfa
added some text-shadow for carb/insulin amount to make them easier to…
Dec 23, 2014
38f755e
move the context NOW line when scrolling
Dec 24, 2014
ac2f6a4
draw non-insulin/carbs treatment circles on the trendline too, if the…
Dec 27, 2014
53d4997
Nightscout NOT NightScout
Dec 27, 2014
bfcbda8
corrected some issues found in code review; improved use of media que…
Jan 5, 2015
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
@@ -1,4 +1,4 @@
cgm-remote-monitor (a.k.a. NightScout)
cgm-remote-monitor (a.k.a. Nightscout)
======================================

[![Build Status](https://travis-ci.org/nightscout/cgm-remote-monitor.png)](https://travis-ci.org/nightscout/cgm-remote-monitor)
Expand Down
41 changes: 41 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ function config ( ) {
env.api_secret = shasum.digest('hex');
}

env.thresholds = {
bg_high: readIntENV('BG_HIGH', 260)
, bg_target_top: readIntENV('BG_TARGET_TOP', 180)
, bg_target_bottom: readIntENV('BG_TARGET_BOTTOM', 80)
, bg_low: readIntENV('BG_LOW', 55)
};

//NOTE: using +/- 1 here to make the thresholds look visibly wrong in the UI
// if all thresholds were set to the same value you should see 4 lines stacked right on top of each other
if (env.thresholds.bg_target_bottom >= env.thresholds.bg_target_top) {
console.warn('BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ') was >= BG_TARGET_TOP(' + env.thresholds.bg_target_top + ')');
env.thresholds.bg_target_bottom = env.thresholds.bg_target_top - 1;
console.warn('BG_TARGET_BOTTOM is now ' + env.thresholds.bg_target_bottom);
}

if (env.thresholds.bg_target_top <= env.thresholds.bg_target_bottom) {
console.warn('BG_TARGET_TOP(' + env.thresholds.bg_target_top + ') was <= BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ')');
env.thresholds.bg_target_top = env.thresholds.bg_target_bottom + 1;
console.warn('BG_TARGET_TOP is now ' + env.thresholds.bg_target_top);
}

if (env.thresholds.bg_low >= env.thresholds.bg_target_bottom) {
console.warn('BG_LOW(' + env.thresholds.bg_low + ') was >= BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ')');
env.thresholds.bg_low = env.thresholds.bg_target_bottom - 1;
console.warn('BG_LOW is now ' + env.thresholds.bg_low);
}

if (env.thresholds.bg_high <= env.thresholds.bg_target_top) {
console.warn('BG_HIGH(' + env.thresholds.bg_high + ') was <= BG_TARGET_TOP(' + env.thresholds.bg_target_top + ')');
env.thresholds.bg_high = env.thresholds.bg_target_top + 1;
console.warn('BG_HIGH is now ' + env.thresholds.bg_high);
}

//if any of the BG_* thresholds are set, default to "simple" otherwise default to "predict" to preserve current behavior
var thresholdsSet = readIntENV('BG_HIGH') || readIntENV('BG_TARGET_TOP') || readIntENV('BG_TARGET_BOTTOM') || readIntENV('BG_LOW');
env.alarm_types = readENV('ALARM_TYPES') || (thresholdsSet ? "simple" : "predict");

// For pushing notifications to Pushover.
env.pushover_api_token = readENV('PUSHOVER_API_TOKEN');
env.pushover_user_key = readENV('PUSHOVER_USER_KEY') || readENV('PUSHOVER_GROUP_KEY');
Expand All @@ -97,6 +134,10 @@ function config ( ) {
return env;
}

function readIntENV(varName, defaultValue) {
return parseInt(readENV(varName)) || defaultValue;
}

function readENV(varName, defaultValue) {
//for some reason Azure uses this prefix, maybe there is a good reason
var value = process.env['CUSTOMCONNSTR_' + varName]
Expand Down
3 changes: 3 additions & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function create (env, entries, settings, treatments, devicestatus) {

app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));

app.thresholds = env.thresholds;
app.alarm_types = env.alarm_types;

// Start setting up routes
if (app.enabled('api')) {
// experiments
Expand Down
2 changes: 2 additions & 0 deletions lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function configure (app, wares) {
, units: app.get('units')
, head: wares.get_head( )
, version: app.get('version')
, thresholds: app.thresholds
, alarm_types: app.alarm_types
, name: app.get('name')};
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';
return res.format({
Expand Down
46 changes: 35 additions & 11 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ function update() {
obj.y = element.mbg;
obj.x = element.date;
obj.d = element.dateString;
obj.device = element.device;
mbgData.push(obj);
} else if (element.sgv) {
var obj = {};
obj.y = element.sgv;
obj.x = element.date;
obj.d = element.dateString;
obj.device = element.device;
obj.direction = directionToChar(element.direction);
cgmData.push(obj);
}
Expand Down Expand Up @@ -238,20 +240,42 @@ function loadData() {
emitData( );
}

// compute current loss
var avgLoss = 0;
var size = Math.min(predicted.length - 1, 6);
for (var j = 0; j <= size; j++) {
avgLoss += 1 / size * Math.pow(log10(predicted[j].y / 120), 2);
var emitAlarmType = null;

if (env.alarm_types.indexOf("simple") > -1) {
var lastBG = actual[actualLength].y;

if (lastBG > env.thresholds.bg_high) {
emitAlarmType = 'urgent_alarm';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not conflate urgent and high.
This should be a high alarm type not urgent, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jason stipulated two high thresholds: a "high end of target range"
threshold (default 180), which would trigger a standard alarm, and a
"urgent high" threshold (default 240) that would trigger an urgent alarm.
Similar on the low end (80 and 55 IIRC).

Does that paradigm make sense to you? Do you have any suggestions for a
better way to approach it?

On Fri, Dec 19, 2014 at 3:56 PM, Ben West notifications@github.com wrote:

In lib/websocket.js
#305 (diff)
:

@@ -238,20 +238,42 @@ function loadData() {
emitData( );
}

  •    // compute current loss
    
  •    var avgLoss = 0;
    
  •    var size = Math.min(predicted.length - 1, 6);
    
  •    for (var j = 0; j <= size; j++) {
    
  •        avgLoss += 1 / size \* Math.pow(log10(predicted[j].y / 120), 2);
    
  •    var emitAlarmType = null;
    
  •    if (env.alarm_types.indexOf("simple") > -1) {
    
  •        var lastBG = actual[actualLength].y;
    
  •        if (lastBG > env.thresholds.bg_high) {
    
  •            emitAlarmType = 'urgent_alarm';
    

Let's not conflate urgent and high.
This should be a high alarm type not urgent, right?


Reply to this email directly or view it on GitHub
https://github.com/nightscout/cgm-remote-monitor/pull/305/files#r22136552
.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was attempting to not change the current normal/urgent alarms levels, since adding extra levels will make snooze more complicated.

There are still issues to work out with the High/Low setting on the client. The easy thing to do is make them say Urgent/Normal, but I don't think thats what people want.

} else if (lastBG > env.thresholds.bg_target_top) {
emitAlarmType = 'alarm';
} else if (lastBG < env.thresholds.bg_low) {
emitAlarmType = 'urgent_alarm';
} else if (lastBG < env.thresholds.bg_target_bottom) {
emitAlarmType = 'alarm';
}
}

if (avgLoss > alarms['urgent_alarm'].threshold) {
emitAlarm('urgent_alarm');
} else if (avgLoss > alarms['alarm'].threshold) {
emitAlarm('alarm');
} else if (errorCode) {
emitAlarm('urgent_alarm');
if (!emitAlarmType && env.alarm_types.indexOf("predict") > -1) {
// compute current loss
var avgLoss = 0;
var size = Math.min(predicted.length - 1, 6);
for (var j = 0; j <= size; j++) {
avgLoss += 1 / size * Math.pow(log10(predicted[j].y / 120), 2);
}

if (avgLoss > alarms['urgent_alarm'].threshold) {
emitAlarmType = 'urgent_alarm';
} else if (avgLoss > alarms['alarm'].threshold) {
emitAlarmType = 'alarm';
}
}

if (errorCode) {
emitAlarmType = 'urgent_alarm';
}

if (emitAlarmType) emitAlarm(emitAlarmType);
}
}
function is_different (actual, predicted, mbg, treatment, errorCode) {
Expand Down
2 changes: 1 addition & 1 deletion static/css/drawer.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
position: absolute;
margin-top: 45px;
right: -200px;
width: 200px;
width: 300px;
top: 0;
z-index: 1;
}
Expand Down
95 changes: 59 additions & 36 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ body {
}

#bgButton {
background: #ff2035;
background: yellow;
border: 2px solid #DDD;
border-right: 2px solid #ccc;
border-bottom: 2px solid #ccc;
Expand All @@ -176,6 +176,10 @@ body {
-ms-user-select: none;
}

#bgButton.urgent {
background: red;
}

.bgButton:active {
background: #850406;
border: 2px solid #999;
Expand Down Expand Up @@ -220,32 +224,6 @@ div.tooltip {
padding: 0 0 10px 0;
}

@media (max-height: 480px) {
html body #toolbar {
float: right;
height: auto;
}

#toolbar h1 {
display: none;
}

html body .container {
top: 15px;
padding-bottom: 20px;
}
html body .container .status {
font-size: 70%;
}

html body #chartContainer {
top: 130px;
}
html body #chartContainer svg {
height: calc(100vh - 130px);
}
}

/* Large desktop */
@media (min-width: 980px) {
.content {
Expand All @@ -261,7 +239,7 @@ div.tooltip {

@media (max-width: 800px) {
#chartContainer {
font-size: 115%;
font-size: 80%;
}

.bgStatus {
Expand All @@ -286,12 +264,9 @@ div.tooltip {
.dropdown-menu {
font-size: 60% !important;
}
#currentTime {
font-size: 65%;
padding: 0;
}
#lastEntry {
font-size: 65%;

.container .status {
font-size: 70%;
}

#chartContainer {
Expand Down Expand Up @@ -342,6 +317,10 @@ div.tooltip {
margin-left: 2vw;
width: 96vw;
}
.container .status {
font-size: 100% !important;
}

.time {
margin-bottom: 0.1em;
margin-top: -1em;
Expand All @@ -354,7 +333,7 @@ div.tooltip {
}
#currentTime {
display: inline;
font-size: 25%;
font-size: 25% !important;
font-weight: bold;
}
.timeOther {
Expand All @@ -363,10 +342,54 @@ div.tooltip {
}

#chartContainer {
font-size: 110%;
font-size: 110% !important;
top: 210px;
}
#chartContainer svg {
height: calc(100vh - (210px));
}
}

@media (max-height: 480px) {
#toolbar {
float: right;
height: auto !important;
}

#toolbar h1 {
display: none;
}

.container {
top: 15px;
padding-bottom: 20px;
}

#bgButton {
font-size: 70% !important;
}

#currentTime {
font-size: 85%;
}

#chartContainer {
top: 130px;
font-size: 80%;
}
#chartContainer svg {
height: calc(100vh - 130px);
}
}

@media (max-height: 480px) and (min-width: 400px) {
.container .status {
font-size: 70%;
}
}

@media (max-height: 480px) and (max-width: 400px) {
.container .status {
font-size: 80% !important;
}
}
8 changes: 5 additions & 3 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="/images/logomobile.png">
<title>NightScout</title>
<title>Nightscout</title>
<link href="/images/round1.png" rel="icon" id="favicon" type="image/png" />
<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.5.x-12-13" />
<link rel="stylesheet" type="text/css" href="/css/dropdown.css" />
Expand Down Expand Up @@ -76,8 +76,10 @@ <h1 class="customTitle">Nightscout</h1>
</dl>
<dl class="toggle">
<dt>Enable Alarms <a class="tip" original-title="When enabled the an alarm will sound."><i class="icon-help-circled"></i></a></dt>
<dd><input type="checkbox" name="alarmhigh-browser" id="alarmhigh-browser" /><label for="alarmhigh-browser">High Alarm</label></dd>
<dd><input type="checkbox" name="alarmlow-browser" id="alarmlow-browser" /><label for="alarmlow-browser">Low Alarm</label></dd>
<dd><input type="checkbox" id="alarm-urgenthigh-browser" /><label for="alarm-urgenthigh-browser">Urgent High Alarm</label></dd>
<dd><input type="checkbox" id="alarm-high-browser" /><label for="alarm-high-browser">High Alarm</label></dd>
<dd><input type="checkbox" id="alarm-low-browser" /><label for="alarm-low-browser">Low Alarm</label></dd>
<dd><input type="checkbox" id="alarm-urgentlow-browser" /><label for="alarm-urgentlow-browser">Urgent Low Alarm</label></dd>
</dl>
<dl class="toggle">
<dt>Night Mode <a class="tip" original-title="When enabled the page will be dimmed from 10pm - 6am."><i class="icon-help-circled"></i></a></dt>
Expand Down
Loading