Compare commits

...

1 Commits

Author SHA1 Message Date
NateSchoolfield a94b699bbd First commit 2021-02-10 14:58:37 -08:00
6 changed files with 161 additions and 1 deletions

1
auth_key_miband4.txt Normal file
View File

@ -0,0 +1 @@
c04bc1eb2efaea8efc20882624b9a0f6

View File

@ -15,7 +15,7 @@ mac_filename = 'mac.txt'
maximize_graph = False maximize_graph = False
vibration_settings = { vibration_settings = {
'interval_minutes': 0.1, 'interval_minutes': 45,
'duration_seconds': 5, 'duration_seconds': 5,
'type': 'random' 'type': 'random'
} }

63
crymonitor.py Normal file
View File

@ -0,0 +1,63 @@
import pyaudio, time, threading
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.animation as animation
CHUNKSIZE = 1024 # fixed chunk size
# initialize portaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
for i in range(0, numdevices):
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name'))
stream = p.open(
format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=CHUNKSIZE,
input_device_index=18
)
plt.style.use('dark_background')
graph_figure = plt.figure()
graph_figure.canvas.set_window_title('blesleep')
graph_axes = graph_figure.add_subplot(1, 1, 1)
graph_data = {}
def graph_animation(i):
graph_axes.clear()
graph_axes.plot(numpydata)
ani = animation.FuncAnimation(graph_figure, graph_animation, interval=1000)
def get_audio_data():
global numpydata
while True:
data = stream.read(CHUNKSIZE)
numpydata = np.frombuffer(data, dtype=np.int16)
time.sleep(1)
threading.Thread(target=get_audio_data).start()
plt.show()
# close stream
stream.stop_stream()
stream.close()
p.terminate()

76
datafilter.py Normal file
View File

@ -0,0 +1,76 @@
import time, os, csv
from datetime import datetime
from matplotlib import pyplot as plt
datapath = '/home/daddy/Projects/miband/data/2021_02_07/'
window_min = 30
figure_height = 9
figure_width = 18
fullscreen = False
files = os.listdir(datapath)
wavs = []
csvs = []
for file in files:
if 'wav' in file:
wavs.append(file)
elif 'csv' in file and 'raw' in file:
csvs.append(file)
event_data_list = []
for wav in wavs:
event_dict = {
'name': wav,
'data': {
'mov_x': [],
'mov_y': [],
'bpm_x': [],
'bpm_y': []
}
}
wavtime = datetime.strptime(wav, '%Y_%m_%d__%H_%M_%S.wav')
wavestamp = wavtime.timestamp()
plotdata_mov_x = []
plotdata_mov_y = []
plotdata_bpm_x = []
plotdata_bpm_y = []
for mycsv in csvs:
with open((datapath + mycsv), newline='') as csvfile:
csvreader = csv.DictReader(csvfile, delimiter=',')
for row in csvreader:
if abs((float(wavestamp) - float(row['time']))) <= (window_min * 60):
if 'bpm' in row:
event_dict['data']['bpm_x'].append( int(row['bpm']) )
event_dict['data']['bpm_y'].append( datetime.fromtimestamp(float(row['time'])) )
elif 'movement' in row:
event_dict['data']['mov_x'].append( int(row['movement']) )
event_dict['data']['mov_y'].append( datetime.fromtimestamp(float(row['time'])) )
event_data_list.append(event_dict)
for event_data in event_data_list:
event_name = event_data['name'].rsplit('.', 1)[0]
output_png_filename = '{}{}'.format(event_name, ".png")
data = event_data['data']
plt.close("all")
fig, ax = plt.subplots()
ax2 = ax.twinx()
ax.plot(data['bpm_y'], data['bpm_x'], color="red")
ax2.plot(data['mov_y'], data['mov_x'], color="blue")
fig.set_figheight(figure_height)
fig.set_figwidth(figure_width)
fig.autofmt_xdate()
if fullscreen:
plt.get_current_fig_manager().full_screen_toggle()
plt.title(event_name)
if data['bpm_y']:
plt.savefig(datapath + output_png_filename)
plt.show()

1
mac_miband4.txt Normal file
View File

@ -0,0 +1 @@
EB:DD:13:97:9C:0D

19
test.py Normal file
View File

@ -0,0 +1,19 @@
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
figures=[manager.canvas.figure
for manager in plt._pylab_helpers.Gcf.get_all_fig_managers()]
print(figures)
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b-')
plt.show()