<commit_before>open! Core.Std
open! Async.Std

type deploy_strategy = Before | After of int [@@deriving sexp, yojson]

type json = [ `Assoc of (string * json) list
            | `Bool of bool
            | `Float of float
            | `Int of int
            | `List of json list
            | `Null
            | `String of string ] [@@deriving sexp, yojson]

type t = {
  deploy : deploy_strategy;
  spec : json;
  health_timeout : int;
  stop_timeout : int;
} [@@deriving sexp, yojson]

let int_field v k ~default =
  match Edn.Util.(v |> member (`Keyword (None, k))) with
  | `Int v -> Ok v
  | `Null -> Ok default
  | _ -> Error (sprintf "`%s` should be integer" k)

let parse_spec v =
  let open Result.Let_syntax in
  let%bind spec = match Edn.Util.(v |> member (`Keyword (None, "spec"))) with
  | `Assoc _ as spec -> Ok spec
  | _ -> Error "`spec` keyword with map is required" in
  let deploy' = Edn.Util.(v |> member (`Keyword (None, "deploy"))) in
  let%bind health_timeout = int_field v "health-timeout" ~default:10 in
  let%bind stop_timeout = int_field v "health-timeout" ~default:10 in
  let%map deploy = match deploy' with
  | `Null -> Ok Before
  | `Vector [`Keyword (None, "after"); `Int timeout] -> Ok (After timeout)
  | `Vector [`Keyword (None, "before")] -> Ok Before
  | _ -> Error "`deploy` option should be [:Before] or [:After timeout] where timeout is number of seconds before previous container termination" in
  {deploy; spec = (Edn.Json.to_json spec); health_timeout; stop_timeout}

let from_file path =<commit_msg>before / after in spec fixed<commit_after>open! Core.Std
open! Async.Std

type deploy_strategy = Before | After of int [@@deriving sexp, yojson]

type json = [ `Assoc of (string * json) list
            | `Bool of bool
            | `Float of float
            | `Int of int
            | `List of json list
            | `Null
            | `String of string ] [@@deriving sexp, yojson]

type t = {
  deploy : deploy_strategy;
  spec : json;
  health_timeout : int;
  stop_timeout : int;
} [@@deriving sexp, yojson]

let int_field v k ~default =
  match Edn.Util.(v |> member (`Keyword (None, k))) with
  | `Int v -> Ok v
  | `Null -> Ok default
  | _ -> Error (sprintf "`%s` should be integer" k)

let parse_spec v =
  let open Result.Let_syntax in
  let%bind spec = match Edn.Util.(v |> member (`Keyword (None, "spec"))) with
  | `Assoc _ as spec -> Ok spec
  | _ -> Error "`spec` keyword with map is required" in
  let deploy' = Edn.Util.(v |> member (`Keyword (None, "deploy"))) in
  let%bind health_timeout = int_field v "health-timeout" ~default:10 in
  let%bind stop_timeout = int_field v "health-timeout" ~default:10 in
  let%map deploy = match deploy' with
  | `Null -> Ok Before
  | `Vector [`Keyword (None, "After"); `Int timeout] -> Ok (After timeout)
  | `Vector [`Keyword (None, "Before")] -> Ok Before
  | _ -> Error "`deploy` option should be [:Before] or [:After timeout] where timeout is number of seconds before previous container termination" in
  {deploy; spec = (Edn.Json.to_json spec); health_timeout; stop_timeout}

let from_file path =
{'fraction_non_alphanumeric': 0.1316382362407467, 'fraction_numerical': 0.002574831026713872, 'mean_word_length': 3.0948616600790513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2594555', 'n_tokens_mistral': 1022, 'n_tokens_neox': 1007, 'n_words': 368}