From 2316820db1f660deb6f5c194661b169094e10a12 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 30 Jul 2020 17:52:28 +0100 Subject: [PATCH] Minor cleanup of RenderTypes --- src/components/DistBuilder.re | 24 +------ src/distPlus/renderers/DistPlusRenderer.re | 36 +++++++---- src/distPlus/renderers/RenderTypes.re | 73 +++------------------- 3 files changed, 36 insertions(+), 97 deletions(-) diff --git a/src/components/DistBuilder.re b/src/components/DistBuilder.re index 1432ddb8..fac4e483 100644 --- a/src/components/DistBuilder.re +++ b/src/components/DistBuilder.re @@ -167,30 +167,12 @@ module DemoDist = { ); let response1 = DistPlusRenderer.run(inputs1); - let inputs2 = - RenderTypes.DistPlusRenderer.make( - ~samplingInputs={ - sampleCount: Some(options.sampleCount), - outputXYPoints: Some(options.outputXYPoints), - kernelWidth: options.kernelWidth, - }, - ~distPlusIngredients, - ~shouldDownsample=options.downsampleTo |> E.O.isSome, - ~recommendedLength=options.downsampleTo |> E.O.default(1000), - ~inputVariables= - [|("p", `SymbolicDist(`Float(2.0)))|] - ->Belt.Map.String.fromArray, - (), - ); - let response2 = DistPlusRenderer.run(inputs2); - switch (response1, response2) { - | (Ok(distPlus1), Ok(distPlus2)) => + switch (response1) { + | (Ok(distPlus1)) => <> - - | (Error(r), _) => r |> R.ste - | (_, Error(r)) => r |> R.ste + | (Error(r)) => r |> R.ste }; | _ => "Nothing to show. Try to change the distribution description." diff --git a/src/distPlus/renderers/DistPlusRenderer.re b/src/distPlus/renderers/DistPlusRenderer.re index dd23513b..c38758f3 100644 --- a/src/distPlus/renderers/DistPlusRenderer.re +++ b/src/distPlus/renderers/DistPlusRenderer.re @@ -1,4 +1,16 @@ -let inputsToShape = (inputs: RenderTypes.ShapeRenderer.Combined.inputs) => { +type inputs = { + samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs, + symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs, + guesstimatorString: string, + inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node), +}; +type outputs = { + graph: ExpressionTypes.ExpressionTree.node, + shape: DistTypes.shape, +}; +let makeOutputs = (graph, shape): outputs => {graph, shape}; + +let inputsToShape = (inputs: inputs) => { MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables) |> E.R.bind(_, g => ExpressionTree.toShape( @@ -12,20 +24,11 @@ let inputsToShape = (inputs: RenderTypes.ShapeRenderer.Combined.inputs) => { }, g, ) - |> E.R.fmap(RenderTypes.ShapeRenderer.Symbolic.make(g)) + |> E.R.fmap(makeOutputs(g)) ); }; let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => { - let toDist = shape => - DistPlus.make( - ~shape, - ~domain=inputs.distPlusIngredients.domain, - ~unit=inputs.distPlusIngredients.unit, - ~guesstimatorString=Some(inputs.distPlusIngredients.guesstimatorString), - (), - ) - |> DistPlus.T.normalize; let output = inputsToShape({ samplingInputs: inputs.samplingInputs, @@ -36,7 +39,14 @@ let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => { }, }); output - |> E.R.fmap((o: RenderTypes.ShapeRenderer.Symbolic.outputs) => - toDist(o.shape) + |> E.R.fmap((o: outputs) => + DistPlus.make( + ~shape=o.shape, + ~domain=inputs.distPlusIngredients.domain, + ~unit=inputs.distPlusIngredients.unit, + ~guesstimatorString= + Some(inputs.distPlusIngredients.guesstimatorString), + (), + ) ); }; diff --git a/src/distPlus/renderers/RenderTypes.re b/src/distPlus/renderers/RenderTypes.re index c7dc418f..fafcdb4d 100644 --- a/src/distPlus/renderers/RenderTypes.re +++ b/src/distPlus/renderers/RenderTypes.re @@ -7,20 +7,8 @@ module ShapeRenderer = { outputXYPoints: option(int), kernelWidth: option(float), }; - type samplingStats = { - sampleCount: int, - outputXYPoints: int, - bandwidthXSuggested: float, - bandwidthUnitSuggested: float, - bandwidthXImplemented: float, - bandwidthUnitImplemented: float, - }; - type outputs = { - continuousParseParams: option(samplingStats), - shape: option(DistTypes.shape), - }; module Inputs = { - let defaultSampleCount = 5000; + let defaultSampleCount = 10000; let defaultOutputXYPoints = 10000; let empty = { sampleCount: None, @@ -44,36 +32,6 @@ module ShapeRenderer = { module Symbolic = { type inputs = {length: int}; - type outputs = { - graph: ExpressionTypes.ExpressionTree.node, - shape: DistTypes.shape, - }; - let make = (graph, shape) => {graph, shape}; - }; - - module Combined = { - type inputs = { - samplingInputs: Sampling.inputs, - symbolicInputs: Symbolic.inputs, - guesstimatorString: string, - inputVariables: MS.t(ExpressionTypes.ExpressionTree.node), - }; - type outputs = { - symbolic: option(Belt.Result.t(Symbolic.outputs, string)), - sampling: option(Sampling.outputs), - }; - let methodUsed = ({symbolic, sampling}: outputs) => - switch (symbolic, sampling) { - | (Some(Ok(_)), _) => `Symbolic - | (_, Some({shape: Some(_)})) => `Sampling - | _ => `None - }; - let getShape = (r: outputs) => - switch (r.symbolic, r.sampling) { - | (Some(Ok({shape})), _) => Some(shape) - | (_, Some({shape})) => shape - | _ => None - }; }; }; @@ -85,14 +43,8 @@ module DistPlusRenderer = { domain: DistTypes.domain, unit: DistTypes.distributionUnit, }; - type inputs = { - distPlusIngredients: ingredients, - samplingInputs: ShapeRenderer.Sampling.inputs, - recommendedLength: int, - shouldDownsample: bool, - inputVariables: MS.t(ExpressionTypes.ExpressionTree.node), - }; module Ingredients = { + type t = ingredients; let make = ( ~guesstimatorString, @@ -100,12 +52,19 @@ module DistPlusRenderer = { ~unit=DistTypes.UnspecifiedDistribution, (), ) - : ingredients => { + : t => { guesstimatorString, domain, unit, }; }; + type inputs = { + distPlusIngredients: ingredients, + samplingInputs: ShapeRenderer.Sampling.inputs, + recommendedLength: int, + shouldDownsample: bool, + inputVariables: MS.t(ExpressionTypes.ExpressionTree.node), + }; let make = ( ~samplingInputs=ShapeRenderer.Sampling.Inputs.empty, @@ -122,16 +81,4 @@ module DistPlusRenderer = { shouldDownsample, inputVariables, }; - type outputs = { - shapeRenderOutputs: ShapeRenderer.Combined.outputs, - distPlus: option(DistTypes.distPlus), - }; - module Outputs = { - let distplus = (t: outputs) => t.distPlus; - let shapeRenderOutputs = (t: outputs) => t.shapeRenderOutputs; - let make = (shapeRenderOutputs, distPlus) => { - shapeRenderOutputs, - distPlus, - }; - }; };