connect to pokai file select UI
This commit is contained in:
+19
@@ -67,6 +67,7 @@ class dataAnalyticFunc():
|
||||
return data_list, cut_bins
|
||||
|
||||
def cal_slop_array(self, window = 10):
|
||||
# print(self._raw_data)
|
||||
print('window')
|
||||
if window*2+1 >= len(self._raw_data):
|
||||
print('Scale of data are smaller than window.')
|
||||
@@ -100,3 +101,21 @@ class dataAnalyticFunc():
|
||||
for i in range(len(df)-1):
|
||||
df[value_name].iloc[i+1]-df[value_name].iloc[i]
|
||||
|
||||
def integral_func(self, int_value_name, int_key_name, sort=True ):
|
||||
df = self._raw_data.sort_values(int_key_name) if sort else self._raw_data
|
||||
temp_value_sum = 0
|
||||
last_key = df[int_key_name].iloc[0]
|
||||
temp_key_num = 0
|
||||
integral_value = 0
|
||||
for i in range(len(df)):
|
||||
row = df.iloc[i]
|
||||
if last_key == row[int_key_name] :
|
||||
temp_value_sum += row[int_value_name]
|
||||
temp_key_num += 1
|
||||
else:
|
||||
integral_value += (row[int_key_name]-last_key) * temp_value_sum/temp_key_num
|
||||
last_key = row[int_key_name]
|
||||
temp_value_sum = row[int_value_name]
|
||||
temp_key_num = 1
|
||||
return integral_value
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import json,csv
|
||||
# from deviceManager import DeviceManager
|
||||
# from requests import Requests
|
||||
from mqtt import MqttThread
|
||||
from test import VTmode_run, slop_run ,search_id_by_str
|
||||
from test import VTmode_run, slop_run ,CVmode_run ,search_id_by_str
|
||||
|
||||
class Main():
|
||||
def __init__(self, controller_id = 'dc:a6:32:0f:56:9d', mqtt_ip = '192.168.2.1') -> None:
|
||||
@@ -19,18 +19,20 @@ class Main():
|
||||
def get_analysis_data(self, input:str):
|
||||
start_time = time.time()
|
||||
input_data = json.loads(input)['e']
|
||||
print(input_data['data_name'])
|
||||
search_id = input_data['data_id'] if input_data['data_id'] else search_id_by_str(input_data['data_name'])
|
||||
# print(input_data['data_name'])
|
||||
# print([i.split('-') for i in input_data['data_id']])
|
||||
search_id = [int(i.split('-')[1]) for i in input_data['data_id']]
|
||||
print(search_id)
|
||||
with open('csv_file/output.csv', 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
print([[i[0],i[1]] for i in input_data.items()])
|
||||
# print([[i[0],i[1]] for i in input_data.items()])
|
||||
writer.writerows([[i[0],i[1]] for i in input_data.items()])
|
||||
writer.writerow("")
|
||||
if input_data['mode'] == 1:
|
||||
first_flag = True
|
||||
for i in search_id:
|
||||
raw_data, csv_data = VTmode_run(i, input_data['data']['persentage'])
|
||||
print(i)
|
||||
raw_data, csv_data = VTmode_run(i, input_data['data_channel'], input_data['data']['persentage'])
|
||||
fieldnames = list(csv_data.keys())
|
||||
print(fieldnames)
|
||||
dict_writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
@@ -41,15 +43,17 @@ class Main():
|
||||
print('csv_data', csv_data)
|
||||
|
||||
dict_writer.writerow(csv_data)
|
||||
elif input_data['mode'] == 3:
|
||||
print('mode333')
|
||||
raw_data = CVmode_run()
|
||||
print('mode3')
|
||||
else:
|
||||
for i in search_id:
|
||||
raw_data = slop_run(i, input_data['data']['window'])
|
||||
raw_data = slop_run(i, input_data['data_channel'], input_data['data']['window'])
|
||||
self._mqttThread.publish(raw_data)
|
||||
end_time = time.time()
|
||||
print("執行時間:%f 秒" % (end_time - start_time))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# if len(sys.argv) < 3:
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,8 @@
|
||||
import psycopg2
|
||||
import ana_func
|
||||
import matplotlib.pyplot as plt
|
||||
import csv, math
|
||||
import csv
|
||||
import pandas as pd
|
||||
|
||||
def search_id_by_str(keyword):
|
||||
conn = psycopg2.connect(database="postgres", user="biopro", password="BioProControlBox", host="127.0.0.1", port="5432")
|
||||
@@ -12,7 +13,7 @@ def search_id_by_str(keyword):
|
||||
data = [i[0] for i in data]
|
||||
return data
|
||||
|
||||
def read_data(id):
|
||||
def read_data(id,channel_list):
|
||||
conn = psycopg2.connect(database="postgres", user="biopro", password="BioProControlBox", host="127.0.0.1", port="5432")
|
||||
cur = conn.cursor()
|
||||
|
||||
@@ -20,7 +21,8 @@ def read_data(id):
|
||||
cur.execute(sql_str)
|
||||
data = cur.fetchall()[0][0]
|
||||
channel_data = []
|
||||
for i in ['1','2']:
|
||||
for channel in channel_list:
|
||||
i = str(channel+1)
|
||||
channel_data_temp = []
|
||||
for j in data[i]:
|
||||
# print(j)
|
||||
@@ -34,22 +36,39 @@ def read_data(id):
|
||||
|
||||
return channel_data
|
||||
|
||||
def slop_run(id,win):
|
||||
def read_data_csv(file_name=0, start_row=0):
|
||||
df = pd.read_excel("read_file/2021-8-9-15-42-46-0_CV discussion.xlsx",skiprows = 63, usecols="B,D,F,H")
|
||||
data = [list(df['Current[nA]']),list(df['Voltage[uV]'])]
|
||||
# print(df)
|
||||
return data
|
||||
# read_data_csv()
|
||||
|
||||
def CVmode_run():
|
||||
df = read_data_csv()
|
||||
print(df[0][:10])
|
||||
CVmode = ana_func.dataAnalyticFunc(df[0], df[1])
|
||||
cal_slop_data = CVmode.guess_func()
|
||||
return [[i for i in range(len(df[0]))],cal_slop_data]
|
||||
# return [[i for i in range(len(df[0]))],[i/50 for i in df[0]]]
|
||||
# CVmode()
|
||||
|
||||
def slop_run(id, channel_list, win):
|
||||
# id = 166
|
||||
# win = 20
|
||||
print(win)
|
||||
channel_data = read_data(id)
|
||||
channel_data = read_data(id, channel_list)
|
||||
slop_mode = ana_func.dataAnalyticFunc(channel_data[0], channel_data[1])
|
||||
cal_slop_data = slop_mode.guess_func(window=win)
|
||||
return [channel_data[0], cal_slop_data]
|
||||
cal_slop_data = slop_mode.cal_slop_array(window=win)
|
||||
# return [[i for i in range(len(channel_data[0]))], channel_data[1]]
|
||||
return [[i for i in range(len(channel_data[0]))], cal_slop_data]
|
||||
|
||||
|
||||
def VTmode_run(id,percentage):
|
||||
def VTmode_run(id, channel_list, percentage):
|
||||
# id = 166
|
||||
percentage = percentage/100
|
||||
data_list = {'id':id}
|
||||
print(percentage)
|
||||
channel_data = read_data(id)
|
||||
channel_data = read_data(id, channel_list)
|
||||
VT_mode = ana_func.dataAnalyticFunc(channel_data[0], channel_data[1])
|
||||
VT_data_list ,_ = VT_mode.histogram_find_peak()
|
||||
# print('peak list =', data_list['ground'])
|
||||
|
||||
Reference in New Issue
Block a user