@buildingsblock/core
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcSalesTurnoverRate = exports.calcContingencyReserveFundPerSquareFoot = void 0; | ||
exports.default = exports.calcSalesTurnoverRate = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundPerSquareFoot = void 0; | ||
@@ -34,3 +34,3 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var calcSalesTurnoverRate = function calcSalesTurnoverRate(stratas) { | ||
var calcAverageSalesTurnoverRate = function calcAverageSalesTurnoverRate(stratas) { | ||
var stratasWithSalesAndUnits = stratas.filter(function (x) { | ||
@@ -72,2 +72,16 @@ return x.units; | ||
exports.calcAverageSalesTurnoverRate = calcAverageSalesTurnoverRate; | ||
var calcSalesTurnoverRate = function calcSalesTurnoverRate(strata) { | ||
var latestSales = _lodash.default.orderBy(strata.sales, ['at'], ['desc'])[0]; | ||
var units = strata.units; | ||
if (!latestSales || !units) return null; | ||
return { | ||
pastYear: latestSales.pastYear / units, | ||
twoYearsAgo: latestSales.twoYearsAgo / units, | ||
threeYearsAgo: latestSales.threeYearsAgo / units | ||
}; | ||
}; | ||
exports.calcSalesTurnoverRate = calcSalesTurnoverRate; | ||
@@ -147,2 +161,3 @@ | ||
calcContingencyReserveFundPerSquareFoot: calcContingencyReserveFundPerSquareFoot, | ||
calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, | ||
calcSalesTurnoverRate: calcSalesTurnoverRate, | ||
@@ -149,0 +164,0 @@ createSchema: createSchema |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Core code base for Buildingsblock", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -5,2 +5,3 @@ import test from 'ava' | ||
calcContingencyReserveFundPerSquareFoot, | ||
calcAverageSalesTurnoverRate, | ||
calcSalesTurnoverRate, | ||
@@ -35,3 +36,3 @@ } from '../../src/stratas' | ||
test('calcSalesTurnoverRate', (t) => { | ||
test('calcAverageSalesTurnoverRate', (t) => { | ||
const strata = [{ | ||
@@ -45,7 +46,20 @@ sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
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) => { | ||
const strata = { | ||
sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
units: 100, | ||
} | ||
const result = calcSalesTurnoverRate(strata) | ||
t.is(result.pastYear, 0.09, 'should return turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.13, 'should return turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.19, 'should return turnover rate for three years ago') | ||
t.is(result.pastYear, 0.1, 'should return turnover rate for past year') | ||
t.is(result.twoYearsAgo, 0.05, 'should return turnover rate for two years ago') | ||
t.is(result.threeYearsAgo, 0.2, 'should return turnover rate for three years ago') | ||
}) |
Sorry, the diff of this file is not supported yet
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
364808
232