@buildingsblock/core
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageContingencyReserveFundContributionsPerBudget = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundContributions = exports.calcContingencyReserveFundPerSquareFoot = exports.calcContingencyReserveFund = exports.calcBudgetPerSquareFoot = exports.calcBudget = exports.calcRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
exports.default = exports.calcAverageContingencyReserveFundContributionsPerOperatingBudget = exports.calcAverageContingencyReserveFundPerOperatingBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundContributions = exports.calcContingencyReserveFundPerSquareFoot = exports.calcContingencyReserveFund = exports.calcBudgetPerSquareFoot = exports.calcBudget = exports.calcRepairAndMaintenanceBudgetPerSquareFoot = void 0; | ||
@@ -166,3 +166,3 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
return x.contingencyReserveFundContributions.length; | ||
return x.contingencyReserveFundContributions && x.contingencyReserveFundContributions.length; | ||
}).filter(function (x) { | ||
@@ -228,15 +228,16 @@ return x.area.total; | ||
var calcAverageContingencyReserveFundPerBudget = function calcAverageContingencyReserveFundPerBudget(stratas) { | ||
var calcAverageContingencyReserveFundPerOperatingBudget = function calcAverageContingencyReserveFundPerOperatingBudget(stratas) { | ||
var stratasWithContingencyReserveFund = stratas.filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}).filter(function (x) { | ||
return x.contingencyReserveFund && x.contingencyReserveFund.length; | ||
}).filter(function (x) { | ||
return x.budget && x.budget.length; | ||
return x.contingencyReserveFundContributions && x.contingencyReserveFundContributions.length; | ||
}); | ||
if (!stratasWithContingencyReserveFund.length) return null; | ||
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); | ||
var contingencyReserveFund = new _decimal.Decimal(_lodash.default.orderBy(x.contingencyReserveFund, ['at'], ['desc'])[0].value); | ||
var contingencyReserveFundContributions = new _decimal.Decimal(_lodash.default.orderBy(x.contingencyReserveFundContributions, ['at'], ['desc'])[0].value); | ||
var budget = new _decimal.Decimal(_lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value); | ||
return new _decimal.Decimal(contingencyReserveFund).dividedBy(budget.minus(contingencyReserveFundContributions)); | ||
}); | ||
@@ -246,17 +247,15 @@ return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
exports.calcAverageContingencyReserveFundPerBudget = calcAverageContingencyReserveFundPerBudget; | ||
exports.calcAverageContingencyReserveFundPerOperatingBudget = calcAverageContingencyReserveFundPerOperatingBudget; | ||
var calcAverageContingencyReserveFundContributionsPerBudget = function calcAverageContingencyReserveFundContributionsPerBudget(stratas) { | ||
var calcAverageContingencyReserveFundContributionsPerOperatingBudget = function calcAverageContingencyReserveFundContributionsPerOperatingBudget(stratas) { | ||
var stratasWithContingencyReserveFundContributions = stratas.filter(function (x) { | ||
return x.budget && x.budget.length; | ||
}).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); | ||
var contingencyReserveFundContributions = new _decimal.Decimal(_lodash.default.orderBy(x.contingencyReserveFundContributions, ['at'], ['desc'])[0].value); | ||
var budget = new _decimal.Decimal(_lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value); | ||
return new _decimal.Decimal(contingencyReserveFundContributions).dividedBy(budget.minus(contingencyReserveFundContributions)); | ||
}); | ||
@@ -266,3 +265,3 @@ return (0, _utils.toFixed)((0, _utils.average)(metrics), 2); | ||
exports.calcAverageContingencyReserveFundContributionsPerBudget = calcAverageContingencyReserveFundContributionsPerBudget; | ||
exports.calcAverageContingencyReserveFundContributionsPerOperatingBudget = calcAverageContingencyReserveFundContributionsPerOperatingBudget; | ||
@@ -348,4 +347,4 @@ var createSchema = function createSchema(Mongoose) { | ||
calcContingencyReserveFundContributionsPerSquareFoot: calcContingencyReserveFundContributionsPerSquareFoot, | ||
calcAverageContingencyReserveFundContributionsPerBudget: calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageContingencyReserveFundPerBudget: calcAverageContingencyReserveFundPerBudget, | ||
calcAverageContingencyReserveFundContributionsPerOperatingBudget: calcAverageContingencyReserveFundContributionsPerOperatingBudget, | ||
calcAverageContingencyReserveFundPerOperatingBudget: calcAverageContingencyReserveFundPerOperatingBudget, | ||
calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, | ||
@@ -352,0 +351,0 @@ createSchema: createSchema |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Core code base for Eli", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -9,4 +9,4 @@ import test from 'ava' | ||
calcAverageContingencyReserveFundPerBudget, | ||
calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageContingencyReserveFundPerOperatingBudget, | ||
calcAverageContingencyReserveFundContributionsPerOperatingBudget, | ||
@@ -40,6 +40,6 @@ calcAverageSalesTurnoverRate, | ||
t.is(data.min, 12.62, 'should ignore min CRF/sqft of stratas') | ||
t.is(data.max, 33.23, 'should ignore max CRF/sqft of stratas') | ||
t.is(data.max, 53.83, 'should ignore max CRF/sqft of stratas') | ||
}) | ||
test.only('calcBudgetPerSquareFoot', (t) => { | ||
test('calcBudgetPerSquareFoot', (t) => { | ||
const stratas = [ | ||
@@ -158,11 +158,11 @@ { | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
contingencyReserveFundContributions: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
area: { total: 1000 }, | ||
}, | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 40000 }], | ||
contingencyReserveFundContributions: [{ value: 40000 }], | ||
area: { total: 100 }, | ||
}, | ||
{ | ||
repairAndMaintenanceBudget: [], | ||
contingencyReserveFundContributions: [], | ||
}, | ||
@@ -176,3 +176,3 @@ { | ||
{ | ||
repairAndMaintenanceBudget: [{ value: 20000 }], | ||
contingencyReserveFundContributions: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
@@ -253,11 +253,13 @@ }, | ||
test('calcAverageContingencyReserveFundPerBudget', (t) => { | ||
test.only('calcAverageContingencyReserveFundPerOperatingBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
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' }], | ||
contingencyReserveFund: [{ value: 2000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
contingencyReserveFundContributions: [{ value: 2000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
contingencyReserveFund: [{ value: 3000, at: '2018-05-11' }], | ||
contingencyReserveFundContributions: [{ value: 2000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-05-11' }], | ||
}, | ||
@@ -274,4 +276,5 @@ { | ||
{ | ||
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: 70000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
contingencyReserveFundContributions: [{ value: 2000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
@@ -288,9 +291,9 @@ ] | ||
const result = calcAverageContingencyReserveFundPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerBudget(emptyStrata) | ||
const result = calcAverageContingencyReserveFundPerOperatingBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundPerOperatingBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundPerOperatingBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundPerOperatingBudget(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(result, 0.22, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 0.25, 'should return average budget per sqft for past year') | ||
t.is(nullStrataResult, null, 'should return average budget per sqft for past year') | ||
@@ -301,11 +304,11 @@ t.is(emptyStrataResult, null, 'should return average budget per sqft for past year') | ||
test('calcAverageContingencyReserveFundContributionsPerBudget', (t) => { | ||
test('calcAverageContingencyReserveFundContributionsPerOperatingBudget', (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: 2000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFundContributions: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
contingencyReserveFundContributions: [{ value: 3000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-05-11' }], | ||
}, | ||
@@ -322,4 +325,4 @@ { | ||
{ | ||
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' }], | ||
contingencyReserveFundContributions: [{ value: 70000, at: '2018-01-11' }, { value: 4000, at: '2018-05-11' }], | ||
budget: [{ value: 20000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
@@ -336,11 +339,11 @@ ] | ||
const result = calcAverageContingencyReserveFundContributionsPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(emptyStrata) | ||
const result = calcAverageContingencyReserveFundContributionsPerOperatingBudget(stratas, t.log) | ||
const oneStrataResult = calcAverageContingencyReserveFundContributionsPerOperatingBudget(oneStrata, t.log) | ||
const nullStrataResult = calcAverageContingencyReserveFundContributionsPerOperatingBudget(nullStrata, t.log) | ||
const emptyStrataResult = calcAverageContingencyReserveFundContributionsPerOperatingBudget(emptyStrata, t.log) | ||
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(result, 0.21, 'should return average budget per sqft for past year') | ||
t.is(oneStrataResult, 0.25, '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
384948
702