perhaps the final push of PR 124?
This commit is contained in:
parent
320b8da91a
commit
50f5256dc5
|
@ -22,13 +22,13 @@ describe("Normal distribution with sparklines", () => {
|
|||
|
||||
let normalDistAtMean5: SymbolicDistTypes.normal = {mean: 5.0, stdev: 2.0}
|
||||
let normalDistAtMean10: SymbolicDistTypes.normal = {mean: 10.0, stdev: 2.0}
|
||||
let range20Float = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,]
|
||||
let range20Float = E.A.rangeFloat(0, 20) // [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,]
|
||||
|
||||
let pdfNormalDistAtMean5 = x => Normal.pdf(x, normalDistAtMean5)
|
||||
let sparklineMean5 = pdfImage(pdfNormalDistAtMean5, range20Float)
|
||||
makeTest("mean=5", Sparklines.create(sparklineMean5, ()), `▁▂▃▅███▅▃▂▁▁▁▁▁▁▁▁▁▁`)
|
||||
makeTest("mean=5", Sparklines.create(sparklineMean5, ()), `▁▂▃▅███▅▃▂▁▁▁▁▁▁▁▁▁▁▁`)
|
||||
|
||||
let sparklineMean15 = normalDistAtMean5 -> parameterWiseAdditionHelper(normalDistAtMean10) -> pdfImage(range20Float)
|
||||
// let sparklineMean15 = pdfImage(pdfNormalDistAtMean15, range20Float)
|
||||
makeTest("parameter-wise addition of two normal distributions", Sparklines.create(sparklineMean15, ()), `▁▁▁▁▁▁▁▁▁▁▂▃▅▇███▇▅▃`)
|
||||
makeTest("parameter-wise addition of two normal distributions", Sparklines.create(sparklineMean15, ()), `▁▁▁▁▁▁▁▁▁▁▂▃▅▇███▇▅▃▂`)
|
||||
})
|
||||
|
|
|
@ -269,6 +269,7 @@ module A = {
|
|||
))
|
||||
|> Rationale.Result.return
|
||||
}
|
||||
let rangeFloat = (start, stop) => start -> Belt.Array.rangeBy(stop, ~step=1) -> (arr => fmap(Belt.Int.toFloat, arr))
|
||||
|
||||
// This zips while taking the longest elements of each array.
|
||||
let zipMaxLength = (array1, array2) => {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Port of Sindre Sorhus' Sparkly to Rescript
|
||||
// reference implementation: https://github.com/sindresorhus/sparkly
|
||||
// Omitting rgb "fire" style, so no `chalk` dependency
|
||||
// Omitting: NaN handling, special consideration for constant data.
|
||||
|
||||
let create = (
|
||||
numbers: array<float>,
|
||||
|
@ -8,30 +9,20 @@ let create = (
|
|||
~maximum=?,
|
||||
()
|
||||
) => {
|
||||
// Unlike reference impl, we assume that all numbers are finite, i.e. no NaN.
|
||||
|
||||
let ticks = [`▁`, `▂`, `▃`, `▄`, `▅`, `▆`, `▇`, `█`]
|
||||
|
||||
let minimum = E.O.default(Js.Math.minMany_float(numbers), minimum)
|
||||
let maximum = E.O.default(Js.Math.maxMany_float(numbers), maximum)
|
||||
|
||||
// // Use a high tick if data is constant and max is not equal to min or zero
|
||||
// let ticks = if minimum == maximum && maximum != 0.0 {
|
||||
// [ticks[4]]
|
||||
// } else {
|
||||
// ticks
|
||||
// }
|
||||
|
||||
let toHeight = (number: float) => {
|
||||
let tickIndex = Js.Math.ceil_int((number /. maximum) *. (ticks -> Belt.Array.length -> Belt.Int.toFloat)) - 1
|
||||
|
||||
let tickIndex = if maximum == 0.0 || tickIndex < 0 {
|
||||
0
|
||||
} else {
|
||||
tickIndex
|
||||
}
|
||||
|
||||
ticks[tickIndex]
|
||||
}
|
||||
|
||||
toHeight -> E.A.fmap(numbers) -> (arr => E.A.joinWith("", arr))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user