Iterate over groups with the new MARK AS step

pull/1200/head
Rick Carlino 2020-05-12 11:48:33 -05:00
parent 229aa645c9
commit 786fd450be
4 changed files with 34 additions and 23 deletions

View File

@ -1 +1 @@
10.0.0-rc18
10.0.0-rc19

View File

@ -30,8 +30,7 @@ defmodule FarmbotCeleryScript.Compiler.Sequence do
def compile_sequence_iterable(
iterable_ast,
%{
args:
%{ locals: %{ body: _ } = locals } = sequence_args,
args: %{locals: %{body: _} = locals} = sequence_args,
meta: sequence_meta
} = sequence_ast,
env
@ -114,26 +113,33 @@ defmodule FarmbotCeleryScript.Compiler.Sequence do
end
def create_better_params(body, env) do
parameter_declarations = Enum.reduce(env, %{}, fn
{key, value}, map ->
encoded_label = "#{key}"
if String.starts_with?(encoded_label, "unsafe_") do
Map.put(map, IdentifierSanitizer.to_string(encoded_label), value)
else
map
end
end)
parameter_declarations =
Enum.reduce(env, %{}, fn
{key, value}, map ->
encoded_label = "#{key}"
if String.starts_with?(encoded_label, "unsafe_") do
Map.put(map, IdentifierSanitizer.to_string(encoded_label), value)
else
map
end
end)
Enum.reduce(body, parameter_declarations, fn ast, map ->
case ast do
%{kind: :parameter_application} ->
args = Map.fetch!(ast, :args)
label = Map.fetch!(args, :label)
Map.put(map, label, Map.fetch!(args, :data_value))
%{kind: :variable_declaration} ->
args = Map.fetch!(ast, :args)
label = Map.fetch!(args, :label)
Map.put(map, label, Map.fetch!(args, :data_value))
%{kind: :parameter_declaration} -> map
_ -> raise "How do I compile this? #{inspect(ast)}"
end
%{kind: :parameter_declaration} ->
map
end
end)
end

View File

@ -1,5 +1,5 @@
defmodule FarmbotCeleryScript.Compiler.UpdateResource do
alias FarmbotCeleryScript.{ AST, DotProps}
alias FarmbotCeleryScript.{AST, DotProps}
def update_resource(%AST{args: args, body: body}, _env) do
quote location: :keep do
@ -13,11 +13,15 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
label = Map.fetch!(args, :label)
resource = Map.fetch!(better_params, label)
me.do_update(resource, update)
%AST{kind: :point} ->
me.do_update(variable.args, update)
%AST{kind: :resource} ->
me.do_update(variable.args, update)
res -> raise "Resource error. Please notfiy support: #{inspect(res)}"
res ->
raise "Resource error. Please notfiy support: #{inspect(res)}"
end
end
end
@ -36,11 +40,11 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
def do_update(other, update) do
raise String.trim("""
MARK AS can only be used to mark resources like plants and devices.
It cannot be used on things like coordinates.
Ensure that your sequences and farm events us MARK AS on plants and not
coordinates (#{inspect(other)} / #{inspect(update)})
""")
MARK AS can only be used to mark resources like plants and devices.
It cannot be used on things like coordinates.
Ensure that your sequences and farm events us MARK AS on plants and not
coordinates (#{inspect(other)} / #{inspect(update)})
""")
end
defp unpair([pair | rest], acc) do

View File

@ -35,9 +35,10 @@ defmodule FarmbotOS.SysCalls.ResourceUpdate do
@doc false
def point_update_resource(type, id, params) do
with %{} = point <- Asset.get_point(pointer_type: type, id: id),
with %{} = point <- Asset.get_point(id: id),
{:ok, point} <- Asset.update_point(point, params) do
_ = Private.mark_dirty!(point)
IO.puts("Updated point #{id}: #{inspect(params)}")
:ok
else
nil ->