From 641c3aadde885ffda50476b3398c06a4107e9a65 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Mon, 10 Feb 2020 23:32:44 +0000 Subject: [PATCH] Attempted to add new model, but now everything is broken --- package.json | 2 +- src/models/GlobalCatastrophe.re | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/models/GlobalCatastrophe.re diff --git a/package.json b/package.json index 8d177fdd..1ac59fb6 100644 --- a/package.json +++ b/package.json @@ -46,4 +46,4 @@ "moduleserve": "^0.9.0", "tailwindcss": "^1.2.0" } -} +} \ No newline at end of file diff --git a/src/models/GlobalCatastrophe.re b/src/models/GlobalCatastrophe.re new file mode 100644 index 00000000..97888bb0 --- /dev/null +++ b/src/models/GlobalCatastrophe.re @@ -0,0 +1,59 @@ +module Model = { + let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => { + let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.; + Prop.Value.Probability((100. -. yearDiff) /. 100.); + }; +}; + +module Interface = { + let dayKey = "Day"; + + let run = (p: Prop.Combo.t) => { + switch (Prop.Combo.InputValues.toValueArray(p)) { + | [|Some(DateTime(intendedYear)), Some(DateTime(currentYear))|] => + Some(Model.make(intendedYear, currentYear)) + | _ => None + }; + }; + + let model: Prop.Model.t = + Prop.{ + name: "Global Catastrophe", + description: "The chances of catastrophe per year in the future.", + version: "1.0.0", + author: "Ozzie Gooen", + inputTypes: [| + TypeWithMetadata.make( + ~name=dayKey, + ~type_= + DateTime({ + default: + Some( + MomentRe.Moment.add( + ~duration=MomentRe.duration(5., `years), + MomentRe.momentNow(), + ), + ), + min: + Some( + MomentRe.Moment.subtract( + ~duration=MomentRe.duration(20., `years), + MomentRe.momentNow(), + ), + ), + max: + Some( + MomentRe.Moment.add( + ~duration=MomentRe.duration(20., `years), + MomentRe.momentNow(), + ), + ), + }), + (), + ), + TypeWithMetadata.currentYear, + |], + outputTypes: [||], + run, + }; +}; \ No newline at end of file