@buildingsblock/core
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcSalesTurnoverRate = exports.calcContingencyReserveFundPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageSalesTurnoverRate = exports.calcSalesTurnoverRate = exports.calcContingencyReserveFundPerBudget = exports.calcContingencyReserveFundPerSquareFoot = exports.calcAverageBudgetPerSquareFoot = exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
@@ -17,2 +17,41 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var calcAverageRepairAndMaintenanceBudgetPerSquareFoot = function calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) { | ||
var stratasWithBudget = stratas.filter(function (x) { | ||
return x.repairAndMaintenanceBudget && x.repairAndMaintenanceBudget.length; | ||
}).filter(function (x) { | ||
return x.area && x.area.total; | ||
}); | ||
var metrics = stratasWithBudget.map(function (x) { | ||
var _$orderBy = _lodash.default.orderBy(x.repairAndMaintenanceBudget, ['at'], ['desc']), | ||
value = _$orderBy.value; | ||
var total = x.area.total; | ||
return new _decimal.Decimal(value).dividedBy(total); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics.map(function (x) { | ||
return x; | ||
})), 2); | ||
}; | ||
exports.calcAverageRepairAndMaintenanceBudgetPerSquareFoot = calcAverageRepairAndMaintenanceBudgetPerSquareFoot; | ||
var calcAverageBudgetPerSquareFoot = function calcAverageBudgetPerSquareFoot(stratas) { | ||
var stratasWithBudget = stratas.filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}).filter(function (x) { | ||
return x.area && x.area.total; | ||
}); | ||
var metrics = stratasWithBudget.map(function (x) { | ||
var value = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
var total = x.area.total; | ||
return new _decimal.Decimal(value).dividedBy(total); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics.map(function (x) { | ||
return x; | ||
})), 2); | ||
}; | ||
exports.calcAverageBudgetPerSquareFoot = calcAverageBudgetPerSquareFoot; | ||
var calcContingencyReserveFundPerSquareFoot = function calcContingencyReserveFundPerSquareFoot(stratas) { | ||
@@ -35,2 +74,20 @@ var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
var calcContingencyReserveFundPerBudget = function calcContingencyReserveFundPerBudget(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
return x.contingencyReserveFund && x.contingencyReserveFund.length; | ||
}).filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}); | ||
var metrics = stratasWithContingencyReserveFund.map(function (x) { | ||
var contingencyReserveFund = _lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value; | ||
var budget = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFund).dividedBy(budget); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
}; | ||
exports.calcContingencyReserveFundPerBudget = calcContingencyReserveFundPerBudget; | ||
var calcSalesTurnoverRate = function calcSalesTurnoverRate(strata) { | ||
@@ -143,2 +200,3 @@ var latestSales = _lodash.default.orderBy(strata.sales, ['at'], ['desc'])[0]; | ||
var _default = { | ||
calcAverageRepairAndMaintenanceBudgetPerSquareFoot: calcAverageRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcContingencyReserveFundPerSquareFoot: calcContingencyReserveFundPerSquareFoot, | ||
@@ -145,0 +203,0 @@ calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Core code base for Buildingsblock", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -7,2 +7,5 @@ import test from 'ava' | ||
calcSalesTurnoverRate, | ||
calcAverageBudgetPerSquareFoot, | ||
calcAverageRepairAndMaintenanceBudgetPerSquareFoot, | ||
calcContingencyReserveFundPerBudget, | ||
} from '../../src/stratas' | ||
@@ -77,1 +80,146 @@ | ||
}) | ||
test('calcAverageBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
{ | ||
budget: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
area: { total: 1000 }, | ||
}, | ||
{ | ||
budget: [{ value: 40000 }], | ||
area: { total: 100 }, | ||
}, | ||
{ | ||
budget: [], | ||
}, | ||
{ | ||
area: null, | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
budget: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
area: null, | ||
}, | ||
] | ||
const emptyStrata = [ | ||
{ | ||
budget: [], | ||
}, | ||
] | ||
const result = calcAverageBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageBudgetPerSquareFoot(emptyStrata) | ||
t.is(result, 210, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
}) | ||
test('calcAverageRepairAndMaintenanceBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [], | ||
}, | ||
{ | ||
budget: null, | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 2000, at: '2018-01-11' }, { value: 1000, at: '2018-05-11' }], | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
budget: null, | ||
}, | ||
] | ||
const emptyStrata = [ | ||
{ | ||
contingencyReserveFund: [], | ||
}, | ||
] | ||
const result = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(stratas) | ||
const oneStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(oneStrata) | ||
const nullStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(nullStrata) | ||
const emptyStrataResult = calcAverageRepairAndMaintenanceBudgetPerSquareFoot(emptyStrata) | ||
t.is(result, 210, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 20, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
}) | ||
test('calcContingencyReserveFundPerBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
area: { total: 1000 }, | ||
}, | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 40000 }], | ||
area: { total: 100 }, | ||
}, | ||
{ | ||
repairAndMaintenanceBudget: [], | ||
}, | ||
{ | ||
area: null, | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
area: null, | ||
}, | ||
] | ||
const emptyStrata = [ | ||
{ | ||
repairAndMaintenanceBudget: [], | ||
}, | ||
] | ||
const result = calcContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcContingencyReserveFundPerBudget(emptyStrata) | ||
t.is(result, 210, 'should return average contingency reserve fund per budget for past year') | ||
t.is(oneStrataResult, 20, 'should return average contingency reserve fund per budget for past year') | ||
t.is(nullStrataResult, null, 'should return average contingency reserve fund per budget for past year') | ||
t.is(emptyStrataResult, null, 'should return average contingency reserve fund per budget for past year') | ||
}) |
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
371425
12
407