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))