Starting to add conditionals
This commit is contained in:
parent
fc3108c289
commit
b44073140f
|
@ -1,14 +1,25 @@
|
||||||
module Value = {
|
module Value = {
|
||||||
|
type binaryConditional =
|
||||||
|
| Selected(bool)
|
||||||
|
| Unselected;
|
||||||
type t =
|
type t =
|
||||||
|
| BinaryConditional(binaryConditional)
|
||||||
| SelectSingle(string)
|
| SelectSingle(string)
|
||||||
| DateTime(MomentRe.Moment.t)
|
| DateTime(MomentRe.Moment.t)
|
||||||
| FloatPoint(float)
|
| FloatPoint(float)
|
||||||
|
| Probability(float)
|
||||||
| FloatCdf(string);
|
| FloatCdf(string);
|
||||||
|
|
||||||
let to_string = (t: t) => {
|
let to_string = (t: t) => {
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
| BinaryConditional(binaryConditional) =>
|
||||||
|
switch (binaryConditional) {
|
||||||
|
| Selected(r) => r ? "True" : "False"
|
||||||
|
| Unselected => ""
|
||||||
|
}
|
||||||
| SelectSingle(r) => r
|
| SelectSingle(r) => r
|
||||||
| FloatCdf(r) => r
|
| FloatCdf(r) => r
|
||||||
|
| Probability(r) => (r *. 100. |> Js.Float.toFixed) ++ "%"
|
||||||
| DateTime(r) => r |> MomentRe.Moment.defaultFormat
|
| DateTime(r) => r |> MomentRe.Moment.defaultFormat
|
||||||
| FloatPoint(r) => r |> Js.Float.toFixed
|
| FloatPoint(r) => r |> Js.Float.toFixed
|
||||||
};
|
};
|
||||||
|
@ -34,17 +45,23 @@ module Type = {
|
||||||
max: option('a),
|
max: option('a),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type withDefault('a) = {default: option('a)};
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
|
| BinaryConditional
|
||||||
| SelectSingle(selectSingle)
|
| SelectSingle(selectSingle)
|
||||||
| FloatPoint(withDefaultMinMax(float))
|
| FloatPoint(withDefaultMinMax(float))
|
||||||
|
| Probability(withDefault(float))
|
||||||
| DateTime(withDefaultMinMax(MomentRe.Moment.t))
|
| DateTime(withDefaultMinMax(MomentRe.Moment.t))
|
||||||
| Year(withDefaultMinMax(float))
|
| Year(withDefaultMinMax(float))
|
||||||
| FloatCdf;
|
| FloatCdf;
|
||||||
|
|
||||||
let default = (t: t) =>
|
let default = (t: t) =>
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
| BinaryConditional => Some(Value.BinaryConditional(Unselected))
|
||||||
| 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))
|
||||||
| DateTime(r) => r.default->Belt.Option.map(p => Value.DateTime(p))
|
| DateTime(r) => r.default->Belt.Option.map(p => Value.DateTime(p))
|
||||||
| SelectSingle(r) =>
|
| SelectSingle(r) =>
|
||||||
r.default->Belt.Option.map(p => Value.SelectSingle(p))
|
r.default->Belt.Option.map(p => Value.SelectSingle(p))
|
||||||
|
|
|
@ -33,6 +33,36 @@ let make =
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
| (BinaryConditional, Some(BinaryConditional(r))) =>
|
||||||
|
switch (r) {
|
||||||
|
| Unselected =>
|
||||||
|
<div
|
||||||
|
onClick={_ => onChange(Some(BinaryConditional(Selected(true))))}>
|
||||||
|
{"Select" |> ReasonReact.string}
|
||||||
|
</div>
|
||||||
|
| Selected(true) =>
|
||||||
|
<div>
|
||||||
|
{"YES!" |> ReasonReact.string}
|
||||||
|
<div
|
||||||
|
onClick={_ => onChange(Some(BinaryConditional(Selected(false))))}>
|
||||||
|
{"No" |> ReasonReact.string}
|
||||||
|
</div>
|
||||||
|
<div onClick={_ => onChange(Some(BinaryConditional(Unselected)))}>
|
||||||
|
{"Deselect" |> ReasonReact.string}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
| Selected(false) =>
|
||||||
|
<div>
|
||||||
|
{"NO!" |> ReasonReact.string}
|
||||||
|
<div
|
||||||
|
onClick={_ => onChange(Some(BinaryConditional(Selected(true))))}>
|
||||||
|
{"Yes" |> ReasonReact.string}
|
||||||
|
</div>
|
||||||
|
<div onClick={_ => onChange(Some(BinaryConditional(Unselected)))}>
|
||||||
|
{"Deselect" |> ReasonReact.string}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
| (Year(_), _)
|
| (Year(_), _)
|
||||||
| (FloatPoint(_), _) => <input type_="number" value="" />
|
| (FloatPoint(_), _) => <input type_="number" value="" />
|
||||||
| (SelectSingle(t), Some(SelectSingle(r))) =>
|
| (SelectSingle(t), Some(SelectSingle(r))) =>
|
||||||
|
|
|
@ -11,8 +11,12 @@ module Data = {
|
||||||
|
|
||||||
type output =
|
type output =
|
||||||
| DONATIONS
|
| DONATIONS
|
||||||
|
| CHANCE_OF_EXISTENCE
|
||||||
| PAYOUTS;
|
| PAYOUTS;
|
||||||
|
|
||||||
|
type conditionals =
|
||||||
|
| WORLD_CATASTROPHE;
|
||||||
|
|
||||||
type fundWithInfo = {
|
type fundWithInfo = {
|
||||||
group,
|
group,
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -93,6 +97,7 @@ module Model = {
|
||||||
| (Fund(META), DONATIONS) => 9300000.0
|
| (Fund(META), DONATIONS) => 9300000.0
|
||||||
| (Fund(META), PAYOUTS) => 830000.0
|
| (Fund(META), PAYOUTS) => 830000.0
|
||||||
| (All, _) => sum()
|
| (All, _) => sum()
|
||||||
|
| (_, CHANCE_OF_EXISTENCE) => 0.0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
let make =
|
let make =
|
||||||
|
@ -102,6 +107,9 @@ module Model = {
|
||||||
currentDateTime: MomentRe.Moment.t,
|
currentDateTime: MomentRe.Moment.t,
|
||||||
output: output,
|
output: output,
|
||||||
) => {
|
) => {
|
||||||
|
switch (output) {
|
||||||
|
| DONATIONS
|
||||||
|
| PAYOUTS =>
|
||||||
Prop.Value.FloatCdf(
|
Prop.Value.FloatCdf(
|
||||||
calculateDifference(
|
calculateDifference(
|
||||||
currentValue(group, output),
|
currentValue(group, output),
|
||||||
|
@ -109,7 +117,11 @@ module Model = {
|
||||||
currentDateTime,
|
currentDateTime,
|
||||||
yearlyMeanGrowthRateIfNotClosed(group),
|
yearlyMeanGrowthRateIfNotClosed(group),
|
||||||
),
|
),
|
||||||
);
|
)
|
||||||
|
| CHANCE_OF_EXISTENCE =>
|
||||||
|
let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.;
|
||||||
|
Prop.Value.Probability((100. -. yearDiff) /. 100.);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,6 +138,7 @@ module Interface = {
|
||||||
let outputFromString = (s: string) =>
|
let outputFromString = (s: string) =>
|
||||||
switch (s) {
|
switch (s) {
|
||||||
| "donations" => DONATIONS
|
| "donations" => DONATIONS
|
||||||
|
| "exists" => CHANCE_OF_EXISTENCE
|
||||||
| _ => PAYOUTS
|
| _ => PAYOUTS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,6 +149,7 @@ 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 =>
|
||||||
|
@ -206,12 +220,19 @@ module Interface = {
|
||||||
SelectSingle({
|
SelectSingle({
|
||||||
default: Some("Output"),
|
default: Some("Output"),
|
||||||
options: [
|
options: [
|
||||||
{name: "Donations", id: "donations"},
|
{name: "Donations | Exists", id: "donations"},
|
||||||
{name: "Funding", id: "funding"},
|
{name: "Funding | Exists", id: "funding"},
|
||||||
|
{name: "Exists", id: "exists"},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
|
TypeWithMetadata.make(
|
||||||
|
~name="Conditional on World Ending",
|
||||||
|
~id="worldEnd",
|
||||||
|
~type_=BinaryConditional,
|
||||||
|
(),
|
||||||
|
),
|
||||||
|],
|
|],
|
||||||
outputTypes: [||],
|
outputTypes: [||],
|
||||||
run,
|
run,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user