Starting to refactor into EAFunds_Model

This commit is contained in:
Ozzie Gooen 2020-02-08 18:09:44 +00:00
parent 7393f88bfd
commit 6d94cb3227
3 changed files with 171 additions and 39 deletions

View File

@ -1,6 +1,10 @@
'use strict';
var Block = require("bs-platform/lib/js/block.js");
var Curry = require("bs-platform/lib/js/curry.js");
var CamlinternalOO = require("bs-platform/lib/js/camlinternalOO.js");
var Math$ProbExample = require("../Math.bs.js");
var Model$ProbExample = require("../Model.bs.js");
function yearDiff(year) {
return year - 2020.0;
@ -70,9 +74,102 @@ function run(group, year, output) {
]);
}
var Model = { };
var model_002 = /* assumptions : :: */[
Model$ProbExample.Input.make("Yearly Growth Rate", /* FloatPoint */0, undefined, /* () */0),
/* :: */[
Model$ProbExample.Input.currentYear,
/* [] */0
]
];
var model_003 = /* inputs : :: */[
Model$ProbExample.Input.make("Fund", /* SingleChoice */Block.__(1, [/* record */[
/* options : :: */[
/* tuple */[
"Animal Welfare Fund",
"animal"
],
/* :: */[
/* tuple */[
"Global Health Fund",
"globalHealth"
],
/* :: */[
/* tuple */[
"Long Term Future Fund",
"longTerm"
],
/* :: */[
/* tuple */[
"Meta Fund",
"metaFund"
],
/* :: */[
/* tuple */[
"Total",
"total"
],
/* [] */0
]
]
]
]
],
/* default */"total"
]]), undefined, /* () */0),
/* :: */[
Model$ProbExample.Input.make("Year", /* Year */Block.__(0, [/* record */[
/* default */2030.0,
/* min */2020.0,
/* max */2050.0
]]), undefined, /* () */0),
/* [] */0
]
];
var model_004 = /* outputs : :: */[
Model$ProbExample.Output.make("Payments", /* FloatCdf */2, undefined, /* () */0),
/* :: */[
Model$ProbExample.Output.make("Payouts", /* FloatCdf */2, undefined, /* () */0),
/* [] */0
]
];
var model = /* record */[
/* name */"Calculate the payments and payouts of EA Funds based on existing data.",
/* author */"George Harrison",
model_002,
model_003,
model_004
];
var class_tables = [
0,
0,
0
];
function run$1(a, i) {
if (!class_tables[0]) {
var $$class = CamlinternalOO.create_table(0);
var env = CamlinternalOO.new_variable($$class, "");
var env_init = function (env$1) {
var self = CamlinternalOO.create_object_opt(0, $$class);
self[env] = env$1;
return self;
};
CamlinternalOO.init_class($$class);
class_tables[0] = env_init;
}
return Curry._1(class_tables[0], 0);
}
var Interface = {
model: model,
run: run$1
};
exports.PayoutsIfAround = PayoutsIfAround;
exports.run = run;
exports.Model = Model;
/* No side effect */
exports.Interface = Interface;
/* model Not a pure module */

View File

@ -52,10 +52,47 @@ let run = (group: group, year: float, output: output) => {
);
};
module Model = {
type params = {
groups: array(fundWithInfo),
year: float,
outputs: array(output),
module Interface = {
open Model;
let model = {
name: "Calculate the payments and payouts of EA Funds based on existing data.",
author: "George Harrison",
assumptions: [
Input.make(~name="Yearly Growth Rate", ~parameterType=FloatPoint, ()),
Input.currentYear,
],
inputs: [
Input.make(
~name="Fund",
~parameterType=
SingleChoice({
default: Some("total"),
options: [
("Animal Welfare Fund", "animal"),
("Global Health Fund", "globalHealth"),
("Long Term Future Fund", "longTerm"),
("Meta Fund", "metaFund"),
("Total", "total"),
],
}),
(),
),
Input.make(
~name="Year",
~parameterType=
Year({
default: Some(2030.0),
min: Some(2020.0),
max: Some(2050.0),
}),
(),
),
],
outputs: [
Output.make(~name="Payments", ~parameterType=FloatCdf, ()),
Output.make(~name="Payouts", ~parameterType=FloatCdf, ()),
],
};
let run = (a, i) => {};
};

View File

@ -1,22 +1,40 @@
module IOTypes = {
type singleChoice = {options: list(string)};
type singleChoice = {
options: list((string, string)),
default: option(string),
};
type floatPoint = {validatations: list(float => bool)};
type withDefault('a) = {default: option('a)};
type withDefaultMinMax('a) = {
default: option('a),
min: option('a),
max: option('a),
};
};
module Input = {
type parameterType =
| Year(IOTypes.withDefault(float))
| Year(IOTypes.withDefaultMinMax(float))
| SingleChoice(IOTypes.singleChoice)
| FloatPoint
| FloatCdf;
type parameter = {
id: string,
name: string,
parameterType,
};
let make = (name, parameterType) => {name, parameterType};
let currentYear = {
id: "currentyear",
name: "Current Year",
parameterType: FloatPoint,
};
let make = (~name, ~parameterType, ~id=name, ()) => {
id,
name,
parameterType,
};
};
module Output = {
@ -27,42 +45,22 @@ module Output = {
| FloatCdf;
type parameter = {
id: string,
name: string,
parameterType,
};
let make = (name, parameterType) => {name, parameterType};
let make = (~name, ~parameterType, ~id=name, ()) => {
id,
name,
parameterType,
};
};
type props = {
type model = {
name: string,
author: string,
assumptions: list(Input.parameter),
inputs: list(Input.parameter),
outputs: list(Output.parameter),
};
let model1 = {
name: "Calculate the payments and payouts of EA Funds based on existing data.",
author: "George Harrison",
assumptions: [Input.make("Yearly Growth Rate", FloatPoint)],
inputs: [
Input.make(
"Fund",
SingleChoice({
options: [
"Animal Welfare Fund",
"Global Health Fund",
"Long Term Future Fund",
"Meta Fund",
"Total",
],
}),
),
{name: "Year", parameterType: Year({default: Some(2030.0)})},
],
outputs: [
Output.make("Payments", FloatCdf),
Output.make("Payouts", FloatCdf),
],
};