Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
imnik11 committed Apr 12, 2022
1 parent fb31cc1 commit c70da76
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 23 deletions.
41 changes: 41 additions & 0 deletions .iex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,44 @@ alias ArchEthic.TransactionChain
alias ArchEthic.TransactionChain.Transaction
alias ArchEthic.TransactionChain.TransactionData
alias ArchEthic.BeaconChain
alias ArchEthic.Contracts.Interpreter
x = fn -> """
condition inherit: [
content: get_genesis_address(\"000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B\"),
origin_family: biometric
]
actions triggered_by: datetime, at: 1601039923 do
set_type hosting
set_content \"Mr.X: 10, Mr.Y: 8\"
end
""" |> Contracts.parse!() end

y = fn ->

Interpreter.execute({{:., [line: 2],
[
{:__aliases__, [alias: ArchEthic.Contracts.Interpreter.Library],
[:Library]},
:get_genesis_address
]}, [line: 2],
[{:get_in, [line: 2], [{:scope, [line: 2], nil}, ["content"]]}]}, %{ "content" => "000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B" })
end
z = fn ->

Interpreter.execute({{:., [line: 2],
[
{:__aliases__, [alias: ArchEthic.Contracts.Interpreter.Library],
[:Library]},
:get_genesis_address
]}, [line: 2],
[{:get_in, [line: 2], [{:scope, [line: 2], nil}, ["content"]]}]}, %{ "content" => "000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B" })
end
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config

config :logger, level: System.get_env("ARCHETHIC_LOGGER_LEVEL", "debug") |> String.to_atom()
config :logger, level: System.get_env("ARCHETHIC_LOGGER_LEVEL", "error") |> String.to_atom()

config :archethic,
:mut_dir,
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/contracts/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ defmodule ArchEthic.Contracts.Interpreter do
) do
{node, acc}
end

# Whitelist the used of functions in the actions
defp prewalk(node = {{:atom, fun_name}, _, _}, {:ok, acc = %{scope: :actions}})
when fun_name in @transaction_statements_functions_names,
Expand Down
3 changes: 2 additions & 1 deletion lib/archethic/contracts/interpreter/library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ defmodule ArchEthic.Contracts.Interpreter.Library do
else
[] ->
{:error, :network_issue}
# TODO NotFound is not a valid behaviour of P2P GetFirstPublicKey need to address this issue after P2P GetFirstPublicKey

# TODO NotFound is not a valid behaviour of P2P GetFirstPublicKey need to address this issue after P2P GetFirstPublicKey
{:ok, %NotFound{}} ->
address
end
Expand Down
60 changes: 40 additions & 20 deletions lib/archethic/p2p/geo_patch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ defmodule ArchEthic.P2P.GeoPatch do
Enum.take_random(list_char, 3) |> List.to_string()
end

defp compute_patch(lat, lon) do
def list_of_coordinates() do
l = for lat <- 0..90, do: for(lon <- 0..180, do: {lat, lon})

l = List.flatten(l) |> Enum.uniq()

patches =
Enum.map(l, fn {x, y} ->
compute_patch(y, x)
end)

patches |> Enum.to_list() |> Enum.uniq()
IO.inspect(patches)
end

def compute_patch(lat, lon) do
lat_sign = sign(lat)
lon_sign = sign(lon)

Expand Down Expand Up @@ -56,25 +70,31 @@ defmodule ArchEthic.P2P.GeoPatch do
patch
end

defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < -0.5 and s_i >= -1, do: '0'
defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 0 and s_i >= -0.5, do: '1'
defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 0.5 and s_i >= 0, do: '2'
defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 1 and s_i >= 0.5, do: '3'

defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < -0.5 and s_i >= -1, do: '4'
defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 0 and s_i >= -0.5, do: '5'
defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 0.5 and s_i >= 0, do: '6'
defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 1 and s_i >= 0.5, do: '7'

defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < -0.5 and s_i >= -1, do: '8'
defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 0 and s_i >= -0.5, do: '9'
defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 0.5 and s_i >= 0, do: 'A'
defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 1 and s_i >= 0.5, do: 'B'

defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < -0.5 and s_i >= -1, do: 'C'
defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 0 and s_i >= -0.5, do: 'D'
defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 0.5 and s_i >= 0, do: 'E'
defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 1 and s_i >= 0.5, do: 'F'
defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= -0.5 and s_i >= -1, do: '0'
defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 0 and s_i >= -0.5, do: '1'
defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 0.5 and s_i >= 0, do: '2'
defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 1 and s_i >= 0.5, do: '3'

defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= -0.5 and s_i >= -1, do: '4'
defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 0 and s_i >= -0.5, do: '5'
defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 0.5 and s_i >= 0, do: '6'
defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 1 and s_i >= 0.5, do: '7'

defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= -0.5 and s_i >= -1,
do: '8'

defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 0 and s_i >= -0.5, do: '9'
defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 0.5 and s_i >= 0, do: 'A'
defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 1 and s_i >= 0.5, do: 'B'

defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= -0.5 and s_i >= -1,
do: 'C'

defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 0 and s_i >= -0.5,
do: 'D'

defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 0.5 and s_i >= 0, do: 'E'
defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 1 and s_i >= 0.5, do: 'F'

defp sign(number) when number < 0, do: -1
defp sign(number) when number >= 0, do: 1
Expand Down

0 comments on commit c70da76

Please sign in to comment.