Skip to content

Commit

Permalink
Compute monthly average
Browse files Browse the repository at this point in the history
  • Loading branch information
thbar committed Oct 13, 2024
1 parent dd8116c commit e18265c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions livebook/irve-total.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ VegaLite.new(width: 800)
|> VegaLite.encode_field(:y, "row_count", type: :quantitative)
|> VegaLite.encode_field(:color, "row_count", type: :quantitative)
```

```elixir
month_trunc = fn(d) ->
Date.new!(d.year, d.month, 1)
end

data
|> Enum.group_by(
fn(x) -> x["inserted_at"] |> month_trunc.() end,
fn(x) -> x["row_count"] end
)
|> Enum.map(
fn({a,b}) ->
%{date: a, pdc_count: (Enum.sum(b) / length(b)) |> trunc()}
end)
|> Kino.DataTable.new()

```

0 comments on commit e18265c

Please sign in to comment.