From ddd0bc082001f7e4495659673227b7e90900650a Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 25 Feb 2020 19:55:01 +0000 Subject: [PATCH] Make sure that chart minimum is shown --- showcase/entries/Continuous.re | 4 +++- src/components/charts/DistPlusPlot.re | 8 +++++++- .../charts/DistributionPlot/distPlotReact.js | 4 ++-- src/distributions/Distributions.re | 3 ++- src/distributions/TimeTypes.re | 5 +++-- src/interface/FormBuilder.re | 14 +++++++++++--- src/models/GlobalCatastrophe.re | 11 +++-------- src/utility/Guesstimator.re | 4 ++-- src/utility/GuesstimatorLibrary.js | 6 +++--- 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/showcase/entries/Continuous.re b/showcase/entries/Continuous.re index f0a9b7d8..a86d6004 100644 --- a/showcase/entries/Continuous.re +++ b/showcase/entries/Continuous.re @@ -1,6 +1,7 @@ // "mm(floor(uniform(30,35)), normal(50,20), [.25,.5])", // "mm(floor(normal(28,4)), normal(32,2), uniform(20,24), [.5,.2,.1])", +// "mm(5 to 20, floor(normal(20,2)), [.5, .5])", let timeDist = DistPlusIngredients.make( ~guesstimatorString="(floor(10 to 15))", @@ -24,7 +25,8 @@ let distributions = () =>

{"Single-Discrete" |> ReasonReact.string}

{setup( DistPlusIngredients.make( - ~guesstimatorString="mm(5 to 20, floor(normal(20,2)), [.5, .5])", + ~guesstimatorString= + "uniform(0,1) > 0.036 ? lognormal(6.652, -0.41): 0", ~domain= RightLimited({xPoint: 50.0, excludingProbabilityMass: 0.3}), (), diff --git a/src/components/charts/DistPlusPlot.re b/src/components/charts/DistPlusPlot.re index e60062e3..4fadde2d 100644 --- a/src/components/charts/DistPlusPlot.re +++ b/src/components/charts/DistPlusPlot.re @@ -7,7 +7,13 @@ module DistPlusChart = { distPlus |> T.toScaledContinuous |> E.O.fmap(Distributions.Continuous.getShape); - let minX = T.minX(distPlus); + let range = T.xTotalRange(distPlus); + let minX = + switch (T.minX(distPlus), range) { + | (Some(min), Some(range)) => Some(min -. range *. 0.001) + | _ => None + }; + let maxX = T.maxX(distPlus); let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; + let minX = ({continuous, discrete}: t) => { min(Continuous.T.minX(continuous), Discrete.T.minX(discrete)); + }; let maxX = ({continuous, discrete}: t) => max(Continuous.T.maxX(continuous), Discrete.T.maxX(discrete)); let toShape = (t: t): DistTypes.shape => Mixed(t); diff --git a/src/distributions/TimeTypes.re b/src/distributions/TimeTypes.re index 355e8ba5..7a8368e0 100644 --- a/src/distributions/TimeTypes.re +++ b/src/distributions/TimeTypes.re @@ -63,8 +63,9 @@ module RelativeTimePoint = { |> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.unit)) }; - let _timeToX = (time, timeStart, timeUnit) => - MomentRe.diff(timeStart, time, timeUnit); + let _timeToX = (time, timeStart, timeUnit) => { + MomentRe.diff(time, timeStart, timeUnit); + }; let toXValue = (timeVector: timeVector, timeInVector: timeInVector) => switch (timeInVector) { diff --git a/src/interface/FormBuilder.re b/src/interface/FormBuilder.re index 55f1bf23..6a66e981 100644 --- a/src/interface/FormBuilder.re +++ b/src/interface/FormBuilder.re @@ -17,12 +17,20 @@ let propValue = (t: Prop.Value.t) => { switch (t) { | SelectSingle(r) => r |> ReasonReact.string | ConditionalArray(r) => "Array" |> ReasonReact.string - | DistPlusIngredients(r) => + | DistPlusIngredients((r: DistTypes.distPlusIngredients)) => let newDistribution = - DistPlusIngredients.toDistPlus(~sampleCount=1000, r); + DistPlusIngredients.toDistPlus( + ~sampleCount=2000, + ~outputXYPoints=2000, + ~truncateTo=Some(100), + r, + ); switch (newDistribution) { | Some(distribution) => -
+
+ + {r.guesstimatorString |> ReasonReact.string} +
| None => "Something went wrong" |> ReasonReact.string }; | FloatCdf(_) =>
diff --git a/src/models/GlobalCatastrophe.re b/src/models/GlobalCatastrophe.re index ad633077..239a8829 100644 --- a/src/models/GlobalCatastrophe.re +++ b/src/models/GlobalCatastrophe.re @@ -1,21 +1,16 @@ -let guesstimatorString = "normal(40,10)"; +let guesstimatorString = "uniform(1, 100)"; let makeI = (currentDateTime: MomentRe.Moment.t) => { DistPlusIngredients.make( ~guesstimatorString, ~unit=TimeDistribution({zero: currentDateTime, unit: `years}), + ~domain=RightLimited({xPoint: 300.0, excludingProbabilityMass: 0.3}), (), ); }; module Model = { let make = (currentDateTime: MomentRe.Moment.t) => { - let distPlusIngredients = - DistPlusIngredients.make( - ~guesstimatorString, - ~unit=TimeDistribution({zero: currentDateTime, unit: `years}), - (), - ); - Prop.Value.DistPlusIngredients(distPlusIngredients); + Prop.Value.DistPlusIngredients(makeI(currentDateTime)); }; }; diff --git a/src/utility/Guesstimator.re b/src/utility/Guesstimator.re index 51ee992a..1e4bf9f4 100644 --- a/src/utility/Guesstimator.re +++ b/src/utility/Guesstimator.re @@ -52,8 +52,8 @@ module Internals = { let stringToMixedShape = ( ~string, - ~sampleCount=1000, - ~outputXYPoints=1000, + ~sampleCount=3000, + ~outputXYPoints=3000, ~truncateTo=Some(500), (), ) => diff --git a/src/utility/GuesstimatorLibrary.js b/src/utility/GuesstimatorLibrary.js index 06c2513c..cef3a65b 100644 --- a/src/utility/GuesstimatorLibrary.js +++ b/src/utility/GuesstimatorLibrary.js @@ -13,9 +13,9 @@ const minMaxRatio = (minValue, maxValue) => { return 'SMALL'; } const ratio = maxValue / minValue; - if (ratio < 100000) { + if (ratio < 10000) { return 'SMALL'; - } else if (ratio < 10000000) { + } else if (ratio < 1000000) { return 'MEDIUM'; } else { return 'LARGE'; @@ -46,7 +46,7 @@ const toPdf = (values, outputResolutionCount, min, max) => { const samples = new Samples(continuousSamples); const ratioSize$ = ratioSize(samples); - const width = ratioSize$ === 'SMALL' ? 100 : 1; + const width = ratioSize$ === 'SMALL' ? 40 : 1; const pdf = samples.toPdf({ size: outputResolutionCount, width, min, max }); continuous = pdf;