Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@buildingsblock/core

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@buildingsblock/core - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2-alpha1

40

lib/stratas/index.js

@@ -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.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,20 +228,38 @@ 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 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));
});
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2);
};
var budget = _lodash.default.orderBy(x.budget, ['at'], ['desc'])[0].value;
exports.calcAverageContingencyReserveFundPerOperatingBudget = calcAverageContingencyReserveFundPerOperatingBudget;
return new _decimal.Decimal(contingencyReserveFund).dividedBy(budget);
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;
});
if (!stratasWithContingencyReserveFundContributions.length) return null;
var metrics = stratasWithContingencyReserveFundContributions.map(function (x) {
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));
});
return (0, _utils.toFixed)((0, _utils.average)(metrics), 2);
};
exports.calcAverageContingencyReserveFundPerBudget = calcAverageContingencyReserveFundPerBudget;
exports.calcAverageContingencyReserveFundContributionsPerOperatingBudget = calcAverageContingencyReserveFundContributionsPerOperatingBudget;

@@ -327,6 +345,4 @@ var createSchema = function createSchema(Mongoose) {

calcContingencyReserveFundContributionsPerSquareFoot: calcContingencyReserveFundContributionsPerSquareFoot,
calcBudget: calcBudget,
calcContingencyReserveFund: calcContingencyReserveFund,
calcContingencyReserveFundContributions: calcContingencyReserveFundContributions,
calcAverageContingencyReserveFundPerBudget: calcAverageContingencyReserveFundPerBudget,
calcAverageContingencyReserveFundContributionsPerOperatingBudget: calcAverageContingencyReserveFundContributionsPerOperatingBudget,
calcAverageContingencyReserveFundPerOperatingBudget: calcAverageContingencyReserveFundPerOperatingBudget,
calcAverageSalesTurnoverRate: calcAverageSalesTurnoverRate,

@@ -333,0 +349,0 @@ createSchema: createSchema

{
"name": "@buildingsblock/core",
"version": "0.1.1",
"version": "0.1.2-alpha1",
"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,
calcAverageContingencyReserveFundPerOperatingBudget,
calcAverageContingencyReserveFundContributionsPerOperatingBudget,
calcAverageContingencyReserveFundPerBudget,
calcAverageSalesTurnoverRate,

@@ -42,6 +40,6 @@ } from '../../src/stratas'

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 = [

@@ -160,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: [],
},

@@ -178,3 +176,3 @@ {

{
repairAndMaintenanceBudget: [{ value: 20000 }],
contingencyReserveFundContributions: [{ value: 20000 }],
area: { total: 1000 },

@@ -255,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' }],
},

@@ -276,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' }],
},

@@ -290,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')

@@ -302,9 +303,12 @@ t.is(emptyStrataResult, null, 'should return average budget per sqft for past year')

test('calcContingencyReserveFundContributions', (t) => {
test('calcAverageContingencyReserveFundContributionsPerOperatingBudget', (t) => {
const stratas = [
{
contingencyReserveFundContributions: [{ value: 70000, at: '2018-01-11' }, { value: 20000, 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: 40000 }],
contingencyReserveFundContributions: [{ value: 3000, at: '2018-05-11' }],
budget: [{ value: 20000, at: '2018-05-11' }],
},

@@ -314,58 +318,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: 4000, at: '2018-05-11' }],
budget: [{ value: 20000, at: '2018-01-11' }, { value: 20000, at: '2018-05-11' }],
},

@@ -376,51 +333,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,

@@ -432,22 +340,11 @@ },

const result = calcBudget(stratas)
const oneStrataResult = calcBudget(oneStrata)
const nullStrataResult = calcBudget(nullStrata)
const emptyStrataResult = calcBudget(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.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, 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')
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc