Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3145f5e
Changes prior to demo
OustanDing Nov 5, 2019
97fc0e6
Remove cache and venv files
tawnyzhao Nov 18, 2019
d22a0c3
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
tawnyzhao Nov 18, 2019
88942bb
Delete .DS_Store
tawnyzhao Nov 18, 2019
07f30f8
Remove pycache
tawnyzhao Nov 18, 2019
8871e84
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
tawnyzhao Nov 18, 2019
b052cd8
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
OustanDing Nov 18, 2019
c9777b8
Cleaned up app.py and functions.py
OustanDing Nov 18, 2019
6b8ef17
Added skeleton code for module class
tawnyzhao Nov 21, 2019
3ff1a99
Updated app.py
OustanDing Nov 21, 2019
a11b7b6
Read noise file function
Jonathancui123 Nov 21, 2019
e6e9a8d
Added absolute location support
OustanDing Nov 21, 2019
e534b80
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
OustanDing Nov 21, 2019
0f4b219
Added list of times
OustanDing Nov 24, 2019
e22ae23
updated noise function
Jonathancui123 Nov 25, 2019
212bc04
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
Jonathancui123 Nov 25, 2019
abbca17
changed function name
Jonathancui123 Nov 25, 2019
e19e98c
NOISE REDUCE ON MODULE.PY :+1:
Jonathancui123 Nov 25, 2019
e93e778
Update module.py
Jonathancui123 Nov 25, 2019
fd6177d
Made changes to app.py
OustanDing Nov 25, 2019
e03423e
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
OustanDing Nov 25, 2019
568192e
Fixed some app.py, working on changes to implement module class
OustanDing Nov 26, 2019
aa7b2cc
Made modifications to app.py in accordance with module.py changes
OustanDing Nov 26, 2019
1933771
push
Jonathancui123 Nov 27, 2019
f905ffc
Add debug
OustanDing Nov 28, 2019
1ef02dc
commiy
OustanDing Nov 28, 2019
75f811d
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
OustanDing Nov 28, 2019
79bf16c
commit after tony fixed negative values
OustanDing Nov 28, 2019
565f7d0
commit
Jonathancui123 Nov 28, 2019
8c5b2a2
Merge branch 'oustan' of https://github.com/YashArora0606/SoftwareEng…
Jonathancui123 Nov 28, 2019
54d05a8
Reduce noise in processfiles()
Jonathancui123 Nov 28, 2019
362cd11
fixed grid
OustanDing Nov 28, 2019
8959571
Big changes
OustanDing Nov 28, 2019
010dc77
Made notes for tomorrow
OustanDing Nov 28, 2019
562bc02
Update server/app.py
YashArora0606 Nov 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file modified .DS_Store
Binary file not shown.
Binary file removed analysis/.DS_Store
Binary file not shown.
Binary file removed analysis/analysis.pyc
Binary file not shown.
Binary file removed analysis/plot.png
Binary file not shown.
Binary file removed analysis/sounds/WAV013.wav
Binary file not shown.
Binary file removed analysis/sounds/ambiance.wav
Binary file not shown.
Binary file removed analysis/sounds/gunshot2.wav
Binary file not shown.
Binary file removed analysis/you-know-what-im-talking.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions pi/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "venv\\Scripts\\python.exe"
}
Binary file modified server/.DS_Store
Binary file not shown.
Binary file modified server/__pycache__/analysis.cpython-37.pyc
Binary file not shown.
Binary file modified server/__pycache__/app.cpython-37.pyc
Binary file not shown.
27 changes: 0 additions & 27 deletions server/__pycache__/backup.py

This file was deleted.

Binary file modified server/__pycache__/functions.cpython-37.pyc
Binary file not shown.
Binary file added server/__pycache__/module.cpython-37.pyc
Binary file not shown.
Binary file removed server/__pycache__/triangulate.cpython-37.pyc
Binary file not shown.
59 changes: 43 additions & 16 deletions server/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import matplotlib.pyplot as plt
import noisereduce as nr

# PATH = os.cwd()
# OUTPUT_DIR = "/pi/output/"
Expand All @@ -19,18 +20,18 @@
frame_total = 1000
chunk_size = 1
num_sounds = 0
zoom = 30
zoom = 50

UPLOADS_PATH = os.path.join(os.getcwd(),"uploads")

def read_files(clear_after_read = False):
global channel1, channel2, channel3
file_list = os.listdir(UPLOADS_PATH)
for file_name in file_list:
print(file_list)
# print(file_list)
if re.match(r".*\.wav", file_name):
file_info = file_name.split("-")
print(file_info)
# print(file_info)
if (file_info[1] == '0'):
sample_rate, channel1 = read(os.path.join(UPLOADS_PATH, file_name))
if (clear_after_read):
Expand All @@ -44,6 +45,25 @@ def read_files(clear_after_read = False):
if (clear_after_read):
os.remove(os.path.join(UPLOADS_PATH, file_name))

NOISE_PATH = os.path.join(os.getcwd(), "noise")
def read_noise(clear_after_read = False):
global noisefile
for file_name in os.listdir(NOISE_PATH):
if re.match(r".*\.wav", file_name):
sample_rate, noisefile = read(os.path.join(NOISE_PATH, file_name))
if (clear_after_read):
os.remove(os.path.join(UPLOADS_PATH, file_name))

def process_noise():
global noisefile, frame_total
try:
noisefile = abs(noisefile[:,0]/2) + abs(noisefile[:,1]/2)
except:
noisefile = abs(noisefile[:])
noisefile = noisefile[::len(noisefile)//(frame_total-1)]



def process_files():
global channel1, channel2, channel3, frame_total
try:
Expand All @@ -68,9 +88,11 @@ def smooth(x, window_len = 15):
return y

#Smoothing function that is currently in use
def chonk_avg(arr, chunk_size):
def denoise_and_smooth(arr, chunk_sizem):
#Produces a new array of the average value in each chunk of chunk_size
#New array contains (len(arr)//chunk_size) chunks


chonks = []
newLen = frame_total//chunk_size
for i in range(newLen + 1):
Expand All @@ -88,12 +110,12 @@ def find_module_events(s1, s2, s3):
module_thresh = (find_event_thresh(s1) + find_event_thresh(s2) +find_event_thresh(s3))/3

e1 = find_mic_events(s1, module_thresh)
print(" e1 is:", e1)
# print(" e1 is:", e1)
e2 = find_mic_events(s2, module_thresh)
print(" e2 is:", e2)
# print(" e2 is:", e2)
e3 = find_mic_events(s3, module_thresh)

print("Merge of e1 and e2:", e_merge_two(e1, e2))
# print("Merge of e1 and e2:", e_merge_two(e1, e2))

#Final module list
e_module = e_merge_two(e_merge_two(e1, e2), e3)
Expand Down Expand Up @@ -295,7 +317,7 @@ def convertToVolumeList(event_list, c1, c2, c3):
#Create plot of original sound file
#g = drawPlot(channel1, 0)

#smoothChannel = chonk_avg(channel1, 20)
#smoothChannel = denoise_and_smooth(channel1, 20)
#threshold = find_event_thresh(smoothChannel)

#f = Plot of smoothed sound file
Expand All @@ -312,24 +334,29 @@ def convertToVolumeList(event_list, c1, c2, c3):

def main():
read_files()
read_noise()
process_files()

smooth1 = chonk_avg(channel1, zoom)
smooth2 = chonk_avg(channel2, zoom)
smooth3 = chonk_avg(channel3, zoom)
smooth1 = denoise_and_smooth(channel1, zoom)
smooth2 = denoise_and_smooth(channel2, zoom)
smooth3 = denoise_and_smooth(channel3, zoom)

drawPlot(noisefile, 1)


drawPlot(smooth1, 1)
plt.axhline(y=find_event_thresh(smooth1), color='r', linestyle='-')
plt.xticks(range(0, len(smooth1), 1))
# drawPlot(smooth1, 1)
# plt.axhline(y=find_event_thresh(smooth1), color='r', linestyle='-')
# plt.xticks(range(0, len(smooth1), 1))

drawPlot(smooth2, 2)
drawPlot(smooth3, 3)
# drawPlot(smooth2, 2)
# drawPlot(smooth3, 3)

# print(find_module_events(smooth1, smooth2, smooth3))
# volumes_list = convertToVolumeList(find_module_events(smooth1, smooth2, smooth3), smooth1, smooth2, smooth3)
# print(volumes_list)

plt.show()


find_module_events(smooth1 ,smooth2, smooth3)

Expand Down
116 changes: 88 additions & 28 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,123 @@
import os, requests, analysis as an
import os
import requests
import module
import re
from flask import *
from functions import *
import matplotlib.pyplot as plt

# Sound sample
###############################################################################
# OBJECTS
###############################################################################
# Sound sample (for relative position to one module)
class Sound:
def __init__(self, vol = 0, direc = 0, time = 0):
self.vol = vol
self.dir = direc
self.time = time

# Sound sources
class Source:
def __init__(self, vol = 0, x = 0, y = 0, time = 0):
self.vol = vol
self.x = x
self.y = y
self.time = time

# Data transfer to website
class Data:
def __init__(self, n = 0, avgvol = 0, time = 0):
self.n = n
self.avgvol = avgvol
self.time = time

# Constants
UPLOAD_FOLDER = 'uploads'
# Module Location (coordinates)
class Module_Location:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y

###############################################################################
# CONSTANTS
###############################################################################
UPLOAD_FOLDER = os.path.join(os.getcwd(), "uploads")
x = 3 # size of grid: width
y = 3 # size of grid: height
grid = []
module_locations = [] # list of Module_Location objects (contains locations of modules)
times = [] # list of times of files in folder
tdelta = 3.0 # refresh delay
FILE_NAME = ''
nSamples = 5
zoom = an.zoom
zoom = 20
modules = {}

# App initialization
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True

###############################################################################
# HELPERS
###############################################################################
# Run a function periodically
def refresh(f, delay):
t = Timer(delay, f)
t.start()

# Update sample data datetime.now().strftime('%I:%M:%S%p')
def update():
global grid, nSamples, zoom
an.read_files()
an.process_files()

smooth1 = an.chonk_avg(an.channel1, zoom)
smooth2 = an.chonk_avg(an.channel2, zoom)
smooth3 = an.chonk_avg(an.channel3, zoom)
drawPlot(smooth1, 1)
grid = an.convertToVolumeList(an.find_module_events(smooth1, smooth2, smooth3), smooth1, smooth2, smooth3)
global grid, nSamples, zoom, times, UPLOAD_FOLDER
# Initialize times
for file in os.listdir(UPLOAD_FOLDER):
if re.match(r".*\.wav", file):
currTime = file.split('-')[2]
if currTime not in times:
times.append(currTime)

for time in times:
modules[time] = module.get_modules(time) # list of Modules

grid = []
try:
mostRecent = modules[max(modules.keys())]
except:
mostRecent = []
for mod in mostRecent:
grid.append(mod.convertToVolumeList())

# grid = Module.convertToVolumeList(Module.find_module_events(smooth1, smooth2, smooth3), smooth1, smooth2, smooth3)
convert(grid)
nSamples = len(grid)

if len(grid) and grid[0]:
nSamples = len(grid[0])
else:
nSamples = 1



# module.read_files(times)
# module.process_files()

# nSamples = round(random() * 8 + 1)
# grid = []
# for i in range(nSamples):
# grid.append(gen_random())
# refresh(update, tdelta)

# Print info to console
def printGrid():
def print_grid():
global tdelta, x, y, grid
points = list(map(exact, grid))
points = list(map(relative_location, grid))
for data in points:
print('-------------------------------')
print('Volume: ' + str(data.vol) + ', Direction: ' + str(data.dir) + ', Time: ' + str(data.time))
print('-------------------------------')
# refresh(printGrid, tdelta)

# Put relevant data in Data object to send to front-end
def genData(points):
def generate_data(points):
global nSamples
average = round(sum([point.vol for point in points]) / nSamples, 2)
return Data(nSamples, average, points[0].time)

###############################################################################
# ROUTES
###############################################################################
# Upload
@app.route('/upload', methods = ['GET', 'POST'])
def upload():
Expand All @@ -83,14 +131,18 @@ def upload():
def index():
global grid, tdelta, nSamples
update()
# printGrid()
points = list(map(exact, grid))
print("Past update")
# print_grid()
############################################################################
# TODO: Only take the most recent recordings and put them in a Sound object, ignore all others
for elem in grid:
points = list(map(relative_location, elem))
for display in points:
display.vol = round(display.vol, 2)
display.dir = round(display.dir, 2)
print(display.dir)
address = gen_radar(points)
data = genData(points)
address = generate_radar(points)
# address2 = generate_map(points)
data = generate_data(points)
return render_template('index.html', data=data, address=address, tdelta=tdelta)

# Test POST Requests
Expand All @@ -103,6 +155,14 @@ def listen():
f.save(os.path.join('uploads', f.filename))
FILE_NAME = f.filename
print('File name: ' + FILE_NAME)
# print('IP Address:' + request.text)
return redirect('/')

@app.route('/test', methods = ['POST'])
def test():
if request.method == 'POST':
print('RECEIVED TEST')
print(request.data)
return redirect('/')

if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion server/audioCollection.py

This file was deleted.

12 changes: 6 additions & 6 deletions server/app2.py → server/backup_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def update():
an.read_files()
an.process_files()

smooth1 = an.chonk_avg(an.channel1, zoom)
smooth2 = an.chonk_avg(an.channel2, zoom)
smooth3 = an.chonk_avg(an.channel3, zoom)
smooth1 = an.denoise_and_smooth(an.channel1, zoom)
smooth2 = an.denoise_and_smooth(an.channel2, zoom)
smooth3 = an.denoise_and_smooth(an.channel3, zoom)
drawPlot(smooth1, 1)
grid = an.convertToVolumeList(an.find_module_events(smooth1, smooth2, smooth3), smooth1, smooth2, smooth3)
convert(grid)
Expand Down Expand Up @@ -88,10 +88,10 @@ def index():
for display in points:
display.vol = round(display.vol, 2)
display.dir = round(display.dir, 2)
print(display.dir)
# print(display.dir)
address = gen_radar(points)
data = genData(points)
return render_template('index.html', data=data, address='static/img/plot.png', tdelta=tdelta)
return render_template('index.html', data=data, address=address, tdelta=tdelta)

# Test POST Requests
@app.route('/listen', methods = ['POST'])
Expand All @@ -100,7 +100,7 @@ def listen():
if request.method == 'POST':
print('RECEIVED')
f = request.files['file']
f.save(os.path.join('uploads', f.filename))
f.save(os.path.join('uploads2', f.filename))
FILE_NAME = f.filename
print('File name: ' + FILE_NAME)
return redirect('/')
Expand Down
Loading