Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fca174483 | |||
| 917380a961 | |||
| 7d2e8009b6 | |||
| c277d7c94c | |||
| d93633704e | |||
| 87bcb29242 | |||
| 442eb1eed5 | |||
| 0a0608aa09 | |||
| 423a56466a | |||
| eb79905024 | |||
| 853cf888de | |||
| 3ee4d5a118 | |||
| 37e13ca93f | |||
| 59ebcb946e | |||
| 4a6587530c | |||
| c264157a15 | |||
| be1500bbbc | |||
| 5d5bf0ee51 | |||
| cf83afc8f3 | |||
| c8d0248da1 | |||
| 830fde89a3 | |||
| fcc76c835c | |||
| 2937043f78 | |||
| 1f65ad0f11 | |||
| 18c61c0996 | |||
| 451d246952 | |||
| 15d6c2cda6 | |||
| 5ad6683b81 | |||
| a646844b9a | |||
| 363d8aac11 | |||
| a7bea5288c | |||
| 97993827b2 | |||
| 46b6918031 | |||
| df09a4c92b | |||
| f4ac57c8f8 | |||
| 64c6b20a8f | |||
| 8a65f20142 | |||
| 632d65c057 | |||
| e013b9dd63 | |||
| 5605bcbe68 | |||
| 6a85c88fb7 | |||
| bc687cc2de | |||
| 6bb37fd48d | |||
| 4cbc3873f7 | |||
| 64a6698611 | |||
| 70a4f448e9 | |||
| ddd4524407 | |||
| 92a2fc8a26 | |||
| af999c8b33 | |||
| 5a1577db80 | |||
| f62c99c73a | |||
| ac8c52b75b | |||
| e240ff24b2 | |||
| 9fa0fd5322 | |||
| 567855b7e5 | |||
| 8613369885 | |||
| 88e5f0c155 | |||
| d7a3a06039 | |||
| 6a3c35e594 | |||
| a9f030e95f | |||
| 71f84cb25b | |||
| 13996acf5a | |||
| dd3328b96c | |||
| 47fd4d26b0 | |||
| 685e7d2f15 | |||
| edc3859ba7 | |||
| 9848de900b | |||
| b09d39f18f | |||
| 7283498e26 | |||
| 00c508fd78 | |||
| f02be97497 | |||
| 6845d78716 | |||
| 1c8c26ff25 | |||
| d4f9a6f5f4 | |||
| 7ddc9d8220 | |||
| a9114cc05f | |||
| 9cde625d0c | |||
| 9fa91fcd63 | |||
| 27a140df3d | |||
| 20a2b74e9f | |||
| 11e90e1685 |
+1
-1
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"start": "gulp nodemon",
|
||||
"dev": "gulp",
|
||||
"build": "babel src -d dist",
|
||||
"build": "babel src -d dist --copy-files",
|
||||
"production": "node dist/app.js",
|
||||
"test": "jest",
|
||||
"link": "eslint .",
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ export const DB = {
|
||||
|
||||
export const pgDB = {
|
||||
host: '127.0.0.1', // 服务器地址
|
||||
port: 54321, // 数据库端口号
|
||||
port: 5432, // 数据库端口号
|
||||
username: 'biopro', // 数据库用户名
|
||||
password: 'BioProControlBox', // 数据库密码
|
||||
database: 'postgres' // 数据库名称
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import RecordingDataMeta from '../../models/file/recording_data_meta'
|
||||
import childProcess from 'child_process'
|
||||
import path from 'path'
|
||||
import { createReadStream } from 'fs'
|
||||
|
||||
const recordingDataMeta = new RecordingDataMeta()
|
||||
|
||||
export const spikeDetect = async (ctx, next) => {
|
||||
const request = ctx.request.body
|
||||
|
||||
const id = request.id
|
||||
const channel = request.channel
|
||||
const cutOffFreq = request.cut_off_freq
|
||||
const threshold = request.threshold
|
||||
const waveForm = request.waveForm
|
||||
const retDataType = request.ret_data_type
|
||||
// console.log(id, channel, cutOffFreq, threshold, waveForm)
|
||||
|
||||
const result = await recordingDataMeta.getByID(id)
|
||||
const channels = JSON.parse(result[0].channels)
|
||||
const sampleRate = 8e5 / result[0].parameter_set.ADC_CLOCK / channels.length
|
||||
const timeDuration = result[0].time_duration / 1e6
|
||||
// console.log(sampleRate, timeDuration)
|
||||
|
||||
const process = childProcess.spawnSync('python3', [
|
||||
path.join(__dirname, '/spikeDetect.py'),
|
||||
'meta_id=' + id,
|
||||
'channel=' + channel,
|
||||
'cut_off_freq=' + cutOffFreq,
|
||||
'threshold=' + threshold,
|
||||
'waveform=' + waveForm,
|
||||
'sample_rate=' + sampleRate,
|
||||
'time_duration=' + timeDuration,
|
||||
'ret_data_type=' + retDataType
|
||||
], { maxBuffer: 2 * 1024 * 1024 * 1024 })
|
||||
|
||||
// console.log('out', process.stdout.toString())
|
||||
console.log('err', process.stderr.toString())
|
||||
|
||||
ctx.body = process.stdout.toString()
|
||||
|
||||
// const process = child_process.execSync('python3 /Users/lubokai/Desktop/bioproapiserver/src/controllers/analysis/test.py 1089 0')
|
||||
// console.log(process)
|
||||
// process.stdout.on('data', (data) => {
|
||||
// _data += data.toString()
|
||||
// })
|
||||
|
||||
// process.stderr.on('data', (data) => {
|
||||
// console.error(data.toString())
|
||||
// })
|
||||
|
||||
// process.on('exit', (code) => {
|
||||
// console.log(_data)
|
||||
// console.log(`Child exited with code ${code}`)
|
||||
// })
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getCSV = async (ctx, next) => {
|
||||
const name = ctx.query.name
|
||||
ctx.type = 'stream'
|
||||
// ctx.attachment = name + '.csv'
|
||||
ctx.set('Content-disposition', `attachment; filename=${name}.csv`)
|
||||
ctx.body = createReadStream(path.resolve(__dirname, '../../../../data-analysis/csv_file', 'output.csv'))
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import sys
|
||||
import ast
|
||||
import psycopg2
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from math import ceil, floor
|
||||
from json import loads, dumps
|
||||
from scipy.fft import fft, fftfreq, rfft, rfftfreq, irfft, ifft
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
params = {}
|
||||
for input in sys.argv[1:]: #Now we're going to iterate over argv[1:] (argv[0] is the program name)
|
||||
param = input.split("=") #Get what's left of the '='
|
||||
params[param[0]] = param[1]
|
||||
|
||||
meta_id = params['meta_id']
|
||||
channel = params['channel']
|
||||
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'])
|
||||
DURATION = ceil(float(params['time_duration']))
|
||||
DELTA_TIME = 1e6 / SAMPLE_RATE
|
||||
N = SAMPLE_RATE * DURATION
|
||||
ret_data_type = params['ret_data_type']
|
||||
|
||||
# print(meta_id, channel, cut_off_freq, threshold, waveForm, SAMPLE_RATE, DURATION, N)
|
||||
|
||||
conn = psycopg2.connect(database="postgres", user="biopro", password="BioProControlBox", host="127.0.0.1", port="5432")
|
||||
cur = conn.cursor()
|
||||
sql_str = 'SELECT data FROM "public"."' + str(channel) + '_recording_data_raws" WHERE parent = ' + meta_id + 'ORDER BY id ASC'
|
||||
cur.execute(sql_str)
|
||||
ret = None
|
||||
try:
|
||||
ret = cur.fetchall()
|
||||
except BaseException as e:
|
||||
print(e)
|
||||
exit
|
||||
finally:
|
||||
time = np.array([], dtype=int)
|
||||
data = 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))
|
||||
|
||||
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[:target_idx] = 0
|
||||
new_sig = np.round(irfft(yf, len(data)),3)
|
||||
|
||||
# print(time[-1])
|
||||
# print(len(datas))
|
||||
# print(len(yf),yf)
|
||||
|
||||
if threshold[0] == 'below':
|
||||
th = new_sig < threshold[1]
|
||||
elif threshold[0] == 'over':
|
||||
th = new_sig > threshold[1]
|
||||
elif threshold[0] == 'auto':
|
||||
th = new_sig
|
||||
|
||||
threshold_edges = np.convolve([1, -1], th, mode='same')
|
||||
thresholded_edge_indices = np.where(threshold_edges==1)[0]
|
||||
|
||||
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]]:
|
||||
filter_array.append(True)
|
||||
elif time[thresholded_edge_indices[idx]] - int(waveform[1]) >= time[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:
|
||||
filter_array.append(False)
|
||||
else:
|
||||
filter_array.append(True)
|
||||
|
||||
timemark_list = thresholded_edge_indices[filter_array]
|
||||
|
||||
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 timemark_list))
|
||||
elif ret_data_type == 'partial':
|
||||
return_sub_signal_lists = {}
|
||||
for timemark in timemark_list:
|
||||
start_index = timemark - floor(int(waveform[1] / DELTA_TIME))
|
||||
end_index = timemark + ceil(int(waveform[2] / DELTA_TIME))
|
||||
|
||||
subSignal = new_sig[start_index: end_index + 2]
|
||||
return_sub_signal_lists[str(timemark)] = ' '.join(str(x) for x in subSignal)
|
||||
print(dumps(return_sub_signal_lists))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
exit
|
||||
@@ -0,0 +1,39 @@
|
||||
import ConfigurationModal from '../../models/configuration/configuration'
|
||||
|
||||
const configuration = new ConfigurationModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await configuration.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await configuration.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const configurationType = ctx.query.type
|
||||
const id = ctx.query.id
|
||||
const library = ctx.query.library
|
||||
const query = { id: id, library: library }
|
||||
const result = await configuration.get(configurationType, query)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await configuration.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import TaskModal from '../../models/controller/task'
|
||||
|
||||
const task = new TaskModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await task.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await task.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const id = ctx.params.id
|
||||
const result = await task.getByID(id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await task.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -19,8 +19,36 @@ export const update = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const id = ctx.query.id
|
||||
const name = ctx.query.name
|
||||
const type = ctx.query.type
|
||||
const controllerId = ctx.query.controllerId
|
||||
|
||||
// folder
|
||||
const parent = ctx.query.parent
|
||||
const limit = ctx.query.limit
|
||||
const offset = ctx.query.offset
|
||||
const order = ctx.query.order
|
||||
const attrs = ctx.query.attrs
|
||||
|
||||
const query = {}
|
||||
let result = ''
|
||||
if (id) query.id = id
|
||||
if (name) query.name = name
|
||||
if (type) query.type = type
|
||||
if (controllerId) query.controllerId = controllerId
|
||||
if (id || name) result = await collection.getByQueryWithAttrs(query, attrs)
|
||||
if (type === 'folder') result = await collection.getByParentWithOffsetLimitOrder(type, parent, limit, offset, order)
|
||||
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await collection.clearDeleted()
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await collection.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
@@ -36,7 +64,8 @@ export const getByID = async (ctx, next) => {
|
||||
|
||||
export const getByName = async (ctx, next) => {
|
||||
const name = ctx.params.name
|
||||
const result = await collection.getByName(name)
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await collection.getByName(name, controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
@@ -62,7 +91,8 @@ export const getByParentName = async (ctx, next) => {
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await collection.getAll()
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await collection.getAll(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
import psycopg2
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def log(df, channel):
|
||||
# TODO: not sure need use 32 or 64?
|
||||
df[f'{channel}_log'] = np.log10(np.absolute(df[channel].astype(np.int32)))
|
||||
return df
|
||||
def integral(df, x_channel, y_channel, pre_last_x, pre_last_y, integral_result):
|
||||
offset = df[x_channel]
|
||||
offset = offset.shift(periods=1)
|
||||
offset[0] = pre_last_x
|
||||
x_diff = df[x_channel].astype(np.int32) - offset.astype(np.int32)
|
||||
# print('x_diff\n', x_diff)
|
||||
offset = df[y_channel]
|
||||
offset = offset.shift(periods=1)
|
||||
offset[0] = pre_last_y
|
||||
y_avg = (offset.astype(np.int32) + df[y_channel].astype(np.int32)) / 2
|
||||
# print('y_avg:', y_avg)
|
||||
# print('y_avg: ', y_avg)
|
||||
local_integral = x_diff * y_avg
|
||||
local_integral[0] += integral_result
|
||||
# TODO: if user don't need, then can remove it
|
||||
df[f'{x_channel}_{y_channel}_integral_delta'] = local_integral
|
||||
df[f'{x_channel}_{y_channel}_integral'] = local_integral.cumsum()
|
||||
# print(df)
|
||||
pre_last_x = df[x_channel].iat[-1]
|
||||
pre_last_y = df[y_channel].iat[-1]
|
||||
integral_result = df[f'{x_channel}_{y_channel}_integral'].iat[-1]
|
||||
# print('next run info: ', pre_last_x, pre_last_y, integral_result)
|
||||
return df, pre_last_x, pre_last_y, integral_result
|
||||
def differential(df, x_channel, y_channel, pre_last_x, pre_last_y):
|
||||
offset = df[x_channel]
|
||||
offset = offset.shift(periods=1)
|
||||
offset[0] = pre_last_x
|
||||
x_diff = df[x_channel].astype(np.int32) - offset.astype(np.int32)
|
||||
offset = df[y_channel]
|
||||
offset = offset.shift(periods=1)
|
||||
offset[0] = pre_last_y
|
||||
y_diff = df[y_channel].astype(np.int32) - offset.astype(np.int32)
|
||||
local_diff = y_diff / x_diff
|
||||
print(local_diff)
|
||||
# TODO: if user don't need, then can remove it
|
||||
df[f'{x_channel}_{y_channel}_diff'] = local_diff
|
||||
pre_last_x = df[x_channel].iat[-1]
|
||||
pre_last_y = df[y_channel].iat[-1]
|
||||
return df, pre_last_x, pre_last_y
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# TODO: function parameters: id, mode, x_channel, y_channel
|
||||
conn = psycopg2.connect(database="postgres", user="biopro", password="BioProControlBox", host="127.0.0.1", port="5432")
|
||||
cur = conn.cursor()
|
||||
id = 1262
|
||||
# id = 407
|
||||
# id = 1073
|
||||
# id = 968
|
||||
mode = 'differential'
|
||||
# mode = 'integral'
|
||||
# mode = 'log'
|
||||
sql_str = f'select "raw_data" from "recording_data_metas" WHERE id = {id}' # recording_data_metas: meta info to get the raw_data table
|
||||
# sql_str = 'select "raw_data" from "recording_data_metas" WHERE id = 407' # recording_data_metas: meta info to get the raw_data table
|
||||
# sql_str = 'select * from "0_recording_data_raws" WHERE id = 33384'
|
||||
cur.execute(sql_str)
|
||||
raw_data_list = None
|
||||
# x_
|
||||
try:
|
||||
raw_data_list = cur.fetchall()[0][0]
|
||||
# print(ret[0][0]['0'])
|
||||
channels = list(raw_data_list.keys())
|
||||
df = pd.DataFrame()
|
||||
df_time = []
|
||||
pre_last_x = 0
|
||||
pre_last_y = 0
|
||||
integral_result = 0
|
||||
# print('len(raw_data_list[channels[0]]): ', len(raw_data_list[channels[0]]))
|
||||
for raw_data_pages in range(len(raw_data_list[channels[0]])):
|
||||
for channel in channels:
|
||||
sql_str = f'select "data" from "{channel}_recording_data_raws" WHERE id = {raw_data_list[channel][raw_data_pages]}'
|
||||
cur.execute(sql_str)
|
||||
data_value = cur.fetchall()[0][0].replace('"***"', ' ')
|
||||
data_value = data_value.split(' ')[:-1]
|
||||
if df.empty:
|
||||
df_time = data_value[::2]
|
||||
df[channel] = data_value
|
||||
df = df.iloc[lambda x: x.index % 2 == 1].reset_index(drop=True)
|
||||
df.insert(0, 'time', df_time)
|
||||
if mode == 'log':
|
||||
x_channel = '1'
|
||||
df = log(df, x_channel)
|
||||
elif mode == 'integral':
|
||||
# TODO: x_channel and y_channel will need to be set as parameters
|
||||
x_channel = 'time'
|
||||
y_channel = '0'
|
||||
df, pre_last_x, pre_last_y, integral_result = integral(df, x_channel, y_channel, pre_last_x, pre_last_y, integral_result)
|
||||
elif mode == 'differential':
|
||||
x_channel = '1'
|
||||
y_channel = '0'
|
||||
df, pre_last_x, pre_last_y = differential(df, x_channel, y_channel, pre_last_x, pre_last_y)
|
||||
# print(df)
|
||||
df.to_csv(f"csv_test/{id}.csv", mode='a', index=False, header=False)
|
||||
df = pd.DataFrame()
|
||||
except BaseException as e:
|
||||
print(e)
|
||||
exit
|
||||
@@ -6,6 +6,7 @@ const recordingDataMeta = new RecordingDataMeta()
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log(auth.CheckAuth(ctx))
|
||||
// console.log(data)
|
||||
// console.log(ctx.request.header.authorization)
|
||||
const result = await recordingDataMeta.create(data)
|
||||
// console.log(result)
|
||||
@@ -30,6 +31,49 @@ export const clearDeleted = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const findWithIdRange = async (ctx, next) => {
|
||||
const id = JSON.parse(ctx.query.id)
|
||||
const range = JSON.parse(ctx.query.range)
|
||||
|
||||
const result = await recordingDataMeta.findWithIdRange1(id, range)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const id = ctx.query.id
|
||||
const name = ctx.query.name
|
||||
const uuid = ctx.query.uuid
|
||||
const type = ctx.query.type
|
||||
const time = ctx.query.time
|
||||
// folder
|
||||
const parent = ctx.query.parent
|
||||
const limit = ctx.query.limit
|
||||
const offset = ctx.query.offset
|
||||
const order = ctx.query.order
|
||||
const attrs = ctx.query.attrs
|
||||
const group = ctx.query.group
|
||||
|
||||
// project
|
||||
const project = ctx.query.project
|
||||
|
||||
const query = {}
|
||||
let result = ''
|
||||
if (id) query.id = id
|
||||
if (name) query.name = name
|
||||
if (uuid) query.uuid = uuid
|
||||
if (time) query.time = time
|
||||
if ((id || name || uuid || time) || type === undefined) result = await recordingDataMeta.getByQueryWithAttrs(query, limit, offset, order, attrs, group)
|
||||
|
||||
if (type === 'folder' && parent) result = await recordingDataMeta.getByFolderWithParentLimitOffsetOrderAttrs(type, parent, limit, offset, order, attrs)
|
||||
if (type === 'project' && project) result = await recordingDataMeta.getByProject(project)
|
||||
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataMeta.getByID(id)
|
||||
@@ -47,6 +91,50 @@ export const getByParent = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByParent = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
const attr = ctx.params.attr
|
||||
const result = await recordingDataMeta.getByAttrParent(type, parent, attr)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getCountByParent = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
const result = await recordingDataMeta.getCountByParent(type, parent)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByParentWithLimit = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
const limit = ctx.params.limit
|
||||
const offset = ctx.params.offset
|
||||
const order = ctx.params.order
|
||||
const result = await recordingDataMeta.getByParentWithLimit(type, parent, limit, offset, order)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttrsParentWithLimit = async (ctx, next) => {
|
||||
const type = ctx.params.type
|
||||
const parent = ctx.params.parent
|
||||
const limit = ctx.params.limit
|
||||
const offset = ctx.params.offset
|
||||
const order = ctx.params.order
|
||||
const attr = ctx.params.attr
|
||||
const result = await recordingDataMeta.getByAttrsParentWithLimit(type, parent, limit, offset, order, attr)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByUUID = async (ctx, next) => {
|
||||
const uuid = ctx.params.uuid
|
||||
const result = await recordingDataMeta.getByUUID(uuid)
|
||||
|
||||
@@ -25,6 +25,16 @@ export const update = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataMini.updateByIDs(data, id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// export const get = async (ctx, next) => {
|
||||
// const index = ctx.params.channel
|
||||
// const id = ctx.params.id
|
||||
@@ -51,6 +61,24 @@ export const getByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getExistOrNotByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataMini.getExistOrNotByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataMini.getByIDs(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getMeanDataByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
|
||||
@@ -25,6 +25,26 @@ export const update = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateSdData = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataRaw.updateSdData(data, id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataRaw.updateByIDs(data, id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const result = await recordingDataRaw.clearDeleted(index)
|
||||
@@ -42,6 +62,15 @@ export const getByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await recordingDataRaw.getByIDs(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getDataByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
@@ -70,6 +99,16 @@ export const getAttrByID = async (ctx, next) => {
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByIDs = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const attr = ctx.params.attr
|
||||
const result = await recordingDataRaw.getByAttrIDs(id, attr, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAttrByParent = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const parent = ctx.params.parent
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
time 0 1 2 3 time_0_integral
|
||||
0 0 -73922 -836265 -848970 0 0.000000e+00
|
||||
1 10500 -84368 -834380 -848548 0 -8.310225e+08
|
||||
2 21000 -84389 -834380 -848126 0 -1.716997e+09
|
||||
3 31500 -84332 -835637 -847704 0 -2.602782e+09
|
||||
4 42500 -84166 -835637 -847283 0 -3.529521e+09
|
||||
... ... ... ... ... .. ...
|
||||
1462 15390500 -45761 -449806 -466674 0 -9.716838e+11
|
||||
1463 15401000 -45833 -449806 -466445 0 -9.721646e+11
|
||||
1464 15411500 -45790 -451063 -466216 0 -9.726457e+11
|
||||
1465 15422500 -45638 -449806 -465988 0 -9.731485e+11
|
||||
1466 15432500 -45674 -449806 -465759 0 -9.736051e+11
|
||||
|
||||
[1467 rows x 6 columns]
|
||||
next run info: 15432500 -45674 -973605066500.0
|
||||
time 0 1 2 3 time_0_integral
|
||||
0 15443000 -45689 -448549 -465531 0 -9.740847e+11
|
||||
1 15453500 -45689 -448549 -465531 0 -9.745645e+11
|
||||
2 15464000 -45631 -449178 -465303 0 -9.750439e+11
|
||||
3 15474500 -45581 -447921 -465075 0 -9.755227e+11
|
||||
4 15485500 -45646 -447921 -464847 0 -9.760245e+11
|
||||
... ... ... ... ... .. ...
|
||||
1443 30720000 -24971 -248122 -259749 0 -1.497382e+12
|
||||
1444 30730500 -24920 -247950 -259624 0 -1.497644e+12
|
||||
1445 30741000 -24920 -248381 -259624 0 -1.497905e+12
|
||||
1446 30751500 -24791 -248036 -259500 0 -1.498166e+12
|
||||
1447 30762000 -24856 -247346 -259376 0 -1.498427e+12
|
||||
|
||||
[1448 rows x 6 columns]
|
||||
next run info: 30762000 -24856 -1498426872750.0
|
||||
time 0 1 2 3 time_0_integral
|
||||
0 30772500 -24913 -247669 -259251 0 -1.498688e+12
|
||||
1 30783000 -24848 -247669 -259127 0 -1.498949e+12
|
||||
2 30794000 -24805 -247669 -259003 0 -1.499222e+12
|
||||
3 30804000 -24805 -247454 -259003 0 -1.499471e+12
|
||||
4 30814500 -24870 -247238 -258879 0 -1.499731e+12
|
||||
... ... ... ... ... .. ...
|
||||
1456 46091500 -13496 -134943 -147002 0 -1.783935e+12
|
||||
1457 46102000 -13510 -134921 -146934 0 -1.784077e+12
|
||||
1458 46112500 -13510 -134123 -146934 0 -1.784219e+12
|
||||
1459 46123000 -13597 -134339 -146866 0 -1.784361e+12
|
||||
1460 46134000 -13525 -134598 -146799 0 -1.784510e+12
|
||||
|
||||
[1461 rows x 6 columns]
|
||||
next run info: 46134000 -13525 -1784510350500.0
|
||||
time 0 1 2 3 time_0_integral
|
||||
0 46144500 -13366 -134210 -146732 0 -1.784652e+12
|
||||
1 46154500 -13460 -134210 -146665 0 -1.784786e+12
|
||||
2 46165500 -13503 -134016 -146597 0 -1.784934e+12
|
||||
3 46176000 -13503 -134102 -146597 0 -1.785076e+12
|
||||
4 46186500 -13431 -134167 -146530 0 -1.785217e+12
|
||||
.. ... ... ... ... .. ...
|
||||
583 52277500 -10487 -105193 -117883 0 -1.858083e+12
|
||||
584 52288000 -10573 -105042 -117830 0 -1.858194e+12
|
||||
585 52298500 -10595 -105106 -117778 0 -1.858305e+12
|
||||
586 52309000 -10494 -105085 -117725 0 -1.858415e+12
|
||||
587 52319500 -10523 -105085 -117672 0 -1.858526e+12
|
||||
|
||||
[588 rows x 6 columns]
|
||||
next run info: 52319500 -10523 -1858525771000.0
|
||||
@@ -1,17 +1,37 @@
|
||||
import upload from './upload'
|
||||
import * as api from './api'
|
||||
import * as auth from './auth'
|
||||
import * as controller from './product/controller'
|
||||
import * as device from './product/device'
|
||||
import * as collection from './file/collection'
|
||||
import * as task from './controller/task'
|
||||
import * as recordingDataMeta from './file/recording_data_meta'
|
||||
import * as recordingDataRaw from './file/recording_data_raw'
|
||||
import * as recordingDataMini from './file/recording_data_mini'
|
||||
import * as analysis from './analysis'
|
||||
import * as project from './project/project'
|
||||
import * as projectReport from './project/project_report'
|
||||
import * as projectMeta from './project/project_meta'
|
||||
import * as chart from './configuration/chart'
|
||||
import * as subject from './subject/subject'
|
||||
import * as subjectData from './subject/subject_data'
|
||||
|
||||
export default {
|
||||
upload,
|
||||
api,
|
||||
auth,
|
||||
controller,
|
||||
device,
|
||||
collection,
|
||||
task,
|
||||
recordingDataMeta,
|
||||
recordingDataRaw,
|
||||
recordingDataMini
|
||||
recordingDataMini,
|
||||
analysis,
|
||||
project,
|
||||
projectReport,
|
||||
projectMeta,
|
||||
chart,
|
||||
subject,
|
||||
subjectData
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import ControllerModal from '../../models/product/controller'
|
||||
|
||||
const controller = new ControllerModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await controller.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await controller.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await controller.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await controller.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await controller.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByMac = async (ctx, next) => {
|
||||
const mac = ctx.params.mac
|
||||
const result = await controller.getByMac(mac)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await controller.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await controller.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// export const createTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test',
|
||||
// parent: -1,
|
||||
// size: 0
|
||||
// }
|
||||
// const result = await controller.create(data)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
|
||||
// export const updateTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test121',
|
||||
// parent: -1232,
|
||||
// size: 1243
|
||||
// }
|
||||
// const id = 2
|
||||
// const result = await controller.update(data, id)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
@@ -0,0 +1,103 @@
|
||||
import DeviceModal from '../../models/product/device'
|
||||
|
||||
const device = new DeviceModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await device.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await device.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await device.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByMac = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const mac = ctx.params.mac
|
||||
const result = await device.updateByMac(data, mac)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await device.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await device.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByMac = async (ctx, next) => {
|
||||
const mac = ctx.params.mac
|
||||
const result = await device.getByMac(mac)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await device.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await device.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
// export const createTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test',
|
||||
// parent: -1,
|
||||
// size: 0
|
||||
// }
|
||||
// const result = await device.create(data)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
|
||||
// export const updateTest = async (ctx, next) => {
|
||||
// const data = {
|
||||
// name: 'test121',
|
||||
// parent: -1232,
|
||||
// size: 1243
|
||||
// }
|
||||
// const id = 2
|
||||
// const result = await device.update(data, id)
|
||||
// ctx.body = result
|
||||
|
||||
// next()
|
||||
// }
|
||||
@@ -0,0 +1,62 @@
|
||||
import ProjectModal from '../../models/project/project'
|
||||
|
||||
const project = new ProjectModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await project.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await project.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await project.updateByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await project.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await project.getByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await project.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await project.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import ProjectMeta from '../../models/project/project_meta'
|
||||
|
||||
const projectMeta = new ProjectMeta()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await projectMeta.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await projectMeta.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await projectMeta.updateByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const id = ctx.query.id
|
||||
const name = ctx.query.name
|
||||
const uuid = ctx.query.uuid
|
||||
|
||||
const attrs = ctx.query.attrs
|
||||
const order = ctx.query.order
|
||||
|
||||
const query = {}
|
||||
let result = ''
|
||||
if (id) query.id = id
|
||||
if (name) query.name = name
|
||||
if (uuid) query.uuid = uuid
|
||||
result = await projectMeta.getByQueryWithAttrs(query, attrs, order)
|
||||
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await projectMeta.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await projectMeta.getByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await projectMeta.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await projectMeta.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import ProjectReport from '../../models/project/project_report'
|
||||
|
||||
const projectReport = new ProjectReport()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await projectReport.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await projectReport.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await projectReport.updateByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const id = ctx.query.id
|
||||
const name = ctx.query.name
|
||||
const uuid = ctx.query.uuid
|
||||
|
||||
const attrs = ctx.query.attrs
|
||||
const order = ctx.query.order
|
||||
|
||||
const query = {}
|
||||
let result = ''
|
||||
if (id) query.id = id
|
||||
if (name) query.name = name
|
||||
if (uuid) query.uuid = uuid
|
||||
result = await projectReport.getByQueryWithAttrs(query, attrs, order)
|
||||
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await projectReport.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByID = async (ctx, next) => {
|
||||
const index = ctx.params.channel
|
||||
const id = ctx.params.id
|
||||
const result = await projectReport.getByID(id, index)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await projectReport.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await projectReport.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import SubjectModel from '../../models/subject/subject'
|
||||
|
||||
const subject = new SubjectModel()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await subject.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await subject.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const configurationType = ctx.query.type
|
||||
const id = ctx.query.id
|
||||
const library = ctx.query.library
|
||||
const query = { id: id, library: library }
|
||||
const result = await subject.get(configurationType, query)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await subject.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import SubjectDataModel from '../../models/subject/subject_data'
|
||||
|
||||
const subjectData = new SubjectDataModel()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await subjectData.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await subjectData.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const subjectId = ctx.query.subject_id
|
||||
const meta = ctx.query.meta
|
||||
console.log('subject get', subjectId, meta)
|
||||
const query = {}
|
||||
if (subjectId) query.subject_id = subjectId
|
||||
if (meta) query.meta = meta
|
||||
const result = await subjectData.get(query)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await subjectData.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
+15
-6
@@ -23,20 +23,29 @@ db.Sequelize = Sequelize
|
||||
db.sequelize = sequelize
|
||||
|
||||
db.tutorials = require('./schema/tutirial.model')(sequelize, Sequelize)
|
||||
db.controllers = require('./schema/controller.model')(sequelize, Sequelize)
|
||||
db.tasks = require('./schema/task.model')(sequelize, Sequelize)
|
||||
db.devices = require('./schema/device.model')(sequelize, Sequelize)
|
||||
db.collections = require('./schema/collection.model')(sequelize, Sequelize)
|
||||
db.projects = require('./schema/project.model')(sequelize, Sequelize)
|
||||
db.project_reports = require('./schema/project_report.model')(sequelize, Sequelize)
|
||||
db.project_metas = require('./schema/project_meta.model')(sequelize, Sequelize)
|
||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||
db.charts = require('./schema/configuration/chart.model')(sequelize, Sequelize)
|
||||
db.subjects = require('./schema/subject/subject.model')(sequelize, Sequelize)
|
||||
db.subject_datas = require('./schema/subject/subject_data.model')(sequelize, Sequelize)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
for (let i = 0; i < 32; i++) {
|
||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
for (let i = 256; i < 288; i++) {
|
||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
for (let i = 256; i < 288; i++) {
|
||||
db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
// for (let i = 256; i < 288; i++) {
|
||||
// db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
// }
|
||||
// for (let i = 256; i < 288; i++) {
|
||||
// db[i + '_recording_data_minis'] = require('./schema/recording_data_mini.model')(sequelize, Sequelize, i)
|
||||
// }
|
||||
|
||||
db.sequelize.sync()
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ module.exports = (sequelize, Sequelize) => {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
controller_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Configuration = sequelize.define('configuration', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
library: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
layout: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
chart: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
parameter: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
locked: {
|
||||
type: Sequelize.BOOLEAN
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Configuration
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Chart = sequelize.define('chart', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
library: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
num: {
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
locked: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Chart
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Controller = sequelize.define('controller', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
spec: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mac_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
ip_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
wifi_name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
wifi_password: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_id: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
api_mqtt_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
root: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
// group/user: {
|
||||
// admin: [id...],
|
||||
// normal: [id...],
|
||||
// guest: [id...]
|
||||
// }
|
||||
group_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
device: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
device_scanned: {
|
||||
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||
defaultValue: []
|
||||
},
|
||||
device_connected: {
|
||||
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||
defaultValue: []
|
||||
},
|
||||
// project/task: {
|
||||
// running: [id...],
|
||||
// library: [id...]
|
||||
// }
|
||||
project: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
// task: {
|
||||
// type: Sequelize.JSONB,
|
||||
// defaultValue: {
|
||||
// running: [],
|
||||
// library: []
|
||||
// }
|
||||
// },
|
||||
software_version: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Controller
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Device = sequelize.define('device', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
mac_address: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
serial_number: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
library: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
library_version: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
device_version: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
battery: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
temperature: {
|
||||
type: Sequelize.DOUBLE,
|
||||
defaultValue: 0
|
||||
},
|
||||
auto_connect: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
connect_priority: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
connect_time: {
|
||||
type: Sequelize.BIGINT,
|
||||
defaultValue: 0
|
||||
},
|
||||
connect_status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: 'idle'
|
||||
},
|
||||
connect_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
parameter_set: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
running: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
calibration: {
|
||||
type: Sequelize.TEXT,
|
||||
defaultValue: ''
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Device
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Project = sequelize.define('project', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
desc: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
cycle: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
device: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
subject: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
uuid: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Project
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const ProjectMeta = sequelize.define('project_metas', {
|
||||
project: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
cycle: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
serial_number: {
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return ProjectMeta
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const ProjectReport = sequelize.define('project_report', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
default: ''
|
||||
},
|
||||
desc: {
|
||||
type: Sequelize.STRING,
|
||||
default: ''
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
cycle: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
device: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
uuid: {
|
||||
type: Sequelize.STRING(36)
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return ProjectReport
|
||||
}
|
||||
@@ -22,12 +22,12 @@ module.exports = (sequelize, Sequelize) => {
|
||||
defaultValue: ''
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
time_duration: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '0'
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
@@ -53,6 +53,9 @@ module.exports = (sequelize, Sequelize) => {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
project: {
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
parameter_set: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
@@ -79,7 +82,11 @@ module.exports = (sequelize, Sequelize) => {
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
|
||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: 0
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
path: {
|
||||
type: Sequelize.STRING,
|
||||
@@ -36,12 +36,12 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: -1
|
||||
},
|
||||
start_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
end_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
data_random: {
|
||||
type: Sequelize.TEXT,
|
||||
|
||||
@@ -8,8 +8,8 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: 0
|
||||
},
|
||||
size: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
path: {
|
||||
type: Sequelize.STRING,
|
||||
@@ -32,12 +32,12 @@ module.exports = (sequelize, Sequelize, i) => {
|
||||
defaultValue: -1
|
||||
},
|
||||
start_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
end_time: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: '-1'
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.TEXT,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Scheduler = sequelize.define('scheduler', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
script: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Scheduler
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Subject = sequelize.define('subject', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
cache: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Subject
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const SubjectData = sequelize.define('subject_datas', {
|
||||
subject_id: {
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
mode: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
project: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return SubjectData
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Task = sequelize.define('task', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
describe: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
device_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
chart_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
formula_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
controller_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Task
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const User = sequelize.define('user', {
|
||||
account: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
paword: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
mail: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
devices_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
controller_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
collection_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
meta_list: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return User
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
class ConfigurationModel {
|
||||
async create (req) {
|
||||
return db.charts.create(
|
||||
req
|
||||
)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.charts.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.charts.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.charts.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async get (type, query) {
|
||||
let where = {}
|
||||
if (type === 'chart') {
|
||||
where = {
|
||||
chart: {
|
||||
[Op.ne]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.assign(query, where)
|
||||
const ret = await db.charts.findAll(
|
||||
{
|
||||
where: where
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.charts.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ConfigurationModel
|
||||
@@ -0,0 +1,105 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class TaskModel {
|
||||
async create (req) {
|
||||
console.log(req)
|
||||
return db.tasks.create(req)
|
||||
}
|
||||
|
||||
async update (req) {
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.tasks.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.tasks.delete(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.tasks.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.tasks.findAll()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default TaskModel
|
||||
@@ -4,11 +4,7 @@ const Op = db.Sequelize.Op
|
||||
|
||||
class CollectionModel {
|
||||
async create (req) {
|
||||
return db.collections.create({
|
||||
name: req.name,
|
||||
parent: req.parent,
|
||||
size: req.size
|
||||
})
|
||||
return db.collections.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
@@ -23,17 +19,67 @@ class CollectionModel {
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.collections.delete(
|
||||
async getByQueryWithAttrs (query, attrs) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.collections.findAll(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
where: query,
|
||||
attributes: attrList
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByParentWithOffsetLimitOrder (type, parent, limit, offset, order, attrs) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const orderList = order ? order.split('-') : ['id', 'desc']
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
|
||||
console.log('getByParentWithOffsetLimitOrder', type, parent, limit, offset, order, attrs)
|
||||
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.collections.findAndCountAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
attributes: attrList,
|
||||
order: [
|
||||
orderList
|
||||
],
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (controllerID) {
|
||||
let ret
|
||||
if (controllerID == null) {
|
||||
ret = await db.collections.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
ret = await db.collections.destroy(
|
||||
{
|
||||
where: {
|
||||
controller_id: controllerID,
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.collections.findAll(
|
||||
{
|
||||
@@ -45,14 +91,26 @@ class CollectionModel {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.collections.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
async getByName (name, controllerID) {
|
||||
let ret
|
||||
if (controllerID == null) {
|
||||
ret = await db.collections.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
} else {
|
||||
ret = await db.collections.findAll(
|
||||
{
|
||||
where: {
|
||||
controller_id: controllerID,
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -100,8 +158,19 @@ class CollectionModel {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.collections.findAll()
|
||||
async getAll (controllerID) {
|
||||
let ret
|
||||
if (controllerID == null) {
|
||||
ret = await db.collections.findAll()
|
||||
} else {
|
||||
ret = await db.collections.findAll(
|
||||
{
|
||||
where: {
|
||||
controller_id: controllerID
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import RecordingDataRaw from './recording_data_raw'
|
||||
import RecordingDataMini from './recording_data_mini'
|
||||
const db = require('../../db/database')
|
||||
// const RecordingDataMini = require('./recording_data_mini')
|
||||
|
||||
const recordingDataRaw = new RecordingDataRaw()
|
||||
const recordingDataMini = new RecordingDataMini()
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
@@ -36,7 +42,34 @@ class RecordingDataMeta {
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.recording_data_metas.destroy(
|
||||
let ret = await db.recording_data_metas.findAll(
|
||||
{
|
||||
attributes: [
|
||||
'id',
|
||||
'raw_data',
|
||||
'mini_data'
|
||||
],
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
for (let i = 0; i < ret.length; i++) {
|
||||
const meta = ret[i]
|
||||
for (const channel in meta.raw_data) {
|
||||
if (meta.raw_data[channel] != null) {
|
||||
await recordingDataRaw.updateByIDs({ deleted: true }, meta.raw_data[channel], channel)
|
||||
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)
|
||||
}
|
||||
recordingDataMini.clearDeleted(channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = await db.recording_data_metas.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
@@ -58,13 +91,95 @@ class RecordingDataMeta {
|
||||
parent: parentOp
|
||||
},
|
||||
order: [
|
||||
['id', 'ASC']
|
||||
['id', 'DESC']
|
||||
]
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrParent (type, parent, attr) {
|
||||
const attrList = attr.split('-')
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
attributes: attrList,
|
||||
order: [
|
||||
['id', 'DESC']
|
||||
]
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getCountByParent (type, parent) {
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.count(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByParentWithLimit (type, parent, limit, offset, order) {
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAndCountAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
order: [
|
||||
['id', order]
|
||||
],
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrsParentWithLimit (type, parent, limit, offset, order, attr) {
|
||||
const attrList = attr.split('-')
|
||||
const orderList = order.split('-')
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAndCountAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
attributes: attrList,
|
||||
order: [
|
||||
[orderList[0], orderList[1]]
|
||||
],
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.recording_data_metas.findAll(
|
||||
{
|
||||
@@ -131,6 +246,263 @@ class RecordingDataMeta {
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
console.log('getByQueryWithAttrs', query, limit, offset, order, attrs, group)
|
||||
const result = {}
|
||||
let attrList = attrs ? attrs.split('-') : undefined
|
||||
// group by time
|
||||
if (group === 'time') {
|
||||
const timeGroupNum = await db.recording_data_metas.findAll(
|
||||
{
|
||||
attributes: [[db.Sequelize.fn('COUNT', db.Sequelize.fn('DISTINCT', db.Sequelize.fn('DATE', db.Sequelize.col('created_at')))), 'GroupCount']]
|
||||
}
|
||||
)
|
||||
result.counts = timeGroupNum
|
||||
|
||||
attrList = [[db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), 'date'], [db.sequelize.fn('COUNT', 'date'), 'count']]
|
||||
group = [db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), 'date']
|
||||
order = [[db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), 'desc']]
|
||||
}
|
||||
// group by project
|
||||
if (group === 'project') {
|
||||
attrList = [['project', 'project']]
|
||||
group = ['project', 'project']
|
||||
order = [['project', 'desc']]
|
||||
}
|
||||
// query by time
|
||||
if (query.time) {
|
||||
const start = new Date(query.time)
|
||||
const end = new Date(query.time)
|
||||
end.setDate(end.getDate() + 1)
|
||||
delete query.time
|
||||
query.created_at = {
|
||||
[Op.gte]: start,
|
||||
[Op.lte]: end
|
||||
}
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
group: group,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
result.rows = ret
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
async getByFolderWithParentLimitOffsetOrderAttrs (type, parent, limit, offset, order, attrs) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const orderList = order ? order.split('-') : ['id', 'desc']
|
||||
const collectionType = type + '::jsonb'
|
||||
const parentOp = {}
|
||||
|
||||
console.log('getByFolderWithParentLimitOffsetOrderAttr', type, parent, limit, offset, order, attrs)
|
||||
|
||||
parentOp[collectionType] = {
|
||||
[Op.contains]: '[' + parent + ']'
|
||||
}
|
||||
const ret = await db.recording_data_metas.findAndCountAll(
|
||||
{
|
||||
where: {
|
||||
parent: parentOp
|
||||
},
|
||||
attributes: attrList,
|
||||
order: [
|
||||
[orderList[0], orderList[1]]
|
||||
],
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByProject (uuid) {
|
||||
const [results, _] = await db.sequelize.query(`
|
||||
WITH ProjectData AS (SELECT * FROM project_reports WHERE uuid='${uuid}')
|
||||
SELECT rdm.* FROM ProjectData pr
|
||||
LEFT JOIN project_metas pm ON pr.uuid = pm.project
|
||||
LEFT JOIN recording_data_metas rdm ON pm.id = rdm.project
|
||||
ORDER BY rdm.id desc
|
||||
`)
|
||||
return results
|
||||
}
|
||||
|
||||
async findWithIdRange1 (metaIdArray, range) {
|
||||
/* get x channel & range, y channel & range */
|
||||
const channelX = range[0][0]
|
||||
const rangeX = range[0].slice(1, 3).sort(function (a, b) {
|
||||
return a - b
|
||||
})
|
||||
const channelY = range[1][0]
|
||||
const rangeY = range[1].slice(1, 3).sort(function (a, b) {
|
||||
return a - b
|
||||
})
|
||||
// console.log(channelX, rangeX, channelY, rangeY)
|
||||
const pairID = []
|
||||
|
||||
/* loop with given idArray */
|
||||
for (const _id of metaIdArray) {
|
||||
const meta = await db.recording_data_metas.findOne({
|
||||
where: {
|
||||
id: _id
|
||||
},
|
||||
attributes: ['id', 'raw_data', 'name']
|
||||
})
|
||||
/* if channel has time */
|
||||
if (channelX === 'Time' || channelY === 'Time') {
|
||||
if (channelX === 'Time') {
|
||||
/* if x is time, then get the y channel data */
|
||||
for (const index in meta.raw_data[channelY]) {
|
||||
/* if meta id is paired already then break */
|
||||
if (pairID.findIndex((ele) => ele[0] === meta.id) !== -1) break
|
||||
const rawID = meta.raw_data[channelY][index]
|
||||
const rawData = await db[channelY + '_recording_data_raws'].findOne({
|
||||
where: {
|
||||
id: rawID
|
||||
}
|
||||
})
|
||||
/* get time & data */
|
||||
const data = rawData.data.replace(/"\*\*\*"/g, ' ').split(' ')
|
||||
const time = data.filter((ele, index) => index % 2 === 0)
|
||||
const value = data.filter((ele, index) => index % 2 === 1)
|
||||
/* check with value & time range */
|
||||
for (let index = 0; index < value.length; index++) {
|
||||
if (value[index] <= rangeY[1] && value[index] >= rangeY[0]) {
|
||||
if (time[index] <= rangeX[1] && time[index] >= rangeX[0]) {
|
||||
pairID.push([meta.id, meta.name])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (channelY === 'Time') {
|
||||
for (const index in meta.raw_data[channelX]) {
|
||||
if (pairID.findIndex((ele) => ele[0] === meta.id) !== -1) break
|
||||
const rawID = meta.raw_data[channelX][index]
|
||||
const rawData = await db[channelX + '_recording_data_raws'].findOne({
|
||||
where: {
|
||||
id: rawID
|
||||
}
|
||||
})
|
||||
/* get time & data */
|
||||
const data = rawData.data.replace(/"\*\*\*"/g, ' ').split(' ')
|
||||
const time = data.filter((ele, index) => index % 2 === 0)
|
||||
const value = data.filter((ele, index) => index % 2 === 1)
|
||||
/* check with value & time range */
|
||||
for (let index = 0; index < value.length; index++) {
|
||||
if (value[index] <= rangeX[1] && value[index] >= rangeX[0]) {
|
||||
if (time[index] <= rangeY[1] && time[index] >= rangeY[0]) {
|
||||
pairID.push([meta.id, meta.name])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* when two channels are not time */
|
||||
/* loop with raw data id */
|
||||
for (const index in meta.raw_data[channelX]) {
|
||||
/* if meta id is paired already then break */
|
||||
if (pairID.findIndex((ele) => ele[0] === meta.id) !== -1) break
|
||||
/* get X channel data */
|
||||
const rawIDX = meta.raw_data[channelX][index]
|
||||
const rawDataX = await db[channelX + '_recording_data_raws'].findOne({
|
||||
where: {
|
||||
id: rawIDX
|
||||
}
|
||||
})
|
||||
const valueX = rawDataX.data.replace(/"\*\*\*"/g, ' ').split(' ').filter((ele, index) => index % 2 === 1)
|
||||
/* get Y channel data */
|
||||
const rawIDY = meta.raw_data[channelY][index]
|
||||
const rawDataY = await db[channelY + '_recording_data_raws'].findOne({
|
||||
where: {
|
||||
id: rawIDY
|
||||
}
|
||||
})
|
||||
const valueY = rawDataY.data.replace(/"\*\*\*"/g, ' ').split(' ').filter((ele, index) => index % 2 === 1)
|
||||
/* if x value in range then check y value in range */
|
||||
for (let index = 0; index < valueX.length; index++) {
|
||||
if (valueX[index] <= rangeX[1] && valueX[index] >= rangeX[0]) {
|
||||
if (valueY[index] <= rangeY[1] && valueY[index] >= rangeY[0]) {
|
||||
pairID.push([meta.id, meta.name])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('pair', pairID)
|
||||
}
|
||||
return pairID
|
||||
}
|
||||
|
||||
// async findWithIdRange (id, range) {
|
||||
// const channel = String(range[0][0])
|
||||
// const dataRange = range[0].slice(1, 3)
|
||||
// const matchFile = []
|
||||
|
||||
// for (const _id of id) {
|
||||
// console.log('id', _id)
|
||||
// const meta = await db.recording_data_metas.findOne({
|
||||
// where: {
|
||||
// id: _id
|
||||
// },
|
||||
// attributes: ['id', 'raw_data', 'name']
|
||||
// })
|
||||
// if (await matchRange(channel, meta.raw_data[channel], dataRange) === true) {
|
||||
// matchFile.push(meta.id)
|
||||
// }
|
||||
// }
|
||||
|
||||
// console.log('matchFile', matchFile)
|
||||
// const channel1 = range[1][0]
|
||||
// const range1 = range[1].slice(1, 3)
|
||||
// const doubleMatchFile = []
|
||||
|
||||
// for (const _id of matchFile) {
|
||||
// const meta = await db.recording_data_metas.findOne({
|
||||
// where: {
|
||||
// id: _id
|
||||
// },
|
||||
// attributes: ['id', 'raw_data', 'name']
|
||||
// })
|
||||
// console.log('meta', meta.id)
|
||||
// if (await matchRange(channel1, meta.raw_data[channel1], range1) === true) {
|
||||
// doubleMatchFile.push([meta.id, meta.name])
|
||||
// }
|
||||
// }
|
||||
// console.log('doubleMatchFile', doubleMatchFile)
|
||||
// return doubleMatchFile
|
||||
// }
|
||||
// }
|
||||
|
||||
// async function matchRange (channel, rawIdList, range) {
|
||||
// console.log('matchRange', channel, rawIdList, range)
|
||||
// for (const rawId of rawIdList) {
|
||||
// const raw = await db[channel + '_recording_data_raws'].findOne({
|
||||
// where: {
|
||||
// id: rawId
|
||||
// }
|
||||
// })
|
||||
// const value = raw.data.split('"***"')[0].split(' ').filter((ele, index) => index % 2 === 1)
|
||||
// for (const val of value) {
|
||||
// console.log('val', val)
|
||||
// if (val < range[1] && val > range[0]) {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
}
|
||||
|
||||
export default RecordingDataMeta
|
||||
|
||||
@@ -19,11 +19,23 @@ class RecordingDataMini {
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index) {
|
||||
async updateByIDs (req, id, index) {
|
||||
const ret = await db[index + '_recording_data_minis'].update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index, where = { deleted: true }) {
|
||||
const ret = await db[index + '_recording_data_minis'].destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
...where
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -57,6 +69,30 @@ class RecordingDataMini {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getExistOrNotByID (id, index) {
|
||||
const ret = await db[index + '_recording_data_minis'].findOne(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
).then(token => !(token.data_mean === ''))
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByIDs (id, index) {
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
||||
{
|
||||
batchSize: 1000,
|
||||
where: {
|
||||
id: _id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getMeanDataByID (id, index) {
|
||||
const ret = await db[index + '_recording_data_minis'].findAllWithStream(
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const db = require('../../db/database')
|
||||
const sequelize = require('sequelize')
|
||||
|
||||
class RecordingDataRaw {
|
||||
async create (req, index) {
|
||||
@@ -19,11 +20,28 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index) {
|
||||
async updateSdData (req, id, index) {
|
||||
const ret = await db.sequelize.query(`UPDATE "public"."${index}_recording_data_raws" SET sd_data = sd_data || '${req.data}' WHERE id = ${String(id)}`)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByIDs (req, id, index) {
|
||||
const ret = await db[index + '_recording_data_raws'].update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted (index, where = { deleted: true }) {
|
||||
const ret = await db[index + '_recording_data_raws'].destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
...where
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -57,6 +75,19 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByIDs (id, index) {
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||
{
|
||||
batchSize: 1000,
|
||||
where: {
|
||||
id: _id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getDataByID (id, index) {
|
||||
const ret = await db[index + '_recording_data_raws'].findAllWithStream(
|
||||
{
|
||||
@@ -85,6 +116,23 @@ class RecordingDataRaw {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrIDs (id, attr, index) {
|
||||
const attrList = attr.split('-')
|
||||
const _id = JSON.parse('[' + id + ']')
|
||||
const ord = [sequelize.literal(`ARRAY_POSITION(ARRAY[${_id}]::integer[], "id")`)]
|
||||
|
||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||
{
|
||||
where: {
|
||||
id: _id
|
||||
},
|
||||
attributes: attrList,
|
||||
order: ord
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttrParent (parent, attr, index) {
|
||||
const attrList = attr.split('-')
|
||||
const ret = await db[index + '_recording_data_raws'].findAll(
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class ControllerModel {
|
||||
async create (req) {
|
||||
console.log(req)
|
||||
return db.controllers.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
if (id != null) {
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
const ret = await db.controllers.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.controllers.delete(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByMac (mac) {
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: {
|
||||
mac_address: mac
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.controllers.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.controllers.findAll()
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ControllerModel
|
||||
@@ -0,0 +1,151 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class DeviceModel {
|
||||
async create (req) {
|
||||
return db.devices.create({
|
||||
name: req.name,
|
||||
serial_number: req.serial_number,
|
||||
mac_address: req.mac_address,
|
||||
connect_priority: await db.devices.count()
|
||||
})
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
if (id != null) {
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async updateByID (req, id) {
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByMac (req, mac) {
|
||||
req.updated_at = db.Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
mac_address: mac
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.devices.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.devices.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByName (name) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
name: name
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByMac (mac) {
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: {
|
||||
mac_address: mac
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
const whereObj = {}
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.devices.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.devices.findAll({
|
||||
order: [
|
||||
['connect_priority', 'ASC']
|
||||
]
|
||||
})
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default DeviceModel
|
||||
@@ -0,0 +1,97 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
// const Op = db.Sequelize.Op
|
||||
|
||||
class ProjectModal {
|
||||
async create (req) {
|
||||
return db.projects.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.projects.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.projects.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async updateByAttr (req, attr, value) {
|
||||
const whereObj = {}
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.projects.update(
|
||||
req,
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.projects.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByID (id) {
|
||||
const ret = await db.projects.findAll(
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByAttr (attr, value) {
|
||||
const attrList = attr.split('-')
|
||||
const valueList = value.split('-')
|
||||
const whereObj = {}
|
||||
attrList.forEach((key, idx) => {
|
||||
whereObj[key] = valueList[idx]
|
||||
})
|
||||
|
||||
const ret = await db.projects.findAll(
|
||||
{
|
||||
where: whereObj
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getAll () {
|
||||
const ret = await db.projects.findAll({
|
||||
order: [
|
||||
['created_at', 'ASC']
|
||||
]
|
||||
})
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ProjectModal
|
||||
@@ -0,0 +1,46 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
class ProjectMeta {
|
||||
async create (req) {
|
||||
return db.project_metas.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.project_metas.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.project_metas.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, attrs, order) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const orderList = order ? order.split('-') : ['id', 'desc']
|
||||
console.log('getByQueryWithAttrs', query, attrs, order)
|
||||
const ret = await db.project_metas.findAndCountAll(
|
||||
{
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
// group: group,
|
||||
order: [orderList]
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ProjectMeta
|
||||
@@ -0,0 +1,46 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
class ProjectReport {
|
||||
async create (req) {
|
||||
return db.project_reports.create(req)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.project_reports.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.project_reports.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, attrs, order) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const orderList = order ? order.split('-') : ['id', 'desc']
|
||||
console.log('getByQueryWithAttrs', query, attrs, order)
|
||||
const ret = await db.project_reports.findAndCountAll(
|
||||
{
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
// group: group,
|
||||
order: [orderList]
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default ProjectReport
|
||||
@@ -0,0 +1,79 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
class SubjectModel {
|
||||
async create (req) {
|
||||
return db.subjects.create(
|
||||
req
|
||||
)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.subjects.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.subjects.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.subjects.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async get (type, query) {
|
||||
let where = {}
|
||||
if (type === 'chart') {
|
||||
where = {
|
||||
chart: {
|
||||
[Op.ne]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.assign(query, where)
|
||||
const ret = await db.subjects.findAll(
|
||||
{
|
||||
where: where
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.subjects.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default SubjectModel
|
||||
@@ -0,0 +1,70 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
class SubjectDataModel {
|
||||
async create (req) {
|
||||
return db.charts.create(
|
||||
req
|
||||
)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.subject_datas.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.subject_datas.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.subject_datas.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async get (query) {
|
||||
const ret = await db.subject_datas.findAll(
|
||||
{
|
||||
where: query
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.subject_datas.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default SubjectDataModel
|
||||
+107
-7
@@ -17,32 +17,51 @@ export default router
|
||||
.get('/public/auth/get_cookie', controllers.auth.getCookie)
|
||||
|
||||
// collection
|
||||
.post('/api/collection/create', controllers.collection.create)
|
||||
.get('/api/collection/get_by_id/:id', controllers.collection.getByID)
|
||||
.get('/api/collection/get_by_name/:name', controllers.collection.getByName)
|
||||
.get('/api/collection/get_by_parent/:type/:parent', controllers.collection.getByParent)
|
||||
.get('/api/collection/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName)
|
||||
.get('/api/collection/get/all', controllers.collection.getAll)
|
||||
.post('/api/file/collection/create', controllers.collection.create)
|
||||
.post('/api/file/collection/update/:id', controllers.collection.update)
|
||||
.get('/api/file/collection/clear_deleted/:controller_id', controllers.collection.clearDeleted)
|
||||
.get('/api/file/collection/get_by_id/:id', controllers.collection.getByID)
|
||||
.get('/api/file/collection/get_by_name/:name/:controller_id', controllers.collection.getByName)
|
||||
.get('/api/file/collection/get_by_parent/:type/:parent', controllers.collection.getByParent)
|
||||
.get('/api/file/collection/get_by_parent_name/:type/:parent/:name', controllers.collection.getByParentName)
|
||||
.get('/api/file/collection/get/all/:controller_id', controllers.collection.getAll)
|
||||
|
||||
.get('/api/file/collection/get_by_name/:name', controllers.collection.getByName)
|
||||
.get('/api/file/collection/get/all', controllers.collection.getAll)
|
||||
.get('/api/file/collection/clear_deleted/', controllers.collection.clearDeleted)
|
||||
|
||||
.get('/api/file/collection/get', controllers.collection.get)
|
||||
|
||||
// meta
|
||||
.post('/api/file/meta/create', controllers.recordingDataMeta.create)
|
||||
.post('/api/file/meta/update/:id', controllers.recordingDataMeta.update)
|
||||
.get('/api/file/meta/clear_deleted/:id', controllers.recordingDataMeta.clearDeleted)
|
||||
.get('/api/file/meta/clear_deleted/', controllers.recordingDataMeta.clearDeleted)
|
||||
.get('/api/file/meta/get_by_name/:name', controllers.recordingDataMeta.getByName)
|
||||
.get('/api/file/meta/get_by_uuid/:uuid', controllers.recordingDataMeta.getByUUID)
|
||||
.get('/api/file/meta/get_by_id/:id', controllers.recordingDataMeta.getByID)
|
||||
.get('/api/file/meta/get_by_path/:path', controllers.recordingDataMeta.getByPath)
|
||||
.get('/api/file/meta/get_by_parent/:type/:parent', controllers.recordingDataMeta.getByParent)
|
||||
.get('/api/file/meta/get_attr_by_parent/:type/:parent/:attr', controllers.recordingDataMeta.getAttrByParent)
|
||||
.get('/api/file/meta/get_count_by_parent/:type/:parent', controllers.recordingDataMeta.getCountByParent)
|
||||
.get('/api/file/meta/get_by_parent_with_limit/:type/:parent/:limit/:offset/:order', controllers.recordingDataMeta.getByParentWithLimit)
|
||||
.get('/api/file/meta/get_by_attr_parent_with_limit/:type/:parent/:limit/:offset/:order/:attr', controllers.recordingDataMeta.getByAttrsParentWithLimit)
|
||||
.get('/api/file/meta/get_or_create_by_path/:path', controllers.recordingDataMeta.getOrCreateByPath)
|
||||
.get('/api/file/meta/get/all', controllers.recordingDataMeta.getAll)
|
||||
|
||||
.get('/api/file/meta/find', controllers.recordingDataMeta.findWithIdRange)
|
||||
.get('/api/file/meta/get', controllers.recordingDataMeta.get)
|
||||
|
||||
// raw
|
||||
.post('/api/file/raw/create/:channel', controllers.recordingDataRaw.create)
|
||||
.post('/api/file/raw/update/:channel/:id', controllers.recordingDataRaw.update)
|
||||
.post('/api/file/raw/update_sd_data/:channel/:id', controllers.recordingDataRaw.updateSdData)
|
||||
.get('/api/file/raw/clear_deleted/:channel/:id', controllers.recordingDataRaw.clearDeleted)
|
||||
.get('/api/file/raw/get_by_id/:channel/:id', controllers.recordingDataRaw.getByID)
|
||||
.get('/api/file/raw/get_by_ids/:channel/:id', controllers.recordingDataRaw.getByIDs)
|
||||
.get('/api/file/raw/get_data_by_id/:channel/:id', controllers.recordingDataRaw.getDataByID)
|
||||
.get('/api/file/raw/get_by_parent/:channel/:parent', controllers.recordingDataRaw.getByParent)
|
||||
.get('/api/file/raw/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByID)
|
||||
.get('/api/file/raw/get_attr_by_ids/:channel/:id/:attr', controllers.recordingDataRaw.getAttrByIDs)
|
||||
.get('/api/file/raw/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataRaw.getAttrByParent)
|
||||
|
||||
// mini
|
||||
@@ -50,8 +69,89 @@ export default router
|
||||
.post('/api/file/mini/update/:channel/:id', controllers.recordingDataMini.update)
|
||||
.get('/api/file/mini/clear_deleted/:channel/:id', controllers.recordingDataMini.clearDeleted)
|
||||
.get('/api/file/mini/get_by_id/:channel/:id', controllers.recordingDataMini.getByID)
|
||||
.get('/api/file/mini/get_exist_or_not_by_id/:channel/:id', controllers.recordingDataMini.getExistOrNotByID)
|
||||
.get('/api/file/mini/get_by_parent/:channel/:parent', controllers.recordingDataMini.getByParent)
|
||||
.get('/api/file/mini/get_attr_by_id/:channel/:id/:attr', controllers.recordingDataMini.getAttrByID)
|
||||
.get('/api/file/mini/get_attr_by_parent/:channel/:parent/:attr', controllers.recordingDataMini.getAttrByParent)
|
||||
.get('/api/file/mini/random/get_by_id/:channel/:id', controllers.recordingDataMini.getRandomDataByID)
|
||||
.get('/api/file/mini/mean/get_by_id/:channel/:id', controllers.recordingDataMini.getMeanDataByID)
|
||||
|
||||
// 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)
|
||||
.post('/api/device/update_by_attr/:attr/:value', controllers.device.updateByAttr)
|
||||
.get('/api/device/clear_deleted/:id', controllers.device.clearDeleted)
|
||||
.get('/api/device/get_by_mac/:mac', controllers.device.getByMac)
|
||||
.get('/api/device/get_by_attr/:attr/:value', controllers.device.getByAttr)
|
||||
.get('/api/device/get/all', controllers.device.getAll)
|
||||
|
||||
.post('/api/device/update_by_id/:id', controllers.device.updateByID)
|
||||
.post('/api/device/update', controllers.device.update)
|
||||
|
||||
// controller
|
||||
.post('/api/controller/create', controllers.controller.create)
|
||||
.post('/api/controller/update/:id', controllers.controller.update)
|
||||
.post('/api/controller/update/all', controllers.controller.update)
|
||||
.post('/api/controller/update_by_attr/:attr/:value', controllers.controller.updateByAttr)
|
||||
.get('/api/controller/get_by_mac/:mac', controllers.controller.getByMac)
|
||||
.get('/api/controller/get_by_attr/:attr/:value', controllers.controller.getByAttr)
|
||||
.get('/api/controller/get/all', controllers.controller.getAll)
|
||||
|
||||
.post('/api/controller/update_by_id/:id', controllers.controller.updateByID)
|
||||
.post('/api/controller/update', controllers.controller.update)
|
||||
|
||||
// task
|
||||
.post('/api/task/create', controllers.task.create)
|
||||
.post('/api/task/update/:id', controllers.task.update)
|
||||
.post('/api/task/update_by_attr/:attr/:value', controllers.task.updateByAttr)
|
||||
.post('/api/task/update/all', controllers.task.update)
|
||||
.get('/api/task/get_by_id/:id', controllers.task.getByID)
|
||||
.get('/api/task/get_by_attr/:attr/:value', controllers.task.getByAttr)
|
||||
.get('/api/task/get/all', controllers.task.getAll)
|
||||
|
||||
.post('/api/task/update', controllers.task.update)
|
||||
.post('/api/task/update_by_id/:id', controllers.task.updateByID)
|
||||
// analyze
|
||||
.post('/api/analysis/spike_detect', controllers.analysis.spikeDetect)
|
||||
.get('/api/analysis/get/csv', controllers.analysis.getCSV)
|
||||
|
||||
// project
|
||||
.post('/api/project/create', controllers.project.create)
|
||||
.post('/api/project/update/:id', controllers.project.update)
|
||||
.post('/api/project/update_by_attr/:attr/:value', controllers.project.updateByAttr)
|
||||
.post('/api/project/update/all', controllers.project.update)
|
||||
.get('/api/project/clear_deleted/:controller_id', controllers.project.clearDeleted)
|
||||
.get('/api/project/get_by_id/:id', controllers.project.getByID)
|
||||
.get('/api/project/get_by_attr/:attr/:value', controllers.project.getByAttr)
|
||||
.get('/api/project/get/all', controllers.project.getAll)
|
||||
|
||||
// projectReport
|
||||
.post('/api/project/report/create', controllers.projectReport.create)
|
||||
.post('/api/project/report/update/:id', controllers.projectReport.update)
|
||||
.get('/api/project/report/get', controllers.projectReport.get)
|
||||
|
||||
// projectMeta
|
||||
.post('/api/project/meta/create', controllers.projectMeta.create)
|
||||
.post('/api/project/meta/update/:id', controllers.projectMeta.update)
|
||||
.get('/api/project/meta/get', controllers.projectMeta.get)
|
||||
|
||||
// configuration
|
||||
.post('/api/configuration/create', controllers.chart.create)
|
||||
.post('/api/configuration/update/:id', controllers.chart.update)
|
||||
.get('/api/configuration/get', controllers.chart.get)
|
||||
.get('/api/configuration/clear_deleted/', controllers.chart.clearDeleted)
|
||||
|
||||
// subject
|
||||
.post('/api/subject/create', controllers.subject.create)
|
||||
.post('/api/subject/update/:id', controllers.subject.update)
|
||||
.get('/api/subject/get', controllers.subject.get)
|
||||
.get('/api/subject/clear_deleted/', controllers.subject.clearDeleted)
|
||||
|
||||
// subject_data
|
||||
.post('/api/subject_data/create', controllers.subjectData.create)
|
||||
.post('/api/subject_data/update/:id', controllers.subjectData.update)
|
||||
.get('/api/subject_data/get', controllers.subjectData.get)
|
||||
.get('/api/subject_data/clear_deleted/', controllers.subjectData.clearDeleted)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Elite: 53
|
||||
# Neulive: 101 or 95
|
||||
ssh -NL 54321:localhost:5432 pi@192.168.2.1
|
||||
Reference in New Issue
Block a user