@buildingsblock/core
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcSalesTurnoverRate = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcSalesTurnoverRate = exports.calcContingencyReserveFundPerSquareFoot = void 0; | ||
@@ -34,41 +34,2 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var calcAverageSalesTurnoverRate = function calcAverageSalesTurnoverRate(stratas) { | ||
var stratasWithSalesAndUnits = stratas.filter(function (x) { | ||
return x.units; | ||
}).filter(function (x) { | ||
return x.sales.length; | ||
}); | ||
var metricsPastYear = stratasWithSalesAndUnits.map(function (x) { | ||
var sales = x.sales, | ||
units = x.units; | ||
var _$orderBy$ = _lodash.default.orderBy(sales, ['at'], ['desc'])[0], | ||
pastYear = _$orderBy$.pastYear, | ||
twoYearsAgo = _$orderBy$.twoYearsAgo, | ||
threeYearsAgo = _$orderBy$.threeYearsAgo; | ||
return { | ||
pastYear: new _decimal.Decimal(pastYear).dividedBy(units).toNumber(), | ||
twoYearsAgo: new _decimal.Decimal(twoYearsAgo).dividedBy(units).toNumber(), | ||
threeYearsAgo: new _decimal.Decimal(threeYearsAgo).dividedBy(units).toNumber() | ||
}; | ||
}); | ||
var pastYearAverage = (0, _utils.toFixed)((0, _utils.average)(metricsPastYear.map(function (x) { | ||
return x.pastYear; | ||
})), 2); | ||
var twoYearsAgoAverage = (0, _utils.toFixed)((0, _utils.average)(metricsPastYear.map(function (x) { | ||
return x.twoYearsAgo; | ||
})), 2); | ||
var threeYearsAgoAverage = (0, _utils.toFixed)((0, _utils.average)(metricsPastYear.map(function (x) { | ||
return x.threeYearsAgo; | ||
})), 2); | ||
return { | ||
pastYear: pastYearAverage, | ||
twoYearsAgo: twoYearsAgoAverage, | ||
threeYearsAgo: threeYearsAgoAverage | ||
}; | ||
}; | ||
exports.calcAverageSalesTurnoverRate = calcAverageSalesTurnoverRate; | ||
var calcSalesTurnoverRate = function calcSalesTurnoverRate(strata) { | ||
@@ -88,2 +49,24 @@ var latestSales = _lodash.default.orderBy(strata.sales, ['at'], ['desc'])[0]; | ||
var calcAverageSalesTurnoverRate = function calcAverageSalesTurnoverRate(stratas) { | ||
var stratasWithSalesAndUnits = stratas.filter(function (x) { | ||
return x.units; | ||
}).filter(function (x) { | ||
return x.sales.length; | ||
}); | ||
var salesTurnOverRates = stratasWithSalesAndUnits.map(calcSalesTurnoverRate); | ||
return { | ||
pastYear: (0, _utils.toFixed)((0, _utils.average)(salesTurnOverRates.map(function (x) { | ||
return x.pastYear; | ||
})), 2), | ||
twoYearsAgo: (0, _utils.toFixed)((0, _utils.average)(salesTurnOverRates.map(function (x) { | ||
return x.twoYearsAgo; | ||
})), 2), | ||
threeYearsAgo: (0, _utils.toFixed)((0, _utils.average)(salesTurnOverRates.map(function (x) { | ||
return x.threeYearsAgo; | ||
})), 2) | ||
}; | ||
}; | ||
exports.calcAverageSalesTurnoverRate = calcAverageSalesTurnoverRate; | ||
var createSchema = function createSchema(Mongoose) { | ||
@@ -90,0 +73,0 @@ var StrataSchema = new Mongoose.Schema({ |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Core code base for Buildingsblock", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -35,19 +35,3 @@ import test from 'ava' | ||
test('calcAverageSalesTurnoverRate', (t) => { | ||
const strata = [{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}, { | ||
sales: [{ pastYear: 15, twoYearsAgo: 40, threeYearsAgo: 35 }], | ||
units: 200, | ||
}] | ||
const result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.09, 'should return average turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.13, 'should return average turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.19, 'should return average turnover rate for three years ago') | ||
}) | ||
test('calcSalesTurnoverRate', (t) => { | ||
test.only('calcSalesTurnoverRate', (t) => { | ||
const strata = { | ||
@@ -58,3 +42,3 @@ sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
const result = calcSalesTurnoverRate(strata) | ||
let result = calcSalesTurnoverRate(strata) | ||
@@ -64,2 +48,31 @@ t.is(result.pastYear, 0.1, 'should return turnover rate for past year') | ||
t.is(result.threeYearsAgo, 0.2, 'should return turnover rate for three years ago') | ||
result = calcSalesTurnoverRate({ sales: [], units: 100 }) | ||
t.is(result, null, 'should return null if strata has not sales') | ||
}) | ||
test('calcAverageSalesTurnoverRate', (t) => { | ||
const strata = [ | ||
{ | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
}, | ||
{ | ||
sales: [{ pastYear: 15, twoYearsAgo: 40, threeYearsAgo: 35 }], | ||
units: 200, | ||
}, | ||
{ | ||
sales: [], | ||
}, | ||
{ | ||
units: null, | ||
}, | ||
] | ||
const result = calcAverageSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.09, 'should return average turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.13, 'should return average turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.19, 'should return average turnover rate for three years ago') | ||
t.is(result.pastYear, 0.9, 'should only include properties with sales and units') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45213
10
229