diff --git a/app/Locabean/res/layout/activity_node.xml b/app/Locabean/res/layout/activity_node.xml
index 894342d..760c051 100644
--- a/app/Locabean/res/layout/activity_node.xml
+++ b/app/Locabean/res/layout/activity_node.xml
@@ -57,15 +57,6 @@
android:layout_marginBottom="27dp"
android:text="@string/send" />
-
-
+
+
\ No newline at end of file
diff --git a/locaudio/detectionserver.py b/locaudio/detectionserver.py
index 5b8d88b..75e78c5 100644
--- a/locaudio/detectionserver.py
+++ b/locaudio/detectionserver.py
@@ -146,10 +146,7 @@ def get_position_viewer(sound_name):
ret_list.append(
{
"confidence": round(location.confidence, 3),
- "position": Point(
- round(location.position.x, 3),
- round(location.position.y, 3)
- )
+ "position": location.position
}
)
diff --git a/locaudio/triangulation.py b/locaudio/triangulation.py
index 5150edf..7498846 100644
--- a/locaudio/triangulation.py
+++ b/locaudio/triangulation.py
@@ -39,6 +39,7 @@
MAX_RADIUS_INC = 10
MIN_RADIUS_INC = -10
RADIUS_STEP = 1
+EARTH_RADIUS = 1000 * 6371
def distance_from_sound(r_ref, l_ref, l_current):
@@ -63,10 +64,6 @@ def distance_from_sound(r_ref, l_ref, l_current):
return r_ref * math.pow(10, (l_ref - l_current) / float(20))
-def meters_to_lat_lng_dist(meters):
- return meters / float(111 * 1000)
-
-
def distance_from_detection_event(x, y, node_event):
"""
@@ -86,20 +83,24 @@ def distance_from_detection_event(x, y, node_event):
"""
- earth_radius = 6373 * 1000
- degrees_to_radians = math.pi / 180.0
+ lat1 = math.radians(x)
+ lon1 = math.radians(y)
+ lat2 = math.radians(node_event.x)
+ lon2 = math.radians(node_event.y)
- phi1 = (90.0 - x) * degrees_to_radians
- phi2 = (90.0 - node_event.x) * degrees_to_radians
+ dlon = lon2 - lon1
+ dlat = lat2 - lat1
- theta1 = y * degrees_to_radians
- theta2 = node_event.y * degrees_to_radians
+ a = (
+ (math.sin(dlat / 2)) ** 2 +
+ math.cos(lat1) * math.cos(lat2) * (math.sin(dlon / 2)) ** 2
+ )
- cos = (math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) +
- math.cos(phi1) * math.cos(phi2))
- arc = math.acos(cos)
+ c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
- return earth_radius * arc
+ distance = EARTH_RADIUS * c
+
+ return distance
def normal_distribution(x):
@@ -186,12 +187,8 @@ def position_evaluation(x, y, r_ref, l_ref, node_events):
[
normal_distribution(
(
- meters_to_lat_lng_dist(
- distance_from_detection_event(x, y, n)
- ) -
- meters_to_lat_lng_dist(
- distance_from_sound(r_ref, l_ref, n.spl)
- )
+ distance_from_detection_event(x, y, n) -
+ distance_from_sound(r_ref, l_ref, n.spl)
) / n.get_std()
) / n.get_std() for n in node_events
]
@@ -450,10 +447,13 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
ax = fig.add_subplot(111)
ax.set_xlabel("X Location")
ax.set_ylabel("Y Location")
- v_min = -10
- v_max = 10
- v_step = 0.1
- x = y = np.arange(v_min, v_max, v_step)
+ x_min = 56.3399
+ x_max = 56.3400
+ y_min = -2.80834
+ y_max = -2.80824
+ v_step = 0.000001
+ x = np.arange(x_min, x_max, v_step)
+ y = np.arange(y_min, y_max, v_step)
X, Y = np.meshgrid(x, y)
zs = np.array(
@@ -464,8 +464,6 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
)
Z = zs.reshape(X.shape)
- ax.set_xlim(v_min, v_max)
- ax.set_ylim(v_min, v_max)
ax.pcolormesh(X, Y, Z, cmap=cm.jet)
ax.scatter(
[p.position.x for p in res],
@@ -483,6 +481,9 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
s=300
)
+ ax.set_xlim(x_min, x_max)
+ ax.set_ylim(y_min, y_max)
+
plt.savefig(filename)
return plt
diff --git a/run.py b/run.py
index ed259d4..22910b5 100644
--- a/run.py
+++ b/run.py
@@ -1,13 +1,14 @@
import locaudio
import sys
-
+import socket
if __name__ == "__main__":
if len(sys.argv) == 3:
locaudio.config.run(sys.argv[1], sys.argv[2])
- elif len(sys.argv) == 0:
- locaudio.config.run("localhost", 8000)
+ elif len(sys.argv) == 1:
+ ip_addr = socket.gethostbyname(socket.getfqdn())
+ locaudio.config.run(ip_addr, 8000)
else:
raise Exception("Correct argument form not supplied")
diff --git a/tests/config.json b/tests/config.json
deleted file mode 100644
index e384904..0000000
--- a/tests/config.json
+++ /dev/null
@@ -1,7 +0,0 @@
-
-{
- "radius": 1,
- "sound_pressure_level": 100,
- "fingerprint": [1,2,3,4]
-}
-
diff --git a/tests/test_server.py b/tests/test_server.py
index 71c02f0..55b3097 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -11,9 +11,10 @@
import json
import locaudio.db as db
import locaudio.api as api
+import socket
-server_addr = "192.168.1.9"
+server_addr = socket.gethostbyname(socket.getfqdn())
server_port = 8000
test_sound_name = "Cock"
@@ -24,31 +25,31 @@
d_dicts = [
{
- "x": -9,
- "y": -1,
- "spl": 83,
+ "x": 56.3399723,
+ "y": -2.8082881,
+ "spl": 65,
"timestamp": time.time(),
"fingerprint": f_print
},
{
- "x": -2,
- "y": 1,
- "spl": 97,
- "timestamp": time.time() - 7,
+ "x": 56.3399723,
+ "y": -2.8082881,
+ "spl": 65,
+ "timestamp": time.time() - 1,
"fingerprint": f_print
},
{
- "x": 1,
- "y": 3,
- "spl": 86,
- "timestamp": time.time() - 10,
+ "x": 56.3399723,
+ "y": -2.8082881,
+ "spl": 65,
+ "timestamp": time.time(),
"fingerprint": f_print
},
{
- "x": 0,
- "y": -1,
- "spl": 100,
- "timestamp": time.time() - 5,
+ "x": 56.3399723,
+ "y": -2.8082881,
+ "spl": 65,
+ "timestamp": time.time(),
"fingerprint": f_print
}
]
@@ -77,5 +78,8 @@ def test_names(self):
if __name__ == "__main__":
print "\n=== Server Testing ===\n"
+ global server_addr
+ if len(sys.argv) == 2:
+ server_addr = sys.argv[1]
unittest.main()