@sjcrh/proteinpaint-shared 2.87.0 → 2.87.1
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/src/descriptive.stats.js +10 -10
- package/src/roundValue.js +8 -2
package/package.json
CHANGED
package/src/descriptive.stats.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { roundValueAuto } from './roundValue.js'
|
|
2
2
|
|
|
3
3
|
/* This file generates summary statistics on any given array of numbers*/
|
|
4
4
|
|
|
@@ -42,15 +42,15 @@ export default function summaryStats(array) {
|
|
|
42
42
|
return {
|
|
43
43
|
values: [
|
|
44
44
|
{ id: 'total', label: 'Total', value: n },
|
|
45
|
-
{ id: 'min', label: 'Minimum', value:
|
|
46
|
-
{ id: 'p25', label: '1st quartile', value:
|
|
47
|
-
{ id: 'median', label: 'Median', value:
|
|
48
|
-
{ id: 'mean', label: 'Mean', value:
|
|
49
|
-
{ id: 'p75', label: '3rd quartile', value:
|
|
50
|
-
{ id: 'max', label: 'Maximum', value:
|
|
51
|
-
{ id: 'SD', label: 'Standard deviation', value:
|
|
52
|
-
{ id: 'variance', label: 'Variance', value:
|
|
53
|
-
{ id: 'IQR', label: 'Inter-quartile range', value:
|
|
45
|
+
{ id: 'min', label: 'Minimum', value: roundValueAuto(min) },
|
|
46
|
+
{ id: 'p25', label: '1st quartile', value: roundValueAuto(p25) },
|
|
47
|
+
{ id: 'median', label: 'Median', value: roundValueAuto(median) },
|
|
48
|
+
{ id: 'mean', label: 'Mean', value: roundValueAuto(mean(arr)) },
|
|
49
|
+
{ id: 'p75', label: '3rd quartile', value: roundValueAuto(p75) },
|
|
50
|
+
{ id: 'max', label: 'Maximum', value: roundValueAuto(max) },
|
|
51
|
+
{ id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev) },
|
|
52
|
+
{ id: 'variance', label: 'Variance', value: roundValueAuto(variance) },
|
|
53
|
+
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(IQR) }
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/roundValue.js
CHANGED
|
@@ -7,16 +7,22 @@ round a value to specified digits
|
|
|
7
7
|
value: given value
|
|
8
8
|
digits: number of digits to round to
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
export function roundValue(value, digits) {
|
|
11
12
|
const v = Number(value)
|
|
12
13
|
if (Number.isInteger(v)) return v
|
|
13
|
-
|
|
14
|
+
const abs = Math.abs(v)
|
|
15
|
+
if (abs < 1 || abs > 9999) {
|
|
16
|
+
//Number() reverts positive values less than 10^21 to a whole number
|
|
17
|
+
return abs > 9999 ? v.toPrecision(digits) : Number(v.toPrecision(digits))
|
|
18
|
+
}
|
|
14
19
|
return Number(v.toFixed(digits))
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export function roundValueAuto(value) {
|
|
23
|
+
if (!value && value != 0) return value
|
|
18
24
|
const dp = decimalPlacesUntilFirstNonZero(value)
|
|
19
|
-
|
|
25
|
+
const digits = Math.abs(value) > 1 ? 2 : dp > 0 ? dp + 1 : 2
|
|
20
26
|
|
|
21
27
|
return roundValue(value, digits)
|
|
22
28
|
}
|