<NME> server.js
<BEF> /*
* cgm-remote-monitor - web app to broadcast cgm readings
* Copyright (C) 2014 Nightscout contributors.  See the COPYRIGHT file
* at the root directory of this distribution and at
* https://github.com/nightscout/cgm-remote-monitor/blob/master/COPYRIGHT
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// Description: Basic web server to display data from Dexcom G4.  Requires a database that contains
// the Dexcom SGV data.
'use strict';

require('./lib/server/server');


        // compute current loss
        var avgLoss = 0;
        for (var i = 0; i <= 6; i++) {
            avgLoss += 1 / 6 * Math.pow(log10(predicted[i].y / 120), 2);
        }

        if (avgLoss > alarms['urgent_alarm'].threshold) {

<MSG> don't blow up if there's bad data and no prediction

<DFF> @@ -235,8 +235,9 @@ function loadData() {
 
         // compute current loss
         var avgLoss = 0;
-        for (var i = 0; i <= 6; i++) {
-            avgLoss += 1 / 6 * Math.pow(log10(predicted[i].y / 120), 2);
+        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) {

{'addition_count': 3, 'commit_subject': "don't blow up if there's bad data and no prediction", 'deletion_count': 2, 'file_extension': '.js', 'lang': 'js', 'license': 'agpl-3.0', 'repo_name': 'nightscout/cgm-remote-monitor'}