First prototype of conditionals
This commit is contained in:
		
							parent
							
								
									dfbdc51085
								
							
						
					
					
						commit
						2f503fbef6
					
				|  | @ -2,12 +2,20 @@ module Value = { | |||
|   type binaryConditional = | ||||
|     | Selected(bool) | ||||
|     | Unselected; | ||||
| 
 | ||||
|   type conditional = { | ||||
|     statement: string, | ||||
|     truthValue: bool, | ||||
|   }; | ||||
| 
 | ||||
|   type t = | ||||
|     | BinaryConditional(binaryConditional) | ||||
|     | SelectSingle(string) | ||||
|     | DateTime(MomentRe.Moment.t) | ||||
|     | FloatPoint(float) | ||||
|     | Probability(float) | ||||
|     | Conditional(conditional) | ||||
|     | ConditionalArray(array(conditional)) | ||||
|     | FloatCdf(string); | ||||
| 
 | ||||
|   let to_string = (t: t) => { | ||||
|  | @ -36,6 +44,8 @@ module Value = { | |||
|       ) | ||||
|       |> ReasonReact.string | ||||
|     | SelectSingle(r) => r |> ReasonReact.string | ||||
|     | ConditionalArray(r) => "Array" |> ReasonReact.string | ||||
|     | Conditional(r) => r.statement |> ReasonReact.string | ||||
|     | FloatCdf(r) => | ||||
|       let cdf: Types.distribution = | ||||
|         CdfLibrary.Distribution.fromString(r, 2000); | ||||
|  | @ -65,6 +75,16 @@ module Type = { | |||
|     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 withDefaultMinMax('a) = { | ||||
|  | @ -82,11 +102,13 @@ module Type = { | |||
|     | Probability(withDefault(float)) | ||||
|     | DateTime(withDefaultMinMax(MomentRe.Moment.t)) | ||||
|     | Year(withDefaultMinMax(float)) | ||||
|     | Conditionals(conditionals) | ||||
|     | FloatCdf; | ||||
| 
 | ||||
|   let default = (t: t) => | ||||
|     switch (t) { | ||||
|     | BinaryConditional => Some(Value.BinaryConditional(Unselected)) | ||||
|     | Conditionals(s) => Some(Value.ConditionalArray(s.defaults)) | ||||
|     | Year(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)) | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ let make = | |||
|       ~onChange: onChange, | ||||
|     ) => { | ||||
|   switch (type_.type_, value) { | ||||
|   | (Conditionals(_), r) => "sdfsdf" |> ReasonReact.string | ||||
|   | (Year(_), Some(FloatPoint(r))) => | ||||
|     <input | ||||
|       className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" | ||||
|  |  | |||
|  | @ -152,7 +152,6 @@ module Interface = { | |||
|         Some(DateTime(intendedYear)), | ||||
|         Some(DateTime(currentYear)), | ||||
|         Some(SelectSingle(output)), | ||||
|         Some(BinaryConditional(r)), | ||||
|       |] => | ||||
|       choiceFromString(fund) | ||||
|       |> E.O.fmap(fund => | ||||
|  | @ -230,14 +229,16 @@ module Interface = { | |||
|             }), | ||||
|           (), | ||||
|         ), | ||||
|         TypeWithMetadata.make( | ||||
|           ~name="Conditional on World Ending", | ||||
|           ~id="worldEnd", | ||||
|           ~type_=BinaryConditional, | ||||
|           (), | ||||
|         ), | ||||
|       |], | ||||
|       outputTypes: [||], | ||||
|       run, | ||||
|     }; | ||||
| }; | ||||
| } /* )*/; | ||||
| // TypeWithMetadata.make( | ||||
| //   ~name="Conditional on World Ending", | ||||
| //   ~id="worldEnd", | ||||
| //   ~type_= | ||||
| //     Conditionals( | ||||
| //       Prop.Type.makeConditionals([||], [|"Foo", "Bar", "Char"|]), | ||||
| //     ), | ||||
| //   (), | ||||
|  | @ -1,4 +1,9 @@ | |||
| module Model = { | ||||
|   let foo = { | ||||
|     let bar = 2.0; | ||||
|     (); | ||||
|   }; | ||||
| 
 | ||||
|   let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => { | ||||
|     let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.; | ||||
|     Prop.Value.Probability(0.001 *. yearDiff); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user