First prototype of conditionals

This commit is contained in:
Ozzie Gooen 2020-02-13 18:56:14 +00:00
parent dfbdc51085
commit 2f503fbef6
4 changed files with 37 additions and 8 deletions

View File

@ -2,12 +2,20 @@ module Value = {
type binaryConditional = type binaryConditional =
| Selected(bool) | Selected(bool)
| Unselected; | Unselected;
type conditional = {
statement: string,
truthValue: bool,
};
type t = type t =
| BinaryConditional(binaryConditional) | BinaryConditional(binaryConditional)
| SelectSingle(string) | SelectSingle(string)
| DateTime(MomentRe.Moment.t) | DateTime(MomentRe.Moment.t)
| FloatPoint(float) | FloatPoint(float)
| Probability(float) | Probability(float)
| Conditional(conditional)
| ConditionalArray(array(conditional))
| FloatCdf(string); | FloatCdf(string);
let to_string = (t: t) => { let to_string = (t: t) => {
@ -36,6 +44,8 @@ module Value = {
) )
|> ReasonReact.string |> ReasonReact.string
| SelectSingle(r) => r |> ReasonReact.string | SelectSingle(r) => r |> ReasonReact.string
| ConditionalArray(r) => "Array" |> ReasonReact.string
| Conditional(r) => r.statement |> ReasonReact.string
| FloatCdf(r) => | FloatCdf(r) =>
let cdf: Types.distribution = let cdf: Types.distribution =
CdfLibrary.Distribution.fromString(r, 2000); CdfLibrary.Distribution.fromString(r, 2000);
@ -65,6 +75,16 @@ module Type = {
default: option(string), default: option(string),
}; };
type conditionals = {
defaults: array(Value.conditional),
options: array(string),
};
let makeConditionals = (defaults, options): conditionals => {
defaults,
options,
};
type floatPoint = {validatations: list(float => bool)}; type floatPoint = {validatations: list(float => bool)};
type withDefaultMinMax('a) = { type withDefaultMinMax('a) = {
@ -82,11 +102,13 @@ module Type = {
| Probability(withDefault(float)) | Probability(withDefault(float))
| DateTime(withDefaultMinMax(MomentRe.Moment.t)) | DateTime(withDefaultMinMax(MomentRe.Moment.t))
| Year(withDefaultMinMax(float)) | Year(withDefaultMinMax(float))
| Conditionals(conditionals)
| FloatCdf; | FloatCdf;
let default = (t: t) => let default = (t: t) =>
switch (t) { switch (t) {
| BinaryConditional => Some(Value.BinaryConditional(Unselected)) | BinaryConditional => Some(Value.BinaryConditional(Unselected))
| Conditionals(s) => Some(Value.ConditionalArray(s.defaults))
| Year(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p)) | Year(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
| FloatPoint(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p)) | FloatPoint(r) => r.default->Belt.Option.map(p => Value.FloatPoint(p))
| Probability(r) => r.default->Belt.Option.map(p => Value.Probability(p)) | Probability(r) => r.default->Belt.Option.map(p => Value.Probability(p))

View File

@ -11,6 +11,7 @@ let make =
~onChange: onChange, ~onChange: onChange,
) => { ) => {
switch (type_.type_, value) { switch (type_.type_, value) {
| (Conditionals(_), r) => "sdfsdf" |> ReasonReact.string
| (Year(_), Some(FloatPoint(r))) => | (Year(_), Some(FloatPoint(r))) =>
<input <input
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"

View File

@ -152,7 +152,6 @@ module Interface = {
Some(DateTime(intendedYear)), Some(DateTime(intendedYear)),
Some(DateTime(currentYear)), Some(DateTime(currentYear)),
Some(SelectSingle(output)), Some(SelectSingle(output)),
Some(BinaryConditional(r)),
|] => |] =>
choiceFromString(fund) choiceFromString(fund)
|> E.O.fmap(fund => |> E.O.fmap(fund =>
@ -230,14 +229,16 @@ module Interface = {
}), }),
(), (),
), ),
TypeWithMetadata.make(
~name="Conditional on World Ending",
~id="worldEnd",
~type_=BinaryConditional,
(),
),
|], |],
outputTypes: [||], outputTypes: [||],
run, run,
}; };
}; } /* )*/;
// TypeWithMetadata.make(
// ~name="Conditional on World Ending",
// ~id="worldEnd",
// ~type_=
// Conditionals(
// Prop.Type.makeConditionals([||], [|"Foo", "Bar", "Char"|]),
// ),
// (),

View File

@ -1,4 +1,9 @@
module Model = { module Model = {
let foo = {
let bar = 2.0;
();
};
let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => { let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => {
let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.; let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.;
Prop.Value.Probability(0.001 *. yearDiff); Prop.Value.Probability(0.001 *. yearDiff);