Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52a4dac990 | |||
| 9a3d9689fd |
@@ -1,11 +1,6 @@
|
||||
# BioProAPIServer
|
||||
|
||||
### Setup postgresql
|
||||
|
||||
##### Installation
|
||||
```
|
||||
sudo apt-get install postgresql libpq-dev postgresql-client postgresql-client-common
|
||||
```
|
||||
### Setup pi3 postgresql
|
||||
|
||||
##### Switch to the Postgres user to configure the database
|
||||
```
|
||||
@@ -19,18 +14,11 @@ createuser biopro -P --interactive
|
||||
|
||||
##### Postgres command (type psql first to connect postgres)
|
||||
```
|
||||
#Enter postgresql
|
||||
psql
|
||||
|
||||
#Find databases
|
||||
\l
|
||||
|
||||
#Find tables
|
||||
\dt
|
||||
|
||||
# Create new database and table if you need
|
||||
create database test
|
||||
test=> create table people (name text, company text)
|
||||
```
|
||||
|
||||
### Run apiServer on device
|
||||
@@ -51,11 +39,11 @@ change the code following as:
|
||||
change apiserver port to postgres port, 54321 --> 5432 (default)
|
||||
*/
|
||||
export const pgDB = {
|
||||
host: '127.0.0.1',
|
||||
port: 54321, // -----------------> 5432
|
||||
username: 'biopro',
|
||||
password: 'BioProControlBox',
|
||||
database: 'postgres'
|
||||
host: '127.0.0.1', // 服务器地址
|
||||
port: 54321, // 数据库端口号 -----------------> 5432
|
||||
username: 'biopro', // 数据库用户名
|
||||
password: 'BioProControlBox', // 数据库密码
|
||||
database: 'postgres' // 数据库名称
|
||||
}
|
||||
```
|
||||
|
||||
@@ -79,7 +67,7 @@ nohup node /home/pi/bioproapiserver/dist/app.js > /home/pi/.api_server.out &
|
||||
|
||||
##### Localhost test port binding (your device:54321 -> raspberrypi:5432)
|
||||
```
|
||||
ssh -NL 54321:localhost:5432 pi@your-pi-ip
|
||||
ssh -NL 54321:localhost:5432 pi@your-pi3-ip
|
||||
```
|
||||
|
||||
##### Run apiServer on your localhost (remember binding port first)
|
||||
@@ -91,4 +79,4 @@ npm run start
|
||||
```
|
||||
|
||||
##### References
|
||||
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
|
||||
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi
|
||||
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
import ast
|
||||
import time
|
||||
import psycopg2
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
@@ -8,6 +9,21 @@ from math import ceil, floor
|
||||
from json import loads, dumps
|
||||
from scipy.fft import fft, fftfreq, rfft, rfftfreq, irfft, ifft
|
||||
|
||||
import lttb
|
||||
from lttb.validators import has_two_columns, x_is_regular
|
||||
|
||||
def get_downsampled_signal(ori_signal, output_length):
|
||||
signal_length = len(ori_signal)
|
||||
signal = np.array([range(signal_length), ori_signal]).T
|
||||
assert signal.shape == (signal_length, 2)
|
||||
|
||||
# Downsampling
|
||||
downsampled_signal = lttb.downsample(signal, n_out=output_length, validators=[has_two_columns, x_is_regular])
|
||||
assert downsampled_signal.shape == (output_length, 2)
|
||||
downsampled_signal_index = downsampled_signal[:, 0]
|
||||
downsampled_signal_value = downsampled_signal[:, 1]
|
||||
return downsampled_signal_index, downsampled_signal_value
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
params = {}
|
||||
@@ -20,7 +36,7 @@ if __name__ == '__main__':
|
||||
cut_off_freq = int(params['cut_off_freq'])
|
||||
threshold = ast.literal_eval('[' + params['threshold'] + ']')
|
||||
waveform = ast.literal_eval('[' + params['waveform'] + ']')
|
||||
SAMPLE_RATE = int(params['sample_rate'])
|
||||
SAMPLE_RATE = int(float(params['sample_rate']))
|
||||
DURATION = ceil(float(params['time_duration']))
|
||||
DELTA_TIME = 1e6 / SAMPLE_RATE
|
||||
N = SAMPLE_RATE * DURATION
|
||||
@@ -39,30 +55,22 @@ if __name__ == '__main__':
|
||||
print(e)
|
||||
exit
|
||||
finally:
|
||||
time = np.array([], dtype=int)
|
||||
data = np.array([])
|
||||
timeArray = np.array([], dtype=int)
|
||||
dataArray = np.array([])
|
||||
|
||||
for sub_data in ret:
|
||||
for split_data in sub_data[0].split('"***"')[:-1]:
|
||||
value = np.array(split_data.split(' '))
|
||||
time = np.append(time, value[::2].astype(np.int))
|
||||
data = np.append(data, value[1::2].astype(np.int))
|
||||
|
||||
# print(len(time), len(data))
|
||||
|
||||
timeArray = np.append(timeArray, value[::2].astype(np.int32))
|
||||
dataArray = np.append(dataArray, value[1::2].astype(np.int32))
|
||||
xf = rfftfreq(N, 1 / SAMPLE_RATE)
|
||||
points_per_freq = len(xf) / (SAMPLE_RATE / 2)
|
||||
target_idx = int(points_per_freq * cut_off_freq)
|
||||
|
||||
# print(xf[target_idx])
|
||||
|
||||
yf = rfft(data)
|
||||
yf = rfft(dataArray)
|
||||
yf[:target_idx] = 0
|
||||
new_sig = np.round(irfft(yf, len(data)),3)
|
||||
|
||||
# print(time[-1])
|
||||
# print(len(datas))
|
||||
# print(len(yf),yf)
|
||||
new_sig = np.round(irfft(yf, len(dataArray)),3)
|
||||
|
||||
if threshold[0] == 'below':
|
||||
th = new_sig < threshold[1]
|
||||
@@ -77,23 +85,26 @@ if __name__ == '__main__':
|
||||
filter_array = []
|
||||
for idx, point in enumerate(thresholded_edge_indices):
|
||||
if idx > 0:
|
||||
if time[thresholded_edge_indices[idx]] - int(waveform[2]) >= time[thresholded_edge_indices[idx-1]]:
|
||||
if timeArray[thresholded_edge_indices[idx]] - int(waveform[2]) >= timeArray[thresholded_edge_indices[idx-1]]:
|
||||
filter_array.append(True)
|
||||
elif time[thresholded_edge_indices[idx]] - int(waveform[1]) >= time[thresholded_edge_indices[idx-1]]:
|
||||
elif timeArray[thresholded_edge_indices[idx]] - int(waveform[1]) >= timeArray[thresholded_edge_indices[idx-1]]:
|
||||
filter_array.append(True)
|
||||
else:
|
||||
filter_array.append(False)
|
||||
else:
|
||||
if time[thresholded_edge_indices[idx]] - int(waveform[1]) < 0:
|
||||
if timeArray[thresholded_edge_indices[idx]] - int(waveform[1]) < 0:
|
||||
filter_array.append(False)
|
||||
else:
|
||||
filter_array.append(True)
|
||||
|
||||
timemark_list = thresholded_edge_indices[filter_array]
|
||||
|
||||
OUTPUT_SIGNAL_SIZE = 2000
|
||||
downsampled_signal_index, downsampled_signal_value = get_downsampled_signal(new_sig, OUTPUT_SIGNAL_SIZE)
|
||||
if ret_data_type == 'all':
|
||||
print(' '.join(str(x) for x in time))
|
||||
print(' '.join(str(x) for x in new_sig))
|
||||
print(' '.join(str(x) for x in timeArray))
|
||||
print(' '.join(str(x) for x in downsampled_signal_index))
|
||||
print(' '.join(str(x) for x in downsampled_signal_value))
|
||||
print(' '.join(str(x) for x in timemark_list))
|
||||
elif ret_data_type == 'partial':
|
||||
return_sub_signal_lists = {}
|
||||
|
||||
@@ -62,8 +62,14 @@ class RecordingDataMeta {
|
||||
recordingDataRaw.clearDeleted(channel)
|
||||
}
|
||||
if (meta.mini_data[channel] != null) {
|
||||
for (const miniID in meta.mini_data[channel]) {
|
||||
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel][miniID], channel)
|
||||
if (meta.mini_data[channel]['10'] !== undefined) {
|
||||
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['10'], channel)
|
||||
}
|
||||
if (meta.mini_data[channel]['100'] !== undefined) {
|
||||
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['100'], channel)
|
||||
}
|
||||
if (meta.mini_data[channel]['1000'] !== undefined) {
|
||||
await recordingDataMini.updateByIDs({ deleted: true }, meta.mini_data[channel]['1000'], channel)
|
||||
}
|
||||
recordingDataMini.clearDeleted(channel)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ export default router
|
||||
|
||||
// device
|
||||
.post('/api/device/create', controllers.device.create)
|
||||
.post('/api/device/update/:id', controllers.device.update)
|
||||
.post('/api/device/update/all', controllers.device.update)
|
||||
.post('/api/device/update_by_id/:id', controllers.device.updateByID)
|
||||
.post('/api/device/update_by_mac/:mac', controllers.device.updateByMac)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# Elite: 53
|
||||
# Neulive: 101 or 95
|
||||
ssh -NL 54321:localhost:5432 pi@192.168.2.1
|
||||
Reference in New Issue
Block a user