@buildingsblock/core
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcSalesTurnoverRate = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageContingencyReserveFundPerSquareFoot = exports.calcAverageBudgetPerSquareFoot = exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageContingencyReserveFundPerSquareFoot = exports.calcAverageBudgetPerSquareFoot = exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
@@ -25,4 +25,3 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var metrics = stratasWithBudget.map(function (x) { | ||
var _$orderBy = _lodash.default.orderBy(x.repairAndMaintenanceBudget, ['at'], ['desc']), | ||
value = _$orderBy.value; | ||
var value = _lodash.default.orderBy(x.repairAndMaintenanceBudget, ['at'], ['desc'])[0].value; | ||
@@ -96,16 +95,2 @@ var total = x.area.total; | ||
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: new _decimal.Decimal(latestSales.pastYear).dividedBy(units).toNumber(), | ||
twoYearsAgo: new _decimal.Decimal(latestSales.twoYearsAgo).dividedBy(units).toNumber(), | ||
threeYearsAgo: new _decimal.Decimal(latestSales.threeYearsAgo).dividedBy(units).toNumber() | ||
}; | ||
}; | ||
exports.calcSalesTurnoverRate = calcSalesTurnoverRate; | ||
var calcAverageSalesTurnoverRate = function calcAverageSalesTurnoverRate(stratas) { | ||
@@ -118,3 +103,13 @@ var stratasWithSalesAndUnits = stratas.filter(function (x) { | ||
if (!stratasWithSalesAndUnits.length) return null; | ||
var salesTurnOverRates = stratasWithSalesAndUnits.map(calcSalesTurnoverRate); | ||
var salesTurnOverRates = stratasWithSalesAndUnits.map(function (x) { | ||
var latestSales = _lodash.default.orderBy(x.sales, ['at'], ['desc'])[0]; | ||
var units = x.units; | ||
if (!latestSales || !units) return null; | ||
return { | ||
pastYear: new _decimal.Decimal(latestSales.pastYear).dividedBy(units).toNumber(), | ||
twoYearsAgo: new _decimal.Decimal(latestSales.twoYearsAgo).dividedBy(units).toNumber(), | ||
threeYearsAgo: new _decimal.Decimal(latestSales.threeYearsAgo).dividedBy(units).toNumber() | ||
}; | ||
}); | ||
return { | ||
@@ -121,0 +116,0 @@ pastYear: (0, _utils.toFixed)((0, _utils.average)(salesTurnOverRates.map(function (x) { |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "Core code base for Buildingsblock", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -37,3 +37,3 @@ import test from 'ava' | ||
test.only('calcSalesTurnoverRate', (t) => { | ||
test('calcSalesTurnoverRate', (t) => { | ||
const strata = [{ | ||
@@ -77,3 +77,2 @@ sales: [{ pastYear: 10, twoYearsAgo: 5, threeYearsAgo: 20 }], | ||
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') | ||
}) | ||
@@ -125,6 +124,6 @@ | ||
test('calcAverageRepairAndMaintenanceBudgetPerSquareFoot', (t) => { | ||
test('calcAverageContingencyReserveFundPerBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 40000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
@@ -159,8 +158,8 @@ }, | ||
const result = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(emptyStrata) | ||
const result = calcAverageContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerBudget(emptyStrata) | ||
t.is(result, 210, 'should return average budget per sqft for past year') | ||
t.is(result, 30, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
@@ -172,3 +171,3 @@ t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
test('calcAverageContingencyReserveFundPerBudget', (t) => { | ||
test('calcAverageRepairAndMaintenanceBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
@@ -206,6 +205,6 @@ { | ||
const result = calcAverageContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerBudget(emptyStrata) | ||
const result = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(emptyStrata) | ||
@@ -212,0 +211,0 @@ t.is(result, 210, 'should return average contingency reserve fund per budget for past year') |
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
371549
396