@buildingsblock/core
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.calcAverageContingencyReserveFundPerBudget = exports.calcAverageSalesTurnoverRate = exports.calcContingencyReserveFundContributionsPerSquareFoot = exports.calcContingencyReserveFundContributions = exports.calcContingencyReserveFundPerSquareFoot = exports.calcContingencyReserveFund = exports.calcBudgetPerSquareFoot = exports.calcBudget = 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; | ||
@@ -246,2 +246,21 @@ var _lodash = _interopRequireDefault(require("lodash")); | ||
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) { | ||
@@ -326,5 +345,3 @@ var StrataSchema = new Mongoose.Schema({ | ||
calcContingencyReserveFundContributionsPerSquareFoot: calcContingencyReserveFundContributionsPerSquareFoot, | ||
calcBudget: calcBudget, | ||
calcContingencyReserveFund: calcContingencyReserveFund, | ||
calcContingencyReserveFundContributions: calcContingencyReserveFundContributions, | ||
calcAverageContingencyReserveFundContributionsPerBudget: calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageContingencyReserveFundPerBudget: calcAverageContingencyReserveFundPerBudget, | ||
@@ -331,0 +348,0 @@ calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate, |
{ | ||
"name": "@buildingsblock/core", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Core code base for Eli", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -9,7 +9,5 @@ import test from 'ava' | ||
calcBudget, | ||
calcContingencyReserveFund, | ||
calcContingencyReserveFundContributions, | ||
calcAverageContingencyReserveFundPerBudget, | ||
calcAverageContingencyReserveFundContributionsPerBudget, | ||
calcAverageContingencyReserveFundPerBudget, | ||
calcAverageSalesTurnoverRate, | ||
@@ -296,9 +294,12 @@ } from '../../src/stratas' | ||
test('calcContingencyReserveFundContributions', (t) => { | ||
test('calcAverageContingencyReserveFundContributionsPerBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFundContributions: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
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: 40000 }], | ||
contingencyReserveFundContributions: [{ value: 20000, at: '2018-05-11' }], | ||
budget: [{ value: 1000, at: '2018-05-11' }], | ||
}, | ||
@@ -308,58 +309,11 @@ { | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
contingencyReserveFundContributions: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
budget: null, | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
contingencyReserveFundContributions: null, | ||
}, | ||
] | ||
const emptyStrata = [] | ||
const result = calcContingencyReserveFundContributions(stratas) | ||
const oneStrataResult = calcContingencyReserveFundContributions(oneStrata) | ||
const nullStrataResult = calcContingencyReserveFundContributions(nullStrata) | ||
const emptyStrataResult = calcContingencyReserveFundContributions(emptyStrata) | ||
t.is(result.average, 30000, 'should return average for past year') | ||
t.is(result.min, 20000, 'should return min for past year') | ||
t.is(result.max, 40000, 'should return max for past year') | ||
t.is(oneStrataResult.average, 20000, 'should return average for past year') | ||
t.is(oneStrataResult.min, 20000, 'should return min for past year') | ||
t.is(oneStrataResult.max, 20000, 'should return max for past year') | ||
t.is(nullStrataResult.average, null, 'should return average for past year') | ||
t.is(nullStrataResult.min, null, 'should return min for past year') | ||
t.is(nullStrataResult.max, null, 'should return max for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max for past year') | ||
}) | ||
test('calcContingencyReserveFund', (t) => { | ||
const stratas = [ | ||
{ | ||
contingencyReserveFund: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
contingencyReserveFund: [{ value: 40000 }], | ||
}, | ||
{ | ||
contingencyReserveFund: [], | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
contingencyReserveFund: [{ value: 20000 }], | ||
area: { total: 1000 }, | ||
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' }], | ||
}, | ||
@@ -370,51 +324,2 @@ ] | ||
{ | ||
contingencyReserveFund: null, | ||
}, | ||
] | ||
const emptyStrata = [] | ||
const result = calcContingencyReserveFund(stratas) | ||
const oneStrataResult = calcContingencyReserveFund(oneStrata) | ||
const nullStrataResult = calcContingencyReserveFund(nullStrata) | ||
const emptyStrataResult = calcContingencyReserveFund(emptyStrata) | ||
t.is(result.average, 30000, 'should return average for past year') | ||
t.is(result.min, 20000, 'should return min for past year') | ||
t.is(result.max, 40000, 'should return max for past year') | ||
t.is(oneStrataResult.average, 20000, 'should return average for past year') | ||
t.is(oneStrataResult.min, 20000, 'should return min for past year') | ||
t.is(oneStrataResult.max, 20000, 'should return max for past year') | ||
t.is(nullStrataResult.average, null, 'should return average for past year') | ||
t.is(nullStrataResult.min, null, 'should return min for past year') | ||
t.is(nullStrataResult.max, null, 'should return max for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max for past year') | ||
}) | ||
test('calcBudget', (t) => { | ||
const stratas = [ | ||
{ | ||
budget: [{ value: 70000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }], | ||
}, | ||
{ | ||
budget: [{ value: 40000 }], | ||
}, | ||
{ | ||
budget: [], | ||
}, | ||
] | ||
const oneStrata = [ | ||
{ | ||
budget: [{ value: 20000 }], | ||
}, | ||
] | ||
const nullStrata = [ | ||
{ | ||
budget: null, | ||
@@ -426,22 +331,11 @@ }, | ||
const result = calcBudget(stratas) | ||
const oneStrataResult = calcBudget(oneStrata) | ||
const nullStrataResult = calcBudget(nullStrata) | ||
const emptyStrataResult = calcBudget(emptyStrata) | ||
const result = calcAverageContingencyReserveFundContributionsPerBudget(stratas) | ||
const oneStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(oneStrata) | ||
const nullStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(nullStrata) | ||
const emptyStrataResult = calcAverageContingencyReserveFundContributionsPerBudget(emptyStrata) | ||
t.is(result.average, 30000, 'should return average for past year') | ||
t.is(result.min, 20000, 'should return min for past year') | ||
t.is(result.max, 40000, 'should return max for past year') | ||
t.is(oneStrataResult.average, 20000, 'should return average for past year') | ||
t.is(oneStrataResult.min, 20000, 'should return min for past year') | ||
t.is(oneStrataResult.max, 20000, 'should return max for past year') | ||
t.is(nullStrataResult.average, null, 'should return average for past year') | ||
t.is(nullStrataResult.min, null, 'should return min for past year') | ||
t.is(nullStrataResult.max, null, 'should return max for past year') | ||
t.is(emptyStrataResult.average, null, 'should return average for past year') | ||
t.is(emptyStrataResult.min, null, 'should return min for past year') | ||
t.is(emptyStrataResult.max, null, 'should return max 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') | ||
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
383800
696