From 6d94cb3227c2768d45a944f569b013685b441e88 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 8 Feb 2020 18:09:44 +0000 Subject: [PATCH] Starting to refactor into EAFunds_Model --- src/EAFunds/EAFunds_Model.bs.js | 103 +++++++++++++++++++++++++++++++- src/EAFunds/EAFunds_Model.re | 47 +++++++++++++-- src/Model.re | 60 +++++++++---------- 3 files changed, 171 insertions(+), 39 deletions(-) diff --git a/src/EAFunds/EAFunds_Model.bs.js b/src/EAFunds/EAFunds_Model.bs.js index 44b7f3ce..248540e2 100644 --- a/src/EAFunds/EAFunds_Model.bs.js +++ b/src/EAFunds/EAFunds_Model.bs.js @@ -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 */ diff --git a/src/EAFunds/EAFunds_Model.re b/src/EAFunds/EAFunds_Model.re index 2d61897d..9ee92a4f 100644 --- a/src/EAFunds/EAFunds_Model.re +++ b/src/EAFunds/EAFunds_Model.re @@ -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) => {}; }; \ No newline at end of file diff --git a/src/Model.re b/src/Model.re index ae3f8434..5c8e78ed 100644 --- a/src/Model.re +++ b/src/Model.re @@ -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), - ], }; \ No newline at end of file