@buildingsblock/core
Advanced tools
Comparing version 0.1.0 to 0.1.1-alpha01
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundPerSquareFoot = exports.calcBudgetPerSquareFoot = exports.calcRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageContingencyReserveFundContributionsPerBudget = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundContributions = exports.calcContingencyReserveFundPerSquareFoot = exports.calcContingencyReserveFund = exports.calcBudgetPerSquareFoot = exports.calcBudget = exports.calcRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
@@ -43,2 +43,25 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var calcBudget = function calcBudget(stratas) { | ||
var stratasWithBudget = stratas.filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}); | ||
if (!stratasWithBudget.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithBudget.map(function (x) { | ||
var value = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(value); | ||
}); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcBudget = calcBudget; | ||
var calcBudgetPerSquareFoot = function calcBudgetPerSquareFoot(stratas) { | ||
@@ -70,2 +93,25 @@ var stratasWithBudget = stratas.filter(function (x) { | ||
var calcContingencyReserveFund = function calcContingencyReserveFund(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
return x.contingencyReserveFund && x.contingencyReserveFund.length; | ||
}); | ||
if (!stratasWithContingencyReserveFund.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithContingencyReserveFund.map(function (x) { | ||
var contingencyReserveFund = _lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFund); | ||
}); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcContingencyReserveFund = calcContingencyReserveFund; | ||
var calcContingencyReserveFundPerSquareFoot = function calcContingencyReserveFundPerSquareFoot(stratas) { | ||
@@ -97,2 +143,25 @@ var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
var calcContingencyReserveFundContributions = function calcContingencyReserveFundContributions(stratas) { | ||
var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
return x.contingencyReserveFundContributions && x.contingencyReserveFundContributions.length; | ||
}); | ||
if (!stratasWithContingencyReserveFundContributions.length) return { | ||
average: null, | ||
min: null, | ||
max: null | ||
}; | ||
var metrics = stratasWithContingencyReserveFundContributions.map(function (x) { | ||
var contingencyReserveFundContributions = _lodash.default.orderBy(x.contingencyReserveFundContributions, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFundContributions); | ||
}); | ||
return { | ||
average: (0, _utils.toFixed)((0, _utils.average)(metrics), 2), | ||
min: (0, _utils.toFixed)((0, _utils.min)(metrics), 2), | ||
max: (0, _utils.toFixed)((0, _utils.max)(metrics), 2) | ||
}; | ||
}; | ||
exports.calcContingencyReserveFundContributions = calcContingencyReserveFundContributions; | ||
var calcContingencyReserveFundContributionsPerSquareFoot = function calcContingencyReserveFundContributionsPerSquareFoot(stratas) { | ||
@@ -180,2 +249,21 @@ var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
var calcAverageContingencyReserveFundContributionsPerBudget = function calcAverageContingencyReserveFundContributionsPerBudget(stratas) { | ||
var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
return x.contingencyReserveFundContributions && x.contingencyReserveFundContributions.length; | ||
}).filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}); | ||
if (!stratasWithContingencyReserveFundContributions.length) return null; | ||
var metrics = stratasWithContingencyReserveFundContributions.map(function (x) { | ||
var contingencyReserveFundContributions = _lodash.default.orderBy(x.contingencyReserveFundContributions, ['at'], ['desc'])[0].value; | ||
var budget = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value; | ||
return new _decimal.Decimal(contingencyReserveFundContributions).dividedBy(budget); | ||
}); | ||
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
}; | ||
exports.calcAverageContingencyReserveFundContributionsPerBudget = calcAverageContingencyReserveFundContributionsPerBudget; | ||
var createSchema = function createSchema(Mongoose) { | ||
@@ -260,2 +348,3 @@ var StrataSchema = new Mongoose.Schema({ | ||
calcContingencyReserveFundContributionsPerSquareFoot: calcContingencyReserveFundContributionsPerSquareFoot, | ||
calcAverageContingencyReserveFundContributionsPerBudget: calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageContingencyReserveFundPerBudget: calcAverageContingencyReserveFundPerBudget, | ||
@@ -262,0 +351,0 @@ calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.1.0", | ||
"version": "0.1.1-alpha01", | ||
"description": "Core code base for Eli", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -10,2 +10,4 @@ import test from 'ava' | ||
calcAverageContingencyReserveFundPerBudget, | ||
calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageSalesTurnoverRate, | ||
@@ -207,3 +209,2 @@ } from '../../src/stratas' | ||
test('calcSalesTurnoverRate', (t) => { | ||
@@ -293,1 +294,46 @@ const strata = [{ | ||
}) | ||
test('calcAverageContingencyReserveFundContributionsPerBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFundContributions: [{ 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' }], | ||
}, | ||
{ | ||
contingencyReserveFundContributions: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFundContributions: [], | ||
}, | ||
{ | ||
budget: null, | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
contingencyReserveFundContributions: [{ 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 = [] | ||
const result = calcAverageContingencyReserveFundContributionsPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(emptyStrata) | ||
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') | ||
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') | ||
}) |
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
383808
13
696