Skip to content

Commit

Permalink
added a config.json file and integrated it with the program
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Feb 7, 2014
1 parent 48bb322 commit b2265ce
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 75 deletions.
3 changes: 3 additions & 0 deletions app/Locabean/src/com/locaudio/api/NotifyResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class NotifyResponse {

@SerializedName("confidence")
public float confidence;

@SerializedName("added")
public boolean added;

@Override
public String toString() {
Expand Down
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

{
"jvm_path": "/System/Library/Frameworks/JavaVM.framework/JavaVM",
"db_host": "localhost",
"db_port": 28015,
"max_node_events": 10,
"min_confidence": 0.3,
"debug_mode": true
}

29 changes: 26 additions & 3 deletions locaudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@
"""


import triangulation
import detectionserver
import fingerprint
def run(host, port, config_filename):
"""
Runs the server.
@param host The host for the server
@param port The port for the server
"""

import config
config.load_config_file(config_filename)

global triangulation, detectionserver, fingerprint

import triangulation
import detectionserver
import fingerprint

import db
import detectionserver
import pageserver

db.init()
config.app.run(host=host, port=int(port), debug=True)


34 changes: 17 additions & 17 deletions locaudio/config.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@

import json
import sys

from flask import Flask
import db

app = Flask(__name__)
app.config.from_object(__name__)

detection_events = dict()
new_data = dict()

# So the routes get initiated
import detectionserver
import pageserver


def run(host, port):
"""
Runs the server.
@param host The host for the server
@param port The port for the server
this = sys.modules[__name__]

"""
# setting default values
jvm_path = "/System/Library/Frameworks/JavaVM.framework/JavaVM"
db_host = "localhost"
db_port = 28015
max_node_events = 10
min_confidence = 0.3
debug_mode = True

db.init()
app.run(host=host, port=int(port), debug=True)

def load_config_file(filename):
global this
with open(filename) as f:
config_dict = json.loads(f.read())
for config_key, config_value in config_dict.items():
setattr(this, config_key, config_value)


7 changes: 4 additions & 3 deletions locaudio/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import rethinkdb as r
import fingerprint
import config


"""
Expand All @@ -22,14 +23,14 @@


# Connection Information
HOST = "localhost"
PORT = 28015
HOST = config.db_host
PORT = config.db_port
DB = "reference"

# Sample entry information
SAMPLE_PATH = "sounds/Cock.wav"
SAMPLE_R_REF = 1
SAMPLE_L_REF = 100
SAMPLE_L_REF = 65
SAMPLE_NAME = "Cock"


Expand Down
44 changes: 23 additions & 21 deletions locaudio/detectionserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from flask import request, jsonify, render_template
from point import Point
import time
import util
import config
import json
import triangulation as tri
Expand All @@ -22,8 +20,10 @@
import os


MAX_NODE_EVENTS = 10
DEBUG = True
MAX_NODE_EVENTS = config.max_node_events
MIN_CONFIDENCE = config.min_confidence

CREATE_PLOTS = False
IMG_DIR = "imgs/"


Expand Down Expand Up @@ -62,23 +62,25 @@ def post_notify():

sound_name, confidence = db.get_best_matching_print(req_print)

if not sound_name in config.detection_events.keys():
config.detection_events[sound_name] = list()
if confidence > MIN_CONFIDENCE:
if not sound_name in config.detection_events.keys():
config.detection_events[sound_name] = list()

config.new_data[sound_name] = True
config.new_data[sound_name] = True

if len(config.detection_events[sound_name]) + 1 >= MAX_NODE_EVENTS:
del config.detection_events[sound_name][0]
if len(config.detection_events[sound_name]) + 1 >= MAX_NODE_EVENTS:
del config.detection_events[sound_name][0]

config.detection_events[sound_name].append(
request_to_detection_event(request.form, confidence)
)
config.detection_events[sound_name].append(
request_to_detection_event(request.form, confidence)
)

return jsonify(
error=0,
message="No error",
name=sound_name,
confidence=confidence
confidence=confidence,
added=confidence > MIN_CONFIDENCE
)


Expand Down Expand Up @@ -131,15 +133,15 @@ def get_position_viewer(sound_name):
img_path = IMG_DIR + sound_name + ".png"
img_web_path = "/" + img_path

# if config.new_data[sound_name]:
# plot.plot_detection_events(
# location_list,
# radius, spl,
# config.detection_events[sound_name],
# img_path
# )
if config.new_data[sound_name] and CREATE_PLOTS:
plot.plot_detection_events(
location_list,
radius, spl,
config.detection_events[sound_name],
img_path
)

# config.new_data[sound_name] = False
config.new_data[sound_name] = False

ret_list = list()

Expand Down
22 changes: 3 additions & 19 deletions locaudio/fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import jpype
import math
import json
import config


jvm_path = "/System/Library/Frameworks/JavaVM.framework/JavaVM"
jvm_path = config.jvm_path


def surround_jvm(func):
Expand All @@ -21,16 +22,6 @@ def _inner(*args, **kwargs):
return _inner


def load_fingerprint_from_file(filename):
with open(filename) as f:
print_dict = json.loads(f.read())
return ReferencePrint(
print_dict["fingerprint"],
print_dict["radius"],
print_dict["sound_pressure_level"]
)


#@atexit.register
def destroy_env():
if jpype.isJVMStarted():
Expand All @@ -44,7 +35,7 @@ def get_similarity(f_1, f_2):
sim_obj = com_obj.getFingerprintsSimilarity()
sim = sim_obj.getSimilarity()
if math.isnan(sim):
return 0.5
return 0.0
else:
return sim

Expand All @@ -56,10 +47,3 @@ def get_fingerprint(wav_path):
return list(wv.getFingerprint())


class ReferencePrint(object):

def __init__(self, fingerprint, radius, spl):
self.fingerprint = fingerprint
self.radius = radius
self.spl = spl

3 changes: 0 additions & 3 deletions locaudio/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

STD_SCALE = 1.4
MIN_DIST = 0.0001
MAX_RADIUS_INC = 10
MIN_RADIUS_INC = -10
RADIUS_STEP = 1
EARTH_RADIUS = 1000 * 6371

# Special distance uncertainty threshold in meters
Expand Down
6 changes: 3 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

if __name__ == "__main__":
if len(sys.argv) == 3:
locaudio.config.run(sys.argv[1], sys.argv[2])
elif len(sys.argv) == 1:
locaudio.run(sys.argv[1], sys.argv[2], sys.argv[3])
elif len(sys.argv) == 2:
ip_addr = socket.gethostbyname(socket.getfqdn())
locaudio.config.run(ip_addr, 8000)
locaudio.run(ip_addr, 8000, sys.argv[1])
else:
raise Exception("Correct argument form not supplied")

7 changes: 2 additions & 5 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class ServerTest(unittest.TestCase):

def test_server_notify(self):
for d_dict in d_dicts:
loc.notify_event(d_dict)
ret_dict = loc.notify_event(d_dict)

print "\n=== Server Notify ===\n"
print "\n=== Server Notify === :: {0}\n".format(ret_dict)


def test_server_triangulation(self):
Expand All @@ -78,8 +78,5 @@ 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()

2 changes: 1 addition & 1 deletion tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TriangulationTest(unittest.TestCase):

def setUp(self):

self.show_plot = True
self.show_plot = False
self.d_events = [
tri.DetectionEvent(-9, -1, 0.9, 90, time.time()),
tri.DetectionEvent(-2, 1, 0.3, 97, time.time() - 7),
Expand Down

0 comments on commit b2265ce

Please sign in to comment.