diff --git a/src/EAFunds/EAFunds_Data.re b/src/EAFunds/EAFunds_Data.re
index d8f5d170..33ced1fa 100644
--- a/src/EAFunds/EAFunds_Data.re
+++ b/src/EAFunds/EAFunds_Data.re
@@ -8,7 +8,7 @@ type group =
| Fund(fund)
| All;
-type parameter =
+type output =
| DONATIONS
| PAYOUTS;
diff --git a/src/EAFunds/EAFunds_Form.bs.js b/src/EAFunds/EAFunds_Form.bs.js
index dbd61a0b..7b06776a 100644
--- a/src/EAFunds/EAFunds_Form.bs.js
+++ b/src/EAFunds/EAFunds_Form.bs.js
@@ -12,24 +12,64 @@ function handleChange(handleChange$1, $$event) {
return Curry._1(handleChange$1, $$event.target.value);
}
+function get(state, field) {
+ switch (field) {
+ case /* Group */0 :
+ return state[/* group */0];
+ case /* Year */1 :
+ return state[/* year */1];
+ case /* Output */2 :
+ return state[/* output */2];
+
+ }
+}
+
+function set(state, field, value) {
+ switch (field) {
+ case /* Group */0 :
+ return /* record */[
+ /* group */value,
+ /* year */state[/* year */1],
+ /* output */state[/* output */2]
+ ];
+ case /* Year */1 :
+ return /* record */[
+ /* group */state[/* group */0],
+ /* year */value,
+ /* output */state[/* output */2]
+ ];
+ case /* Output */2 :
+ return /* record */[
+ /* group */state[/* group */0],
+ /* year */state[/* year */1],
+ /* output */value
+ ];
+
+ }
+}
+
+var Form = {
+ get: get,
+ set: set
+};
+
function EAFunds_Form(Props) {
var match = React.useState((function () {
- return "Animal Welfare Fund";
+ return /* record */[
+ /* group */"Animal Welfare Fund",
+ /* year */2021,
+ /* output */"Donations"
+ ];
}));
- var setGroup = match[1];
- var group = match[0];
+ var setForm = match[1];
+ var form = match[0];
var match$1 = React.useState((function () {
- return 2021;
- }));
- var setYear = match$1[1];
- var year = match$1[0];
- var match$2 = React.useState((function () {
return "Donations";
}));
- var setProperty = match$2[1];
- var property = match$2[0];
+ var setProperty = match$1[1];
+ var property = match$1[0];
var foundGroup = Belt_Array.getBy(EAFunds_Data$ProbExample.funds, (function (r) {
- return r[/* name */1] === group;
+ return r[/* name */1] === form[/* group */0];
}));
var foundProperty;
switch (property) {
@@ -44,22 +84,25 @@ function EAFunds_Form(Props) {
}
return React.createElement(React.Fragment, undefined, React.createElement("input", {
type: "number",
- value: year.toString(),
+ value: form[/* year */1].toString(),
onChange: (function (param) {
var r = param.target.value;
var r$1 = Number(r);
if (r$1 >= 2020.0 && r$1 <= 2050.0) {
- return Curry._1(setYear, (function (param) {
- return r$1;
+ return Curry._1(setForm, (function (param) {
+ return set(form, /* Year */1, r$1);
}));
} else {
return /* () */0;
}
})
}), React.createElement(Antd_Radio.Group.make, {
- value: group,
+ value: form[/* group */0],
onChange: (function (param) {
- return Curry._1(setGroup, param.target.value);
+ var r = param.target.value;
+ return Curry._1(setForm, (function (param) {
+ return set(form, /* Group */0, r);
+ }));
}),
children: $$Array.map((function (f) {
return React.createElement(Antd_Radio.make, {
@@ -79,11 +122,12 @@ function EAFunds_Form(Props) {
}), React.createElement(Antd_Radio.make, {
value: "Payouts",
children: "Payouts"
- })), foundGroup !== undefined && foundProperty !== undefined ? EAFunds_Model$ProbExample.run(foundGroup[/* group */0], year, foundProperty) : "");
+ })), foundGroup !== undefined && foundProperty !== undefined ? EAFunds_Model$ProbExample.run(foundGroup[/* group */0], form[/* year */1], foundProperty) : "");
}
var make = EAFunds_Form;
exports.handleChange = handleChange;
+exports.Form = Form;
exports.make = make;
/* react Not a pure module */
diff --git a/src/EAFunds/EAFunds_Form.re b/src/EAFunds/EAFunds_Form.re
index 217e186a..02750e7d 100644
--- a/src/EAFunds/EAFunds_Form.re
+++ b/src/EAFunds/EAFunds_Form.re
@@ -3,12 +3,23 @@ open EAFunds_Data;
let handleChange = (handleChange, event) =>
handleChange(ReactEvent.Form.target(event)##value);
+module Form = [%lenses
+ type state = {
+ group: string,
+ year: float,
+ output: string,
+ }
+];
+
[@react.component]
let make = () => {
- let (group, setGroup) = React.useState(() => "Animal Welfare Fund");
- let (year, setYear) = React.useState(() => 2021.);
+ let (form, setForm) =
+ React.useState(() =>
+ {Form.group: "Animal Welfare Fund", year: 2021., output: "Donations"}
+ );
let (property, setProperty) = React.useState(() => "Donations");
- let foundGroup = Belt.Array.getBy(EAFunds_Data.funds, r => r.name === group);
+ let foundGroup =
+ Belt.Array.getBy(EAFunds_Data.funds, r => r.name === form.group);
let foundProperty =
switch (property) {
| "Donations" => Some(DONATIONS)
@@ -18,15 +29,20 @@ let make = () => {
<>
Js.Float.toString}
+ value={Form.get(form, Year) |> Js.Float.toString}
onChange={handleChange(r =>
switch (Js.Float.fromString(r)) {
- | r when r >= 2020.0 && r <= 2050.0 => setYear(_ => r)
+ | r when r >= 2020.0 && r <= 2050.0 =>
+ setForm(_ => Form.set(form, Form.Year, r))
| _ => ()
}
)}
/>
- setGroup(r))}>
+
+ setForm(_ => Form.set(form, Form.Group, r))
+ )}>
{EAFunds_Data.funds
|> Array.map(f =>
@@ -46,7 +62,8 @@ let make = () => {
{(
switch (foundGroup, foundProperty) {
- | (Some(g), Some(f)) => EAFunds_Model.run(g.group, year, f)
+ | (Some(g), Some(f)) =>
+ EAFunds_Model.run(g.group, Form.get(form, Year), f)
| _ => ""
}
)
diff --git a/src/EAFunds/EAFunds_Form2.re b/src/EAFunds/EAFunds_Form2.re
index 60137eda..6d0f9844 100644
--- a/src/EAFunds/EAFunds_Form2.re
+++ b/src/EAFunds/EAFunds_Form2.re
@@ -1,16 +1,5 @@
-open BsReform;
open EAFunds_Data;
-module FormConfig = [%lenses
- type state = {
- group: string,
- year: float,
- parameter: string,
- }
-];
-
-module Form = ReForm.Make(FormConfig);
-
let handleChange = (handleChange, event) =>
handleChange(ReactEvent.Form.target(event)##value);
@@ -18,6 +7,7 @@ let handleChange = (handleChange, event) =>
let make = () => {
let (year, setYear) = React.useState(() => 2021.);
<>
+ {"EA Funds Forecasting Model 0.1" |> ReasonReact.string}
Js.Float.toString}
diff --git a/src/EAFunds/EAFunds_Model.bs.js b/src/EAFunds/EAFunds_Model.bs.js
index f9c0530d..44b7f3ce 100644
--- a/src/EAFunds/EAFunds_Model.bs.js
+++ b/src/EAFunds/EAFunds_Model.bs.js
@@ -20,29 +20,29 @@ function calculateDifference(currentValue, yearInQuestion, y) {
return Math$ProbExample.normal(currentValue * meanDiff, 0.2 * stdDevDiff);
}
-function currentValue(group, parameter) {
+function currentValue(group, output) {
if (group) {
switch (group[0]) {
case /* ANIMAL_WELFARE */0 :
- if (parameter) {
+ if (output) {
return 2300000.0;
} else {
return 300000.0;
}
case /* GLOBAL_HEALTH */1 :
- if (parameter) {
+ if (output) {
return 500000.0;
} else {
return 1000000.0;
}
case /* LONG_TERM_FUTURE */2 :
- if (parameter) {
+ if (output) {
return 120000.0;
} else {
return 600000.0;
}
case /* META */3 :
- if (parameter) {
+ if (output) {
return 830000.0;
} else {
return 9300000.0;
@@ -50,7 +50,7 @@ function currentValue(group, parameter) {
}
} else {
- return currentValue(/* Fund */[/* ANIMAL_WELFARE */0], parameter) + currentValue(/* Fund */[/* GLOBAL_HEALTH */1], parameter) + currentValue(/* Fund */[/* LONG_TERM_FUTURE */2], parameter) + currentValue(/* Fund */[/* META */3], parameter);
+ return currentValue(/* Fund */[/* ANIMAL_WELFARE */0], output) + currentValue(/* Fund */[/* GLOBAL_HEALTH */1], output) + currentValue(/* Fund */[/* LONG_TERM_FUTURE */2], output) + currentValue(/* Fund */[/* META */3], output);
}
}
@@ -63,8 +63,8 @@ var PayoutsIfAround = {
currentValue: currentValue
};
-function run(group, year, parameter) {
- return calculateDifference(currentValue(group, parameter), year, /* record */[
+function run(group, year, output) {
+ return calculateDifference(currentValue(group, output), year, /* record */[
/* meanDiff */1.1,
/* stdDiff */1.1
]);
diff --git a/src/EAFunds/EAFunds_Model.re b/src/EAFunds/EAFunds_Model.re
index 8ae52255..2d61897d 100644
--- a/src/EAFunds/EAFunds_Model.re
+++ b/src/EAFunds/EAFunds_Model.re
@@ -22,13 +22,13 @@ module PayoutsIfAround = {
Math.normal(currentValue *. meanDiff, firstYearStdDev *. stdDevDiff);
};
- let rec currentValue = (group: group, parameter) => {
+ let rec currentValue = (group: group, output) => {
let sum = (): float =>
- currentValue(Fund(ANIMAL_WELFARE), parameter)
- +. currentValue(Fund(GLOBAL_HEALTH), parameter)
- +. currentValue(Fund(LONG_TERM_FUTURE), parameter)
- +. currentValue(Fund(META), parameter);
- switch (group, parameter) {
+ currentValue(Fund(ANIMAL_WELFARE), output)
+ +. currentValue(Fund(GLOBAL_HEALTH), output)
+ +. currentValue(Fund(LONG_TERM_FUTURE), output)
+ +. currentValue(Fund(META), output);
+ switch (group, output) {
| (Fund(ANIMAL_WELFARE), DONATIONS) => 300000.0
| (Fund(ANIMAL_WELFARE), PAYOUTS) => 2300000.0
| (Fund(GLOBAL_HEALTH), DONATIONS) => 1000000.0
@@ -42,10 +42,10 @@ module PayoutsIfAround = {
};
};
-let run = (group: group, year: float, parameter: parameter) => {
+let run = (group: group, year: float, output: output) => {
PayoutsIfAround.(
calculateDifference(
- currentValue(group, parameter),
+ currentValue(group, output),
year,
yearlyMeanGrowthRateIfNotClosed(group),
)
@@ -56,6 +56,6 @@ module Model = {
type params = {
groups: array(fundWithInfo),
year: float,
- parameters: array(parameter),
+ outputs: array(output),
};
};
\ No newline at end of file
diff --git a/src/Funds.bs.js b/src/Funds.bs.js
deleted file mode 100644
index fef016a1..00000000
--- a/src/Funds.bs.js
+++ /dev/null
@@ -1,16 +0,0 @@
-'use strict';
-
-var React = require("react");
-var EAFunds_Model$ProbExample = require("./EAFunds/EAFunds_Model.bs.js");
-
-var response = EAFunds_Model$ProbExample.run(/* Fund */[/* GLOBAL_HEALTH */1], 2029, /* DONATIONS */0);
-
-function Funds(Props) {
- return React.createElement("div", undefined, response);
-}
-
-var make = Funds;
-
-exports.response = response;
-exports.make = make;
-/* response Not a pure module */
diff --git a/src/Funds.re b/src/Funds.re
deleted file mode 100644
index 94378d58..00000000
--- a/src/Funds.re
+++ /dev/null
@@ -1,6 +0,0 @@
-let response = EAFunds_Model.run(Fund(GLOBAL_HEALTH), 2029., DONATIONS);
-
-[@react.component]
-let make = () => {
- {React.string(response)}
;
-};
\ No newline at end of file
diff --git a/src/Params.re b/src/Params.re
new file mode 100644
index 00000000..bc0b1473
--- /dev/null
+++ b/src/Params.re
@@ -0,0 +1,17 @@
+type yearAsFloat = {
+ min: option(float),
+ max: option(float),
+};
+
+type namedValue('a) = {
+ name: string,
+ value: 'a,
+};
+
+type choice('a) = list(namedValue('a));
+
+type output =
+ | A
+ | B;
+
+let nOutput: choice(output) = [{name: "sdfsdf", value: A}];
\ No newline at end of file