diff options
Diffstat (limited to 'bin/main.ml')
| -rw-r--r-- | bin/main.ml | 107 |
1 files changed, 105 insertions, 2 deletions
diff --git a/bin/main.ml b/bin/main.ml index 8b1be23..b3f4ec9 100644 --- a/bin/main.ml +++ b/bin/main.ml | |||
| @@ -1,3 +1,106 @@ | |||
| 1 | open Nottui | ||
| 2 | module W = Nottui_widgets | ||
| 3 | |||
| 4 | let f_to_c x = (x -. 32.0) *. 5.0 /. 9.0 | ||
| 5 | let c_to_f x = (x *. 9.0 /. 5.0) +. 32.0 | ||
| 6 | let degrees = Lwd.var 0.0 | ||
| 7 | let farenheit = Lwd.var (nan, ("", 0)) | ||
| 8 | |||
| 9 | let farenheit_text = | ||
| 10 | Lwd.map2 (Lwd.get degrees) (Lwd.get farenheit) ~f:(fun d (d', f) -> | ||
| 11 | if d = d' then f else (string_of_float (c_to_f d), 0)) | ||
| 12 | |||
| 13 | let farenheit_edit = | ||
| 14 | W.edit_field farenheit_text | ||
| 15 | ~on_change:(fun ((text, _) as state) -> | ||
| 16 | let d = | ||
| 17 | match float_of_string_opt text with | ||
| 18 | | None -> Lwd.peek degrees | ||
| 19 | | Some d -> | ||
| 20 | let d = f_to_c d in | ||
| 21 | Lwd.set degrees d; | ||
| 22 | d | ||
| 23 | in | ||
| 24 | Lwd.set farenheit (d, state)) | ||
| 25 | ~on_submit:ignore | ||
| 26 | |||
| 27 | let celsius = Lwd.var (nan, ("", 0)) | ||
| 28 | |||
| 29 | let celsius_text = | ||
| 30 | Lwd.map2 (Lwd.get degrees) (Lwd.get celsius) ~f:(fun d (d', f) -> | ||
| 31 | if d = d' then f else (string_of_float d, 0)) | ||
| 32 | |||
| 33 | let celsius_edit = | ||
| 34 | W.edit_field celsius_text | ||
| 35 | ~on_change:(fun ((text, _) as state) -> | ||
| 36 | let d = | ||
| 37 | match float_of_string_opt text with | ||
| 38 | | None -> Lwd.peek degrees | ||
| 39 | | Some d -> | ||
| 40 | Lwd.set degrees d; | ||
| 41 | d | ||
| 42 | in | ||
| 43 | Lwd.set celsius (d, state)) | ||
| 44 | ~on_submit:ignore | ||
| 45 | |||
| 46 | let root = | ||
| 47 | Lwd_utils.pack Ui.pack_y | ||
| 48 | [ | ||
| 49 | Lwd.pure (W.string "Celsius:"); | ||
| 50 | celsius_edit; | ||
| 51 | Lwd.pure (W.string "Farenheight:"); | ||
| 52 | farenheit_edit; | ||
| 53 | ] | ||
| 54 | |||
| 55 | let root = | ||
| 56 | Lwd_utils.pack Ui.pack_y | ||
| 57 | [ | ||
| 58 | root; | ||
| 59 | root; | ||
| 60 | root; | ||
| 61 | root; | ||
| 62 | root; | ||
| 63 | root; | ||
| 64 | root; | ||
| 65 | root; | ||
| 66 | root; | ||
| 67 | root; | ||
| 68 | root; | ||
| 69 | root; | ||
| 70 | root; | ||
| 71 | root; | ||
| 72 | root; | ||
| 73 | root; | ||
| 74 | root; | ||
| 75 | root; | ||
| 76 | ] | ||
| 77 | |||
| 78 | let root = | ||
| 79 | Lwd_utils.pack Ui.pack_x | ||
| 80 | [ | ||
| 81 | root; | ||
| 82 | root; | ||
| 83 | root; | ||
| 84 | root; | ||
| 85 | root; | ||
| 86 | root; | ||
| 87 | root; | ||
| 88 | root; | ||
| 89 | root; | ||
| 90 | root; | ||
| 91 | root; | ||
| 92 | root; | ||
| 93 | root; | ||
| 94 | root; | ||
| 95 | root; | ||
| 96 | root; | ||
| 97 | root; | ||
| 98 | root; | ||
| 99 | ] | ||
| 100 | |||
| 101 | let root = W.scrollbox root | ||
| 102 | let () = Nottui_unix.run ~tick_period:0.2 root | ||
| 103 | |||
| 1 | open Rdcapsis.Prelude | 104 | open Rdcapsis.Prelude |
| 2 | 105 | ||
| 3 | let () = | 106 | let () = |
| @@ -7,9 +110,9 @@ let () = | |||
| 7 | ~f:(Rdcapsis.Ingcsv.read_channel ~ams_tz) | 110 | ~f:(Rdcapsis.Ingcsv.read_channel ~ams_tz) |
| 8 | |> Result.unwrap | 111 | |> Result.unwrap |
| 9 | in | 112 | in |
| 10 | let euc_id = "EUC" in | 113 | let euc_id = "EUR/C" in |
| 11 | let ledger = | 114 | let ledger = |
| 12 | List.map_result ~f:(Rdcapsis.Convert.les_from_current_acc euc_id) prim_txs | 115 | List.map_result ~f:(Rdcapsis.Convert.les_from_current_acc euc_id) prim_txs |
| 13 | |> Result.unwrap |> List.concat | 116 | |> Result.unwrap |> List.concat |> Rdcapsis.Ledger.make |
| 14 | in | 117 | in |
| 15 | print_endline (Sexp.to_string_hum ([%sexp_of: Rdcapsis.Ledger.t] ledger)) | 118 | print_endline (Sexp.to_string_hum ([%sexp_of: Rdcapsis.Ledger.t] ledger)) |