Skip to content

Commit

Permalink
Tidy up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lawik committed Oct 29, 2024
1 parent 0cb2d0e commit 4b2bb54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
87 changes: 41 additions & 46 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ Hooks.WorldMap = {
// progressBar.style.width = Math.round(processed / total * 100) + '%';
}

console.log(processed, total)

if (processed === total) {
// all markers processed - hide the progress bar:
// progress.classList.add = 'hidden';
Expand Down Expand Up @@ -300,80 +298,77 @@ Hooks.WorldMap = {
let mode = this.el.dataset.mode;
var devices = [];

var clusterLayer = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: this.updateProgressBar });
for (let i = 0; i < markers.length; i++) {
let marker = markers[i];
let location = marker["l"];
if (location["ng"] !== undefined && location["at"] !== undefined) {
let latlng = [location["at"], location["ng"]];
let newMarker;
switch (mode) {
case 'connected':
if (marker["s"] == "connected") {
newMarker = L.marker(latlng, markerConnectedOptions);
} else {
newMarker = L.marker(latlng, markerOfflineOptions);
}
break;
case 'updated':
// Only show connected ones, the offline ones are just confusing
if (marker["s"] == "connected") {
if (marker["lf"]) {
newMarker = L.marker(latlng, markerUpdatedOptions);
} else {
newMarker = L.marker(latlng, markerOutdatedOptions);
}
}
break;
default:
}
devices.push(newMarker);
}
}
var myRenderer = L.canvas({ padding: 0.5 });

var markerConnectedOptions = {
radius: 6,
fillColor: "#4dd54f",
weight: 1,
opacity: 0,
fillOpacity: 1
fillOpacity: 1,
renderer: myRenderer
};

var markerOfflineOptions = {
radius: 6,
fillColor: "rgba(196,49,49,1)",
weight: 1,
opacity: 0,
fillOpacity: 1
fillOpacity: 1,
renderer: myRenderer
};

var markerUpdatedOptions = {
radius: 6,
fillColor: "#4dd54f",
weight: 1,
opacity: 0,
fillOpacity: 1
fillOpacity: 1,
renderer: myRenderer
};

var markerOutdatedOptions = {
radius: 6,
fillColor: "rgba(99,99,99,1)",
weight: 1,
opacity: 0,
fillOpacity: 1
fillOpacity: 1,
renderer: myRenderer
};

// Clear previous defined device layer before adding markers
// if (this.deviceLayer !== undefined) { this.map.removeLayer(this.deviceLayer); }

// let f = 0;
// this.deviceLayer = L.geoJson(devices, {
// pointToLayer: function (feature, latlng) {
var clusterLayer = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: this.updateProgressBar });
for (let i = 0; i < markers.length; i++) {
let marker = markers[i];
let location = marker["l"];
if (location["ng"] !== undefined && location["at"] !== undefined) {
let latlng = [location["at"], location["ng"]];
let newMarker = false;
switch (mode) {
case 'connected':
if (marker["s"] == "connected") {
newMarker = L.circleMarker(latlng, markerConnectedOptions);
} else {
newMarker = L.circleMarker(latlng, markerOfflineOptions);
}
break;
case 'updated':
// Only show connected ones, the offline ones are just confusing
if (marker["s"] == "connected") {
if (marker["lf"]) {
newMarker = L.circleMarker(latlng, markerUpdatedOptions);
} else {
newMarker = L.circleMarker(latlng, markerOutdatedOptions);
}
}
break;
default:
}
if (newMarker) {
devices.push(newMarker);
}
}
}

// }
// });
console.log(devices.length)
console.log("updated end")
clusterLayer.addLayers(devices);
this.map.addLayer(clusterLayer)
}
Expand Down
9 changes: 3 additions & 6 deletions lib/nerves_hub_web/live/dashboard/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule NervesHubWeb.Live.Dashboard.Index do
|> assign(:time, time())
|> assign(:next_timer, nil)
|> assign(:loading?, true)
|> assign(:mode, "connected")
|> assign(:mode, "updated")
|> assign(:device_count, 0)
|> assign(:marker_count, 0)
|> refresh_after(1)
Expand Down Expand Up @@ -81,7 +81,6 @@ defmodule NervesHubWeb.Live.Dashboard.Index do
end

defp update_devices_and_markers(%{assigns: %{org: org, product: product}} = socket) do
IO.puts("Starting...")
t = time()
duration = t - socket.assigns.time

Expand All @@ -101,8 +100,6 @@ defmodule NervesHubWeb.Live.Dashboard.Index do

subscribe_to_devices(socket, devices)

IO.puts("Done!")

socket
|> assign(:time, t)
|> assign(:loading?, false)
Expand All @@ -120,8 +117,8 @@ defmodule NervesHubWeb.Live.Dashboard.Index do

defp generate_map_marker(
%{
id: id,
identifier: identifier,
id: _id,
identifier: _identifier,
connection_status: connection_status,
longitude: longitude,
latitude: latitude,
Expand Down

0 comments on commit 4b2bb54

Please sign in to comment.