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