-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change dashboard map to use clustering to handle many devices Alos adds a mix task for generating devices in development --------- Co-authored-by: elliotjon <[email protected]> Co-authored-by: Nate Shoemaker <[email protected]>
- Loading branch information
1 parent
c761c8c
commit 2c9e880
Showing
7 changed files
with
123 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Mix.Tasks.Gen.Devices do | ||
use Mix.Task | ||
|
||
@shortdoc "Generate a mass of devices" | ||
|
||
def run([org_name, product_name, count]) do | ||
Mix.Task.run("app.start") | ||
count = String.to_integer(count) | ||
{:ok, org} = NervesHub.Accounts.get_org_by_name(org_name) | ||
{:ok, product} = NervesHub.Products.get_product_by_org_id_and_name(org.id, product_name) | ||
|
||
current_count = | ||
NervesHub.Devices.get_device_count_by_org_id_and_product_id(org.id, product.id) | ||
|
||
current_count..(current_count + count) | ||
|> Enum.map(fn i -> | ||
if rem(i, 1000) == 0 do | ||
IO.puts("Created #{i} devices...") | ||
end | ||
|
||
lng = -180..180 |> Enum.random() | ||
lat = -90..90 |> Enum.random() | ||
|
||
NervesHub.Devices.create_device(%{ | ||
org_id: org.id, | ||
product_id: product.id, | ||
identifier: "generated-#{i}", | ||
connection_status: :connected, | ||
connection_established_at: DateTime.now!("Etc/UTC"), | ||
connection_last_seen_at: DateTime.now!("Etc/UTC"), | ||
connection_metadata: %{ | ||
"location" => %{ | ||
"longitude" => lng, | ||
"latitude" => lat, | ||
"source" => "generated" | ||
} | ||
} | ||
}) | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters