Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GeoPatch algorithm #264

Merged
7 commits merged into from
Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/archethic/p2p/geo_patch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ defmodule ArchEthic.P2P.GeoPatchTest do
# Edge value
{1, 2, 3, 4} ->
{90, 180}

# France (Bordeaux)
{1, 1, 1, 1} ->
{44.828114, -0.584424}

# France (Limoges)
{2, 2, 2, 2} ->
{45.819792, 1.256239}

# US (Las Vegas)
{3, 3, 3, 3} ->
{36.165362, -115.102552}

# US (Phoenix)
{4, 4, 4, 4} ->
{33.456609, -112.033383}
end
end)

Expand All @@ -40,5 +56,9 @@ defmodule ArchEthic.P2P.GeoPatchTest do
assert "A1A" == GeoPatch.from_ip({15, 62, 246, 57})
assert "021" == GeoPatch.from_ip({109, 164, 214, 168})
assert "8C0" == GeoPatch.from_ip({1, 2, 3, 4})
assert "F1F" == GeoPatch.from_ip({1, 1, 1, 1})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this distance good ? I mean it's almost close

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, first digit F means that longitude is >= -22.5 and < 0, when going in positive we return to 0. i.e 0 is >= 0 and < 22.5.
So just after FFF we have 000.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok .
@imnik11 can you have a last check ?

assert "020" == GeoPatch.from_ip({2, 2, 2, 2})
assert "A1B" == GeoPatch.from_ip({3, 3, 3, 3})
assert "B14" == GeoPatch.from_ip({4, 4, 4, 4})
end
end