<commit_before>'use strict';

var _ = require('lodash')
  , moment = require('moment')
  , utils = require('../utils')();

function init() {

  function iob() {
    return iob;
  }

  iob.label = 'Insulin-on-Board';
  iob.pluginType = 'pill-major';

  iob.setProperties = function setProperties(sbx) {
    sbx.offerProperty('iob', function setIOB ( ) {
      return iob.calcTotal(sbx.data.treatments, sbx.data.profile, sbx.time);
    });
  };

  iob.calcTotal = function calcTotal(treatments, profile, time) {

    var totalIOB = 0
      , totalActivity = 0;

    if (!treatments) { return {}; }

    if (time === undefined) {
      time = Date.now();
    }

    var lastBolus = null;

    _.forEach(treatments, function eachTreatment(treatment) {
      if (treatment.mills < time) {
        var tIOB = iob.calcTreatment(treatment, profile, time);
        if (tIOB.iobContrib > 0) {
          lastBolus = treatment;
        }
        if (tIOB && tIOB.iobContrib) { totalIOB += tIOB.iobContrib; }
        if (tIOB && tIOB.activityContrib) { totalActivity += tIOB.activityContrib; }
      }
    });

    var display = utils.toFixed(totalIOB);
    return {
      iob: totalIOB<commit_msg>Calculate IOB for treatments that match the current timestamp<commit_after>'use strict';

var _ = require('lodash')
  , moment = require('moment')
  , utils = require('../utils')();

function init() {

  function iob() {
    return iob;
  }

  iob.label = 'Insulin-on-Board';
  iob.pluginType = 'pill-major';

  iob.setProperties = function setProperties(sbx) {
    sbx.offerProperty('iob', function setIOB ( ) {
      return iob.calcTotal(sbx.data.treatments, sbx.data.profile, sbx.time);
    });
  };

  iob.calcTotal = function calcTotal(treatments, profile, time) {

    var totalIOB = 0
      , totalActivity = 0;

    if (!treatments) { return {}; }

    if (time === undefined) {
      time = Date.now();
    }

    var lastBolus = null;

    _.forEach(treatments, function eachTreatment(treatment) {
      if (treatment.mills <= time) {
        var tIOB = iob.calcTreatment(treatment, profile, time);
        if (tIOB.iobContrib > 0) {
          lastBolus = treatment;
        }
        if (tIOB && tIOB.iobContrib) { totalIOB += tIOB.iobContrib; }
        if (tIOB && tIOB.activityContrib) { totalActivity += tIOB.activityContrib; }
      }
    });

    var display = utils.toFixed(totalIOB);
    return {
      iob: totalIOB
{'fraction_non_alphanumeric': 0.14179412980570483, 'fraction_numerical': 0.0024803637866887144, 'mean_word_length': 2.705972434915773, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3697149', 'n_tokens_mistral': 879, 'n_tokens_neox': 823, 'n_words': 169}