Comparing version 1.0.3 to 1.0.5
@@ -54,3 +54,3 @@ 'use strict'; | ||
var zScores = _lodash2.default.mapValues(dataItem, function (dataValue, dataKey) { | ||
if (_lodash2.default.isNumber(dataValue)) { | ||
if (_lodash2.default.isNumber(dataValue) && _this2.data[dataKey]) { | ||
var difference = dataValue - _this2.data[dataKey].mean; | ||
@@ -57,0 +57,0 @@ return difference / _this2.data[dataKey].stdDev; |
{ | ||
"name": "z-score", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/zscore.js", |
@@ -32,3 +32,3 @@ import _ from 'lodash' | ||
const zScores = _.mapValues(dataItem, (dataValue, dataKey) => { | ||
if(_.isNumber(dataValue)) { | ||
if(_.isNumber(dataValue) && this.data[dataKey]) { | ||
const difference = dataValue - this.data[dataKey].mean | ||
@@ -35,0 +35,0 @@ return difference / this.data[dataKey].stdDev |
@@ -31,2 +31,13 @@ export const staticTemperature = [ | ||
} | ||
] | ||
export const dataSetWithNullItems = [ | ||
{ | ||
temperature: -5, | ||
pressure: null | ||
}, | ||
{ | ||
temperature: -4, | ||
pressure: null | ||
} | ||
] |
import ZScore from '../src/zscore' | ||
import { staticTemperature, increasingTemperature } from './fixtures/weather' | ||
import { staticTemperature, increasingTemperature, dataSetWithNullItems } from './fixtures/weather' | ||
import { expect } from 'chai' | ||
@@ -86,4 +86,14 @@ | ||
it('should calculate the correct z scores with null values in dataset', () => { | ||
zScore.train(dataSetWithNullItems) | ||
expect(zScore.calculate({ | ||
temperature: -10, | ||
pressure: 101280 | ||
})).to.deep.equal({ | ||
temperature: -11 | ||
}) | ||
}) | ||
}) | ||
}) |
10327
253