Merge branch 'recovery_release' into mark_as

mark_as
Rick Carlino 2020-04-28 14:19:29 -05:00
commit c0670ec19a
3 changed files with 37 additions and 8 deletions

View File

@ -132,15 +132,14 @@ defmodule FarmbotCore.Asset.CriteriaRetriever do
end
defp stage_1_day_field({pg, accum}) do
day_criteria = pg.criteria["day"] || %{}
days = day_criteria["days_ago"] || 0
day_criteria = pg.criteria["day"] || pg.criteria[:day] || %{}
days = day_criteria["days_ago"] || day_criteria[:days_ago] || 0
op = day_criteria["op"] || day_criteria[:op] || "<"
time = Timex.shift(Timex.now(), days: -1 * days)
if days == 0 do
{ pg, accum }
else
op = day_criteria["op"] || "<"
time = Timex.shift(Timex.now(), days: -1 * days)
inverted_op = if op == ">" do "<" else ">" end
{ pg, accum ++ [{"created_at", inverted_op, time}] }

View File

@ -37,6 +37,7 @@ defmodule FarmbotCore.Asset.Point do
meta: point.meta,
name: point.name,
plant_stage: point.plant_stage,
created_at: point.created_at,
planted_at: point.planted_at,
pointer_type: point.pointer_type,
radius: point.radius,

View File

@ -124,8 +124,6 @@ defmodule FarmbotCore.Asset.CriteriaRetrieverTest do
expect(Timex, :now, fn -> @now end)
pg = point_group_with_fake_points()
# This one is _almost_ a perfect match,
# but the meta field is a miss.
point!(%{
id: 888,
created_at: @five_days_ago,
@ -525,6 +523,37 @@ defmodule FarmbotCore.Asset.CriteriaRetrieverTest do
assert Enum.count(ids) == 1
end
test "edge case: Retrieves by `day` criteria only" do
Repo.delete_all(PointGroup)
Repo.delete_all(Point)
days_ago4 = Timex.shift(@now, days: -4)
days_ago2 = Timex.shift(@now, days: -2)
expect(Timex, :now, fn -> @now end)
point!(%{id: 1, pointer_type: "Plant", created_at: days_ago4})
p2 = point!(%{id: 2, pointer_type: "Plant", created_at: days_ago2})
pg1 = %PointGroup{
id: 212,
created_at: Timex.shift(@now, hours: -1),
updated_at: Timex.shift(@now, hours: -1),
name: "Less than 2 days ago",
point_ids: [],
sort_type: "yx_descending",
criteria: %{
day: %{"op" => "<", "days_ago" => 3},
string_eq: %{},
number_eq: %{},
number_lt: %{},
number_gt: %{}
}
}
ids = CriteriaRetriever.run(pg1) |> Enum.map(fn p -> p.id end)
assert Enum.count(ids) == 1
assert Enum.member?(ids, p2.id)
end
test "edge case: Filter by slot direction" do
Repo.delete_all(PointGroup)
Repo.delete_all(Point)