My agentic slop goes here. Not intended for anyone else!
1open Owntracks_parser
2
3let option_to_json = function
4 | Some v -> v
5 | None -> `Null
6
7let location_to_clickhouse_json record =
8 let point = `A [`Float record.lon; `Float record.lat] in
9 let timestamp_epoch = record.tst in
10 let timestamp_iso = record.timestamp in
11
12 `O [
13 ("timestamp", `String timestamp_iso);
14 ("timestamp_epoch", `Float (float_of_int timestamp_epoch));
15 ("point", point);
16 ("latitude", `Float record.lat);
17 ("longitude", `Float record.lon);
18 ("altitude", option_to_json (Option.map (fun x -> `Float x) record.alt));
19 ("accuracy", option_to_json (Option.map (fun x -> `Float x) record.acc));
20 ("battery", option_to_json (Option.map (fun x -> `Float (float_of_int x)) record.batt));
21 ("tracker_id", option_to_json (Option.map (fun x -> `String x) record.tid));
22 ]
23
24let to_jsonl records =
25 List.map (fun record ->
26 let json = location_to_clickhouse_json record in
27 Ezjsonm.to_string json
28 ) records
29
30let write_jsonl_file path records =
31 let oc = open_out path in
32 List.iter (fun record ->
33 let json = location_to_clickhouse_json record in
34 output_string oc (Ezjsonm.to_string json);
35 output_char oc '\n'
36 ) records;
37 close_out oc
38
39let print_jsonl records =
40 List.iter (fun record ->
41 let json = location_to_clickhouse_json record in
42 print_endline (Ezjsonm.to_string json)
43 ) records