fix alt_unit_names

This commit is contained in:
swrup 2026-02-27 22:05:47 +01:00
parent 19b4188f7c
commit 9ebe44c83f
4 changed files with 45 additions and 56 deletions

View file

@ -87,6 +87,35 @@ module Exchangedb_postgres = struct
end
module Currency = struct
module Alt_unit_names = struct
open Syntax
module Int_map = Map.Make (Int)
module String_map = Map.Make (String)
type t = string Int_map.t
let jsont =
let of_string_map str_map =
str_map
|> String_map.to_list
|> list_map (fun (k, v) ->
match int_of_string_opt k with
| None -> Error "not an integer"
| Some k -> Ok (k, v))
|> function
| Error e -> Jsont.Error.msg Jsont.Meta.none e
| Ok l -> Int_map.of_list l
in
let to_string_map int_map =
int_map
|> Int_map.to_list
|> List.map (fun (k, v) -> (string_of_int k, v))
|> String_map.of_list
in
let string_map_jsont = Jsont.Object.as_string_map Jsont.string in
Jsont.map ~dec:of_string_map ~enc:to_string_map string_map_jsont
end
type t = {
enabled: [ `YES | `NO ];
code: string;
@ -94,7 +123,7 @@ module Currency = struct
fractional_input_digits: int;
fractional_normal_digits: int;
fractional_trailing_zero_digits: int;
alt_unit_names: (int * string) list;
alt_unit_names: Alt_unit_names.t;
}
let currency_sections =
@ -113,12 +142,13 @@ module Currency = struct
fractional_trailing_zero_digits=
get "fractional_trailing_zero_digits" |> int;
alt_unit_names=
get "alt_unit_names" |> Alt_unit_names.decode |> Parse_config.unwrap;
get "alt_unit_names"
|> Jsont_bytesrw.decode_string Alt_unit_names.jsont
|> Parse_config.unwrap;
}
let all_currencies = List.map parse_currency currency_sections
(* I think the exchange only handle one currency *)
let v =
match
List.find_opt (fun v -> v.code = Exchange.currency) all_currencies