lib/step_flow/view/duration_statistics_view.ex

defmodule StepFlow.DurationStatisticsView do
  use StepFlow, :view
  alias StepFlow.DurationStatisticsView

  def render("index.json", %{duration_statistics: %{data: statistics, total: _total}}) do
    %{data: render_many(statistics, DurationStatisticsView, "duration_statistics.json")}
  end

  def render("jobs.json", %{duration_statistics: statistics}) do
    statistics
  end

  def render("show.json", %{duration_statistics: statistics}) do
    render_one(statistics, DurationStatisticsView, "duration_statistics.json")
  end

  def render("duration_statistics.json", %{duration_statistics: statistics}) do
    %{
      count: statistics.count,
      average: statistics.average,
      max: statistics.max,
      min: statistics.min
    }
  end
end