fable 3.1.50 → 3.1.51

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.50",
3
+ "version": "3.1.51",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -119,6 +119,30 @@
119
119
  "Name": "Mode",
120
120
  "Address": "fable.Math.modePrecise"
121
121
  },
122
+ "var": {
123
+ "Name": "Variance (Sample)",
124
+ "Address": "fable.Math.variancePrecise"
125
+ },
126
+ "vara": {
127
+ "Name": "Variance (Sample)",
128
+ "Address": "fable.Math.variancePrecise"
129
+ },
130
+ "varp": {
131
+ "Name": "Variance (Population)",
132
+ "Address": "fable.Math.populationVariancePrecise"
133
+ },
134
+ "stdev": {
135
+ "Name": "Standard Deviation (Sample)",
136
+ "Address": "fable.Math.standardDeviationPrecise"
137
+ },
138
+ "stdeva": {
139
+ "Name": "Standard Deviation (Sample)",
140
+ "Address": "fable.Math.standardDeviationPrecise"
141
+ },
142
+ "stdevp": {
143
+ "Name": "Standard Deviation (Population)",
144
+ "Address": "fable.Math.populationStandardDeviationPrecise"
145
+ },
122
146
  "round": {
123
147
  "Name": "Round",
124
148
  "Address": "fable.Math.roundPrecise"
@@ -1438,7 +1438,7 @@ class FableServiceMath extends libFableServiceBase
1438
1438
  /**
1439
1439
  * Calculates the precise mean of a given value set.
1440
1440
  *
1441
- * @param {Array<number>} pValueSet - The array of values to calculate the mean.
1441
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the mean.
1442
1442
  * @returns {string} The precise mean value as a string.
1443
1443
  */
1444
1444
  meanPrecise(pValueSet)
@@ -1455,8 +1455,8 @@ class FableServiceMath extends libFableServiceBase
1455
1455
  /**
1456
1456
  * Calculates the average of an array of values precisely.
1457
1457
  *
1458
- * @param {Array<number>} pValueSet - The array of values to calculate the average of.
1459
- * @returns {number} The precise average of the values.
1458
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the average of.
1459
+ * @returns {string} The precise average of the values.
1460
1460
  */
1461
1461
  averagePrecise(pValueSet)
1462
1462
  {
@@ -1527,6 +1527,68 @@ class FableServiceMath extends libFableServiceBase
1527
1527
  return tmpModeValueSet;
1528
1528
  }
1529
1529
 
1530
+ /**
1531
+ * Calculates the variance of a given value set using precise mode calculation.
1532
+ *
1533
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the variance from.
1534
+ * @param {boolean} [pIsPopulation=false] - Whether to calculate population variance (true) or sample variance (false).
1535
+ *
1536
+ * @return {string} - The variance of the given value set.
1537
+ */
1538
+ variancePrecise(pValueSet, pIsPopulation = false)
1539
+ {
1540
+ let tmpValueSet = pValueSet;
1541
+ if (!Array.isArray(tmpValueSet) && typeof tmpValueSet === 'object')
1542
+ {
1543
+ tmpValueSet = Object.keys(tmpValueSet).map((pKey) => tmpValueSet[pKey]);
1544
+ }
1545
+ const tmpMeanValue = this.meanPrecise(tmpValueSet);
1546
+ const tmpVarianceSum = tmpValueSet.reduce((pAccumulator, pValue) =>
1547
+ {
1548
+ const tmpDiff = this.subtractPrecise(pValue, tmpMeanValue);
1549
+ const tmpSquaredDiff = this.multiplyPrecise(tmpDiff, tmpDiff);
1550
+ return this.addPrecise(pAccumulator, tmpSquaredDiff);
1551
+ }, '0.0');
1552
+ return this.dividePrecise(tmpVarianceSum, pIsPopulation ? tmpValueSet.length : tmpValueSet.length - 1);
1553
+ }
1554
+
1555
+ /**
1556
+ * Calculates the variance of a given population of values using precise mode calculation.
1557
+ *
1558
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the variance from.
1559
+ *
1560
+ * @return {string} - The variance of the given value set.
1561
+ */
1562
+ populationVariancePrecise(pValueSet)
1563
+ {
1564
+ return this.variancePrecise(pValueSet, true);
1565
+ }
1566
+
1567
+ /**
1568
+ * Calculates the standard deviation of a given value set using precise mode calculation.
1569
+ *
1570
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the standard deviation from.
1571
+ * @param {boolean} [pIsPopulation=false] - Whether to calculate population variance (true) or sample variance (false).
1572
+ *
1573
+ * @return {string} - The standard deviation of the given value set.
1574
+ */
1575
+ standardDeviationPrecise(pValueSet, pIsPopulation = false)
1576
+ {
1577
+ return this.sqrtPrecise(this.variancePrecise(pValueSet, pIsPopulation));
1578
+ }
1579
+
1580
+ /**
1581
+ * Calculates the standard deviation of a given population of values using precise mode calculation.
1582
+ *
1583
+ * @param {Array<string|number>} pValueSet - The array of values to calculate the standard deviation from.
1584
+ *
1585
+ * @return {string} - The standard deviation of the given value set.
1586
+ */
1587
+ populationStandardDeviationPrecise(pValueSet)
1588
+ {
1589
+ return this.standardDeviationPrecise(pValueSet, true);
1590
+ }
1591
+
1530
1592
  /**
1531
1593
  * Performs an nth degree polynomial regression on the given data points.
1532
1594
  *
@@ -347,6 +347,8 @@ suite
347
347
  Expect(_Parser.solve("TotalCost = MEAN(ItemCosts)", { "ItemCosts": [100, 200, 50, 45, 5] })).to.equal("80");
348
348
  Expect(_Parser.solve("TotalCost = MEDIAN(ItemCosts)", { "ItemCosts": [100, 200, 50, 45, 5] })).to.equal("50");
349
349
  Expect(_Parser.solve("TotalCost = COUNT(ItemCosts)", { "ItemCosts": [100, 200, 50, 45, 5] })).to.equal("5");
350
+ Expect(Number(_Parser.solve("StDev = STDEV(Values)", { "Values": [1,2,3,4,5,6,7,8,9,10,11] }))).to.be.closeTo(3.3166, 0.0001);
351
+ Expect(Number(_Parser.solve("StDevP = STDEVP(Values)", { "Values": [1,2,3,4,5,6,7,8,9,10,11] }))).to.be.closeTo(3.1623, 0.0001);
350
352
 
351
353
  _Parser.fable.AppData = {
352
354
  Teams: [
package/test/Math_test.js CHANGED
@@ -316,6 +316,31 @@ suite
316
316
 
317
317
  let tmpChocoSizes = testManyfest.getValueAtAddress(_ChocoData, 'files[].size');
318
318
 
319
+ Expect(testFable.Math.variancePrecise([1, 2, 3])).to.equal('1');
320
+ Expect(Number(testFable.Math.populationVariancePrecise([1, 2, 3]))).to.be.closeTo(0.6667, 0.0001);
321
+ Expect(testFable.Math.standardDeviationPrecise([1, 2, 3])).to.equal('1');
322
+ Expect(Number(testFable.Math.populationStandardDeviationPrecise([1, 2, 3]))).to.be.closeTo(0.8165, 0.0001);
323
+ try
324
+ {
325
+ testFable.Math.variancePrecise([1]);
326
+ Expect.fail('Expected error for sample variance with single value');
327
+ }
328
+ catch (pError)
329
+ {
330
+ Expect(pError).to.be.an.instanceof(Error);
331
+ Expect(pError.message).to.equal('[big.js] Division by zero');
332
+ }
333
+ try
334
+ {
335
+ testFable.Math.standardDeviationPrecise([1]);
336
+ Expect.fail('Expected error for sample standard deviation with single value');
337
+ }
338
+ catch (pError)
339
+ {
340
+ Expect(pError).to.be.an.instanceof(Error);
341
+ Expect(pError.message).to.equal('[big.js] Division by zero');
342
+ }
343
+
319
344
  Expect(testFable.Math.maxPrecise(tmpChocoSizes)).to.equal("31625216");
320
345
  Expect(testFable.Math.minPrecise(tmpChocoSizes)).to.equal("620");
321
346
  Expect(testFable.Math.sumPrecise(tmpChocoSizes)).to.equal("36431778");
@@ -324,6 +349,8 @@ suite
324
349
  Expect(testFable.Math.medianPrecise(tmpChocoSizes)).to.equal("5993");
325
350
  // Since the file sizes are all different, this is just the whole list.
326
351
  Expect(testFable.Math.modePrecise(tmpChocoSizes)).to.deep.equal(["620","838","1371","3383","3503","4093","4951","5993","6843","7481","8388","31141","101114","2248166","2378677","31625216","NaN"]);
352
+ Expect(Number(testFable.Math.standardDeviationPrecise(tmpChocoSizes))).to.be.closeTo(7635456.5390, 0.0001);
353
+ Expect(Number(testFable.Math.populationStandardDeviationPrecise(tmpChocoSizes))).to.be.closeTo(7407480.8965, 0.0001);
327
354
 
328
355
  Expect(testFable.Math.maxPrecise([100, 101, 400, "20", "dog"])).to.equal("400");
329
356
  Expect(testFable.Math.modePrecise([100, 20, 101, 400, "20", "dog"])).to.deep.equal(["20"]);
@@ -351,6 +378,8 @@ suite
351
378
  Expect(testFable.Math.meanPrecise([1,2,3,4,5,6,7,8,9,10,11])).to.equal('6');
352
379
  Expect(testFable.Math.medianPrecise([1,2,3,4,5,6,7,8,9,10,11])).to.equal('6');
353
380
  Expect(testFable.Math.modePrecise([1,2,3,4,5,6,7,8,9,10,11])).to.deep.equal(['1','2','3','4','5','6','7','8','9','10','11']);
381
+ Expect(Number(testFable.Math.standardDeviationPrecise([1,2,3,4,5,6,7,8,9,10,11]))).to.be.closeTo(3.3166, 0.0001);
382
+ Expect(Number(testFable.Math.populationStandardDeviationPrecise([1,2,3,4,5,6,7,8,9,10,11]))).to.be.closeTo(3.1623, 0.0001);
354
383
 
355
384
  return fDone();
356
385
  }