Skip to content

Commit

Permalink
Add support for min.
Browse files Browse the repository at this point in the history
  • Loading branch information
smimram committed Aug 29, 2023
1 parent 7810548 commit 3d987f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ let () =
w "<body>";
w "<h1>Liquidsoap metrics</h1>";
List.iter
(fun (name, _category, unit, data) ->
(fun (name, _category, unit, min, data) ->
Printf.printf "Plotting '%s'\n" name;
w "<h2>%s</h2>" (String.capitalize_ascii name);
w "<div class=\"plot\">";
let ordinate = Printf.sprintf "value (%s)" unit in
w "%s" (Plot.svg ~abscissa:"time (s)" ~ordinate ~width:800. ~height:400. data);
w "%s" (Plot.svg ~abscissa:"time (s)" ~ordinate ~width:800. ~height:400. ?y_min:min data);
w "</div>"
)
(Metrics.series ());
Expand Down
10 changes: 7 additions & 3 deletions src/metrics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ type entry =
category : string;
value : float;
unit : string;
time : float
time : float;
min : float option
}

type entries =
Expand Down Expand Up @@ -33,14 +34,16 @@ let parse_file fname =
let string = function `String s -> s | _ -> assert false in
let float = function `Float x -> x | _ -> assert false in
let string l k = List.assoc k l |> string in
let float_opt l k = List.assoc_opt k l |> Option.map float in
let float l k = List.assoc k l |> float in
let entries =
List.filter_map
(fun l ->
let string = string l in
let float = float l in
let float_opt = float_opt l in
if List.mem_assoc "commit" l then None else
Some {name = string "name"; category = string "category"; value = float "value"; unit = string "unit"; time = float "time"}
Some {name = string "name"; category = string "category"; value = float "value"; unit = string "unit"; time = float "time"; min = float_opt "min"}
) yaml
in
let branch =
Expand All @@ -63,6 +66,7 @@ let load_dir ?branch dir =
|> Array.to_list
|> List.map (fun s -> dir ^ "/" ^ s)
|> List.filter (fun s -> Filename.check_suffix s ".yaml")
|> List.sort_uniq compare
in
List.iter (add_file ?branch) files

Expand All @@ -87,5 +91,5 @@ let series () =
let e = List.hd l in
let l = List.map (fun e -> e.time, e.value) l in
let l = List.sort (fun (t,_) (t',_) -> compare t t') l in
n, e.category, e.unit, l
n, e.category, e.unit, e.min, l
) (names ())

0 comments on commit 3d987f0

Please sign in to comment.