summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorRutger Broekhoff2025-11-27 23:35:08 +0100
committerRutger Broekhoff2025-11-27 23:35:08 +0100
commit46169ec3eb38e177cafd7faf6338d36c6a9e3971 (patch)
treeff4147b884c2f5533d5a7bae3f1211af43dc14a4 /bin
parent80e1f41596ca9955b432addbf01b913d864aa7c0 (diff)
downloadrdcapsis-ocaml.tar.gz
rdcapsis-ocaml.zip
Whatever all of this isocaml
Diffstat (limited to 'bin')
-rw-r--r--bin/dune2
-rw-r--r--bin/main.ml107
2 files changed, 106 insertions, 3 deletions
diff --git a/bin/dune b/bin/dune
index 34c3866..64e7c56 100644
--- a/bin/dune
+++ b/bin/dune
@@ -3,4 +3,4 @@
3 (name main) 3 (name main)
4 (preprocess 4 (preprocess
5 (pps ppx_jane)) 5 (pps ppx_jane))
6 (libraries rdcapsis)) 6 (libraries rdcapsis imguiml lwd nottui nottui-unix notty notty.unix))
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 @@
1open Nottui
2module W = Nottui_widgets
3
4let f_to_c x = (x -. 32.0) *. 5.0 /. 9.0
5let c_to_f x = (x *. 9.0 /. 5.0) +. 32.0
6let degrees = Lwd.var 0.0
7let farenheit = Lwd.var (nan, ("", 0))
8
9let 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
13let 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
27let celsius = Lwd.var (nan, ("", 0))
28
29let 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
33let 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
46let 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
55let 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
78let 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
101let root = W.scrollbox root
102let () = Nottui_unix.run ~tick_period:0.2 root
103
1open Rdcapsis.Prelude 104open Rdcapsis.Prelude
2 105
3let () = 106let () =
@@ -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))