<commit_before>'use strict';

function init() {

  function delta() {
    return delta;
  }

  delta.label = 'BG Delta';
  delta.pluginType = 'pill-major';
  delta.pillFlip = true;

  delta.setProperties = function setProperties (sbx) {
    sbx.offerProperty('delta', function setDelta ( ) {
      return delta.calc(
        sbx.data.sgvs.length >= 2 ? sbx.data.sgvs[sbx.data.sgvs.length - 2].y : null
        , sbx.data.sgvs.length >= 1 ? sbx.data.sgvs[sbx.data.sgvs.length - 1].y : null
        , sbx
      );
    });
  };

  delta.updateVisualisation = function updateVisualisation (sbx) {
    var prop = sbx.properties.delta;
    sbx.pluginBase.updatePillText(delta, {
      value: prop.display
      , label: sbx.unitsLabel
    });
  };

  delta.calc = function calc(prevSVG, currentSGV, sbx) {
    var result = { display: null };

    if (!prevSVG || !currentSGV) { return result; }

    if (currentSGV < 40 || prevSVG < 40) { return result; }
    if (currentSGV > 400 || prevSVG > 400) { return result; }

    result.value = sbx.scaleBg(currentSGV) - sbx.scaleBg(prevSVG);
    result.display = (result.value >= 0 ? '+' : '') + result.value;

    return result;
  };

  return delta();

}

module.exports = init;<commit_msg>Fix delta rounding for mmol users to prevent values such as -0.2999999999997 from being shown<commit_after>'use strict';

function init() {

  function delta() {
    return delta;
  }

  delta.label = 'BG Delta';
  delta.pluginType = 'pill-major';
  delta.pillFlip = true;

  delta.setProperties = function setProperties (sbx) {
    sbx.offerProperty('delta', function setDelta ( ) {
      return delta.calc(
        sbx.data.sgvs.length >= 2 ? sbx.data.sgvs[sbx.data.sgvs.length - 2].y : null
        , sbx.data.sgvs.length >= 1 ? sbx.data.sgvs[sbx.data.sgvs.length - 1].y : null
        , sbx
      );
    });
  };

  delta.updateVisualisation = function updateVisualisation (sbx) {
    var prop = sbx.properties.delta;
    sbx.pluginBase.updatePillText(delta, {
      value: prop.display
      , label: sbx.unitsLabel
    });
  };

  delta.calc = function calc(prevSVG, currentSGV, sbx) {
    var result = { display: null };

    if (!prevSVG || !currentSGV) { return result; }

    if (currentSGV < 40 || prevSVG < 40) { return result; }
    if (currentSGV > 400 || prevSVG > 400) { return result; }

    result.value = sbx.roundBGToDisplayFormat(sbx.scaleBg(currentSGV) - sbx.scaleBg(prevSVG));
    result.display = (result.value >= 0 ? '+' : '') + result.value;

    return result;
  };

  return delta();

}

module.exports = init;
{'fraction_non_alphanumeric': 0.14524922118380063, 'fraction_numerical': 0.017133956386292833, 'mean_word_length': 2.811572700296736, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '5176043', 'n_tokens_mistral': 945, 'n_tokens_neox': 876, 'n_words': 189}