-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeasurement.ex
More file actions
65 lines (53 loc) · 1.3 KB
/
measurement.ex
File metadata and controls
65 lines (53 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
defmodule ElixirBench.Benchmarks.Measurement do
use Ecto.Schema
import Ecto.Changeset
alias ElixirBench.Benchmarks.{Benchmark, Job, Measurement}
schema "measurements" do
belongs_to(:benchmark, Benchmark)
belongs_to(:job, Job)
field :sample_size, :integer
field :mode, {:array, :float}
field :minimum, :float
field :median, :float
field :maximum, :float
field :average, :float
field :std_dev, :float
field :std_dev_ratio, :float
field :ips, :float
field :std_dev_ips, :float
field :percentiles, :map
timestamps(type: :utc_datetime)
end
@fields [
:sample_size,
:minimum,
:median,
:maximum,
:average,
:std_dev,
:std_dev_ratio,
:ips,
:std_dev_ips,
:percentiles
]
@required_fields @fields -- [:mode]
@doc false
def changeset(%Measurement{} = measurement, attrs) do
measurement
|> cast(attrs, @fields)
|> validate_required(@required_fields)
|> set_mode(attrs)
end
# Benchee can return a uniq value for mode so we need to make it an array
defp set_mode(changeset, attrs) do
mode = get_in(attrs, ["mode"])
mode =
cond do
is_integer(mode) or is_float(mode) ->
[mode]
true ->
mode
end
cast(changeset, %{mode: mode}, [:mode])
end
end