fable 3.1.18 → 3.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/source/services/Fable-Service-ExpressionParser/Fable-Service-ExpressionParser-FunctionMap.json +5 -0
- package/source/services/Fable-Service-Math.js +4 -2
- package/source/services/Fable-Service-Utility.js +14 -0
- package/test/ExpressionParser_tests.js +25 -0
- package/test/Utility_tests.js +17 -0
package/package.json
CHANGED
|
@@ -129,6 +129,11 @@
|
|
|
129
129
|
"Address": "fable.Utility.getInternalValueByHash"
|
|
130
130
|
},
|
|
131
131
|
|
|
132
|
+
"createarrayfromabsolutevalues": {
|
|
133
|
+
"Name": "Create Array from Absolute Values",
|
|
134
|
+
"Address": "fable.Utility.createArrayFromAbsoluteValues"
|
|
135
|
+
},
|
|
136
|
+
|
|
132
137
|
"flatten": {
|
|
133
138
|
"Name": "flatten an array of values",
|
|
134
139
|
"Address": "fable.Utility.flattenArrayOfSolverInputs"
|
|
@@ -668,8 +668,10 @@ class FableServiceMath extends libFableServiceBase
|
|
|
668
668
|
return tmpSortedHistogram;
|
|
669
669
|
}
|
|
670
670
|
|
|
671
|
-
cleanValueArray(pValueArray)
|
|
671
|
+
cleanValueArray(pValueArray, pRemoveZeroes)
|
|
672
672
|
{
|
|
673
|
+
let tmpRemoveZeroes = (typeof (pRemoveZeroes) === 'undefined') ? false : pRemoveZeroes;
|
|
674
|
+
|
|
673
675
|
if (!Array.isArray(pValueArray))
|
|
674
676
|
{
|
|
675
677
|
return [];
|
|
@@ -679,7 +681,7 @@ class FableServiceMath extends libFableServiceBase
|
|
|
679
681
|
for (let i = 0; i < pValueArray.length; i++)
|
|
680
682
|
{
|
|
681
683
|
let tmpValue = this.parsePrecise(pValueArray[i], NaN);
|
|
682
|
-
if (!isNaN(tmpValue))
|
|
684
|
+
if (!isNaN(tmpValue) && (!tmpRemoveZeroes || (tmpValue != "0")))
|
|
683
685
|
{
|
|
684
686
|
tmpCleanedArray.push(tmpValue);
|
|
685
687
|
}
|
|
@@ -486,6 +486,20 @@ class FableServiceUtility extends libFableServiceBase
|
|
|
486
486
|
};
|
|
487
487
|
return pInputArray.flatMap(tmpArrayFlattener);
|
|
488
488
|
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Take a set of arbitrary parameters and build an array from them
|
|
492
|
+
* @returns {Array} - An array built from the absolute values of the parameters
|
|
493
|
+
*/
|
|
494
|
+
createArrayFromAbsoluteValues()
|
|
495
|
+
{
|
|
496
|
+
let tmpArray = [];
|
|
497
|
+
for (let i = 0; i < arguments.length; i++)
|
|
498
|
+
{
|
|
499
|
+
tmpArray.push(arguments[i]);
|
|
500
|
+
}
|
|
501
|
+
return tmpArray;
|
|
502
|
+
}
|
|
489
503
|
}
|
|
490
504
|
|
|
491
505
|
module.exports = FableServiceUtility;
|
|
@@ -398,6 +398,13 @@ suite
|
|
|
398
398
|
// Now through the solver
|
|
399
399
|
|
|
400
400
|
let _Parser = testFable.instantiateServiceProviderIfNotExists('ExpressionParser');
|
|
401
|
+
|
|
402
|
+
testFable.AppData.Value1 = "100"; // Comment
|
|
403
|
+
testFable.AppData.Value2 = "-80.5"; // Comment
|
|
404
|
+
testFable.AppData.Value3 = "10000"; // Comment
|
|
405
|
+
testFable.AppData.Value4 = "-333.333"; // Comment
|
|
406
|
+
testFable.AppData.Value5 = "0"; // Comment
|
|
407
|
+
|
|
401
408
|
let tmpResultsObject = {};
|
|
402
409
|
let tmpDestinationObject = {};
|
|
403
410
|
|
|
@@ -405,6 +412,24 @@ suite
|
|
|
405
412
|
_Parser.solve('AggregationResult = aggregationHistogram("AppData.Cities", "state", "population")', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
406
413
|
_Parser.solve('PopSum = sum(flatten(AppData.Cities[].population, AppData.Cities[].latitude))', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
407
414
|
|
|
415
|
+
//_Parser.solve('MadeUpValueArray = ROUND(AVG(createarrayfromabsolutevalues(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
416
|
+
//Expect(tmpDestinationObject.MadeUpValueArray).to.equal('600');
|
|
417
|
+
_Parser.solve('MadeUpValueArray = ROUND(AVG(createarrayfromabsolutevalues(AppData.Value1, AppData.Value2, AppData.Value3, AppData.Value4, AppData.Value5)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
418
|
+
Expect(tmpDestinationObject.MadeUpValueArray).to.equal('1937.23');
|
|
419
|
+
|
|
420
|
+
_Parser.solve('MadeUpValueArray = ROUND(AVG(cleanvaluearray(createarrayfromabsolutevalues(AppData.Value1, AppData.Value2, AppData.Value3, AppData.Value4, AppData.Value5), 1)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
421
|
+
Expect(tmpDestinationObject.MadeUpValueArray).to.equal('2421.54');
|
|
422
|
+
|
|
423
|
+
// _Parser.solve('MadeUpValueArray = ROUND(AVG(createarrayfromabsolutevalues(100, -80.5, 10000, -333.333, 0)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
424
|
+
// Expect(tmpDestinationObject.MadeUpValueArray).to.equal('600');
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
_Parser.solve('MadeUpValueArray = ROUND(AVG(createarrayfromabsolutevalues(100, 10, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
428
|
+
Expect(tmpDestinationObject.MadeUpValueArray).to.equal('550.83');
|
|
429
|
+
|
|
430
|
+
// _Parser.solve('MadeUpValueArray = ROUND(AVG(createarrayfromabsolutevalues(-5, 5, 0, -10, 10, -25, 25, -50, 50)),2)', testFable, tmpResultsObject, false, tmpDestinationObject);
|
|
431
|
+
// Expect(tmpDestinationObject.MadeUpValueArray).to.equal('25');
|
|
432
|
+
|
|
408
433
|
|
|
409
434
|
Expect(tmpDestinationObject.DistributionResult.Alabama).to.equal(12);
|
|
410
435
|
Expect(tmpDestinationObject.DistributionResult.Colorado).to.equal(21);
|
package/test/Utility_tests.js
CHANGED
|
@@ -411,6 +411,23 @@ suite
|
|
|
411
411
|
return fDone();
|
|
412
412
|
}
|
|
413
413
|
);
|
|
414
|
+
test
|
|
415
|
+
(
|
|
416
|
+
'createArrayFromAbsoluteValues works as expected',
|
|
417
|
+
function(fDone)
|
|
418
|
+
{
|
|
419
|
+
testFable = new libFable();
|
|
420
|
+
|
|
421
|
+
let tmpResult = testFable.services.Utility.createArrayFromAbsoluteValues(0,3,5,9);
|
|
422
|
+
Expect(tmpResult).to.be.an('array');
|
|
423
|
+
Expect(tmpResult.length).to.equal(4);
|
|
424
|
+
Expect(tmpResult[0]).to.equal(0);
|
|
425
|
+
Expect(tmpResult[1]).to.equal(3);
|
|
426
|
+
Expect(tmpResult[2]).to.equal(5);
|
|
427
|
+
Expect(tmpResult[3]).to.equal(9);
|
|
428
|
+
return fDone();
|
|
429
|
+
}
|
|
430
|
+
)
|
|
414
431
|
}
|
|
415
432
|
);
|
|
416
433
|
}
|