open BsReform;
module FormConfig = [%lenses
type state = {
guesstimatorString: string,
//
domainType: string, // Complete, LeftLimited(...), RightLimited(...), LeftAndRightLimited(..., ...)
xPoint: string,
excludingProbabilityMass: string,
//
unitType: string, // UnspecifiedDistribution, TimeDistribution(zero, unit)
zero: MomentRe.Moment.t,
unit: string,
}
];
module Form = ReForm.Make(FormConfig);
let schema = Form.Validation.Schema([||]);
module FieldString = {
[@react.component]
let make = (~field, ~label) => {
E.ste}>
validate()}
/>
}
/>;
};
};
module Styles = {
open Css;
let row =
style([display(`flex), selector("div > div", [flex(`num(1.))])]);
let form = style([backgroundColor(hex("eee")), padding(em(1.))]);
let spacer = style([marginTop(em(3.))]);
};
module FieldFloat = {
[@react.component]
let make = (~field, ~label) => {
E.ste}>
validate()}
/>
}
/>;
};
};
[@react.component]
let make = () => {
let reform =
Form.use(
~validationStrategy=OnDemand,
~schema,
~onSubmit=({state}) => {None},
~initialState={
guesstimatorString: "mm(5 to 20, floor(normal(20,2)), [.5, .5])",
domainType: "Complete",
xPoint: "50.0",
excludingProbabilityMass: "0.3",
unitType: "UnspecifiedDistribution",
zero: MomentRe.momentNow(),
unit: "days",
},
(),
);
let onSubmit = e => {
e->ReactEvent.Synthetic.preventDefault;
reform.submit();
};
let domain =
switch (reform.state.values.domainType) {
| "Complete" => DistTypes.Complete
| "LeftLimited" =>
LeftLimited({
xPoint: reform.state.values.xPoint |> float_of_string,
excludingProbabilityMass:
reform.state.values.excludingProbabilityMass |> float_of_string,
})
| "RightLimited" =>
RightLimited({
xPoint: reform.state.values.xPoint |> float_of_string,
excludingProbabilityMass:
reform.state.values.excludingProbabilityMass |> float_of_string,
})
| "LeftAndRightLimited" =>
LeftAndRightLimited(
{
xPoint: reform.state.values.xPoint |> float_of_string,
excludingProbabilityMass:
reform.state.values.excludingProbabilityMass |> float_of_string,
},
{
xPoint: reform.state.values.xPoint |> float_of_string,
excludingProbabilityMass:
reform.state.values.excludingProbabilityMass |> float_of_string,
},
)
| _ => Js.Exn.raiseError("domain is unknown")
};
let unit =
switch (reform.state.values.unitType) {
| "UnspecifiedDistribution" => DistTypes.UnspecifiedDistribution
| "TimeDistribution" =>
TimeDistribution({
zero: reform.state.values.zero,
unit: reform.state.values.unit |> TimeTypes.TimeUnit.ofString,
})
| _ => Js.Exn.raiseError("unit is unknown")
};
let guesstimatorString = reform.state.values.guesstimatorString;
{DistPlusIngredients.make(~guesstimatorString, ~domain, ~unit, ())
|> DistPlusIngredients.toDistPlus(
~sampleCount=10000,
~outputXYPoints=2000,
~truncateTo=Some(1000),
)
|> E.O.React.fmapOrNull(distPlus => )}
E.ste}>
e |> handleChange}>
{"Complete" |> E.ste}
{"LeftLimited" |> E.ste}
{"RightLimited" |> E.ste}
{"LeftAndRightLimited" |> E.ste}
}
/>
E.ste}>
e |> handleChange}>
{"UnspecifiedDistribution" |> E.ste}
{"TimeDistribution" |> E.ste}
}
/>
E.ste}>
{
e |> handleChange;
_ => ();
}}
/>
}
/>
E.ste}>
e |> handleChange}>
{"days" |> E.ste}
{"hours" |> E.ste}
{"milliseconds" |> E.ste}
{"minutes" |> E.ste}
{"months" |> E.ste}
{"quarters" |> E.ste}
{"seconds" |> E.ste}
{"weeks" |> E.ste}
{"years" |> E.ste}
}
/>
;
};