From 6c2f51a6c6b4f02b73ffe0346ec34907337e7c0f Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 27 Feb 2020 22:21:56 +0000 Subject: [PATCH 1/2] Minor changes --- src/components/charts/DistPlusPlot.re | 193 +++++++++++++------------- src/interface/FormBuilder.re | 16 ++- 2 files changed, 112 insertions(+), 97 deletions(-) diff --git a/src/components/charts/DistPlusPlot.re b/src/components/charts/DistPlusPlot.re index d3f57772..9ea8d889 100644 --- a/src/components/charts/DistPlusPlot.re +++ b/src/components/charts/DistPlusPlot.re @@ -1,99 +1,5 @@ -let adjustBoth = discreteProbabilityMass => { - let yMaxDiscreteDomainFactor = discreteProbabilityMass; - let yMaxContinuousDomainFactor = 1.0 -. discreteProbabilityMass; - let yMax = - yMaxDiscreteDomainFactor > yMaxContinuousDomainFactor - ? yMaxDiscreteDomainFactor : yMaxContinuousDomainFactor; - ( - 1.0 /. (yMaxDiscreteDomainFactor /. yMax), - 1.0 /. (yMaxContinuousDomainFactor /. yMax), - ); -}; - -module DistPlusChart = { - [@react.component] - let make = (~distPlus: DistTypes.distPlus, ~onHover) => { - open Distributions.DistPlus; - let discrete = distPlus |> T.toScaledDiscrete; - let continuous = - distPlus - |> T.toScaledContinuous - |> E.O.fmap(Distributions.Continuous.getShape); - 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 toDiscreteProbabilityMass = - distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass; - let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) = - adjustBoth(toDiscreteProbabilityMass); - ; - }; -}; - -module IntegralChart = { - [@react.component] - let make = (~distPlus: DistTypes.distPlus, ~onHover) => { - open Distributions.DistPlus; - let integral = - Distributions.DistPlus.T.toShape(distPlus) - |> Distributions.Shape.T.Integral.get(~cache=None); - let continuous = - integral - |> Distributions.Continuous.toLinear - |> E.O.fmap(Distributions.Continuous.getShape); - let range = T.xTotalRange(distPlus); - let minX = - switch (T.minX(distPlus), range) { - | (Some(min), Some(range)) => Some(min -. range *. 0.001) - | _ => None - }; - let maxX = integral |> Distributions.Continuous.T.maxX; - let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; - ; - }; -}; - -[@react.component] -let make = (~distPlus: DistTypes.distPlus) => { - let (x, setX) = React.useState(() => 0.); - let chart = - React.useMemo1( - () => { {setX(_ => r)}} />}, - [|distPlus|], - ); - let chart2 = - React.useMemo1( - () => { {setX(_ => r)}} />}, - [|distPlus|], - ); +let table = (distPlus, x) => {
- chart - chart2 @@ -204,7 +110,102 @@ let make = (~distPlus: DistTypes.distPlus) => {
-
; +}; + +let adjustBoth = discreteProbabilityMass => { + let yMaxDiscreteDomainFactor = discreteProbabilityMass; + let yMaxContinuousDomainFactor = 1.0 -. discreteProbabilityMass; + let yMax = + yMaxDiscreteDomainFactor > yMaxContinuousDomainFactor + ? yMaxDiscreteDomainFactor : yMaxContinuousDomainFactor; + ( + 1.0 /. (yMaxDiscreteDomainFactor /. yMax), + 1.0 /. (yMaxContinuousDomainFactor /. yMax), + ); +}; + +module DistPlusChart = { + [@react.component] + let make = (~distPlus: DistTypes.distPlus, ~onHover) => { + open Distributions.DistPlus; + let discrete = distPlus |> T.toScaledDiscrete; + let continuous = + distPlus + |> T.toScaledContinuous + |> E.O.fmap(Distributions.Continuous.getShape); + 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 toDiscreteProbabilityMass = + distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass; + let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) = + adjustBoth(toDiscreteProbabilityMass); + ; + }; +}; + +module IntegralChart = { + [@react.component] + let make = (~distPlus: DistTypes.distPlus, ~onHover) => { + open Distributions.DistPlus; + let integral = + Distributions.DistPlus.T.toShape(distPlus) + |> Distributions.Shape.T.Integral.get(~cache=None); + let continuous = + integral + |> Distributions.Continuous.toLinear + |> E.O.fmap(Distributions.Continuous.getShape); + let range = T.xTotalRange(distPlus); + let minX = + switch (T.minX(distPlus), range) { + | (Some(min), Some(range)) => Some(min -. range *. 0.001) + | _ => None + }; + let maxX = integral |> Distributions.Continuous.T.maxX; + let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; + ; + }; +}; + +[@react.component] +let make = (~distPlus: DistTypes.distPlus) => { + let (x, setX) = React.useState(() => 0.); + let chart = + React.useMemo1( + () => { {setX(_ => r)}} />}, + [|distPlus|], + ); + let chart2 = + React.useMemo1( + () => { {setX(_ => r)}} />}, + [|distPlus|], + ); +
chart chart2 {table(distPlus, x)}
; // chart }; \ No newline at end of file diff --git a/src/interface/FormBuilder.re b/src/interface/FormBuilder.re index abef0f10..aa6db47c 100644 --- a/src/interface/FormBuilder.re +++ b/src/interface/FormBuilder.re @@ -29,7 +29,21 @@ let propValue = (t: Prop.Value.t) => { | Some(distribution) =>
- {r.guesstimatorString |> ReasonReact.string} + + +
+ {"30 to infinity, 80% mass" |> ReasonReact.string} +
| None => "Something went wrong" |> ReasonReact.string }; From 297b280a932042d729ffac0320649bfd18ba1b19 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 29 Feb 2020 18:16:47 +0000 Subject: [PATCH 2/2] Add filter command --- src/distributions/XYShape.re | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/distributions/XYShape.re b/src/distributions/XYShape.re index 0721086d..ff8c8f51 100644 --- a/src/distributions/XYShape.re +++ b/src/distributions/XYShape.re @@ -156,6 +156,9 @@ let _transverseShape = (fn, p: t) => { |> fromArray; }; +let filter = (fn, t: t) => + t |> zip |> E.A.filter(fn) |> Belt.Array.unzip |> fromArray; + let accumulateYs = _transverseShape((aCurrent, aLast) => aCurrent +. aLast); let subtractYs = _transverseShape((aCurrent, aLast) => aCurrent -. aLast);