My aggregated monorepo of OCaml code, automaintained
at main 60 lines 1.8 kB view raw
1(** Read progress.json for dashboard display *) 2 3type phase = 4 | Solving 5 | Blessings 6 | Building 7 | Gc 8 | Completed 9 10let phase_of_string = function 11 | "solving" -> Solving 12 | "blessings" -> Blessings 13 | "building" -> Building 14 | "gc" -> Gc 15 | "completed" -> Completed 16 | _ -> Solving 17 18let phase_to_string = function 19 | Solving -> "Solving" 20 | Blessings -> "Computing Blessings" 21 | Building -> "Building" 22 | Gc -> "Garbage Collection" 23 | Completed -> "Completed" 24 25type t = { 26 run_id : string; 27 start_time : string; 28 phase : phase; 29 targets : string list; 30 solutions_found : int; 31 solutions_failed : int; 32 build_completed : int; 33 build_total : int; 34 doc_completed : int; 35 doc_total : int; 36} 37 38let read ~log_dir ~run_id = 39 let path = Filename.concat log_dir 40 (Filename.concat "runs" (Filename.concat run_id "progress.json")) in 41 if Sys.file_exists path then 42 try 43 let content = In_channel.with_open_text path In_channel.input_all in 44 let json = Yojson.Safe.from_string content in 45 let open Yojson.Safe.Util in 46 Some { 47 run_id = json |> member "run_id" |> to_string; 48 start_time = json |> member "start_time" |> to_string; 49 phase = json |> member "phase" |> to_string |> phase_of_string; 50 targets = json |> member "targets" |> to_list |> List.map to_string; 51 solutions_found = json |> member "solutions_found" |> to_int; 52 solutions_failed = json |> member "solutions_failed" |> to_int; 53 build_completed = json |> member "build_completed" |> to_int; 54 build_total = json |> member "build_total" |> to_int; 55 doc_completed = json |> member "doc_completed" |> to_int; 56 doc_total = json |> member "doc_total" |> to_int; 57 } 58 with _ -> None 59 else 60 None