Compare commits

...

6 Commits

Author SHA1 Message Date
peterlu14 0386cf1847 Merge remote-tracking branch 'origin/release/update_eis_cali_fomula' into dev/scheduler_folder 2023-04-06 10:52:17 +08:00
peterlu14 62d8610191 - fix UnboundLocalError : 'project_meta_id' 2023-04-06 10:51:43 +08:00
Roy 991f5d06ea [update] use 4hstia calibration down 2023-04-06 09:06:05 +08:00
peterlu14 55711285e6 - update create meta project info change from data-server to control-server 2023-03-31 13:14:33 +08:00
peterlu14 3ec5fee43b - update create collection table
- init project then create folder
2023-03-31 13:14:29 +08:00
Roy 614a9c0b0f [update] hstia pA->nA & hsrtia_b is 8bytes 2023-03-31 10:16:50 +08:00
10 changed files with 215 additions and 112 deletions
+60
View File
@@ -0,0 +1,60 @@
from sqlalchemy import Table, Column, String, MetaData, ForeignKey, JSON
from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB
from biopro.db.base import Session
from .base import Base
class Collection(Base):
__tablename__ = "collections"
id = Column(Integer, primary_key=True)
name = Column(String(255))
parent = Column(JSONB)
controller_id = Column(Integer)
type = Column(String(255))
description = Column(String(255))
deleted = Column(Boolean)
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
@classmethod
def create_collection(cls, collection_name, parent):
with Session() as session:
name = cls.check_name_duplicate(collection_name, parent, 0)
collection = Collection(
name = name,
parent = parent,
type= "folder",
)
session.add(collection)
session.commit()
print('a', collection.id)
return collection
@classmethod
def check_name_duplicate(cls, collection_name, parent, n):
with Session() as session:
result = session.query(Collection).filter(Collection.name == cls.generate_name(collection_name, n), Collection.parent == parent).first()
if result is None:
return cls.generate_name(collection_name, n)
else:
new_num = n + 1
# new_name = f"{collection_name}({new_num})"
return cls.check_name_duplicate(collection_name, parent, new_num)
@classmethod
def generate_name(cls, collection_name, n):
if n==0:
return collection_name
else:
return f"{collection_name}({n})"
@classmethod
def find_collection(cls, collection_name, parent):
with Session() as session:
result = session.query(Collection).filter(Collection.name == collection_name, Collection.parent == parent).first()
return result
+24
View File
@@ -0,0 +1,24 @@
from sqlalchemy import Table, Column, String, MetaData, ForeignKey, JSON
from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB
from .base import Base
class Project(Base):
__tablename__ = "project"
id = Column(Integer, primary_key=True)
name = Column(String)
desc = Column(String)
task = Column(JSONB)
cycle = Column(JSONB)
device = Column(JSONB)
uuid = Column(String(36))
user_auth = Column(JSONB)
deleted = Column(Boolean, default = False)
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
# def __repr__(self):
# return f"User(id={self.id!r}, name={self.name!r}, fullname={self.task!r})"
+9 -1
View File
@@ -3,7 +3,7 @@ from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.dialects.postgresql import JSONB
from .base import Base from .base import Base, Session
class MetaProjectInfo(Base): class MetaProjectInfo(Base):
__tablename__ = "project_metas" __tablename__ = "project_metas"
@@ -17,5 +17,13 @@ class MetaProjectInfo(Base):
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now()) created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now()) updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
@classmethod
def create_project_meta(cls, project):
with Session() as session:
project_meta = MetaProjectInfo(project = project['project'], cycle= project['cycle'], task=project['task'], serial_number=int(project['serial_number']))
session.add(project_meta)
session.commit()
return project_meta.id
# def __repr__(self): # def __repr__(self):
# return f"User(id={self.id!r}, name={self.name!r}, fullname={self.task!r})" # return f"User(id={self.id!r}, name={self.name!r}, fullname={self.task!r})"
+1 -1
View File
@@ -660,7 +660,7 @@ class CC2650Device(Device):
break break
elif device_type == 'EISZeroOne': elif device_type == 'EISZeroOne':
i = 0 i = 1
request_times = 0 request_times = 0
while i < 13: while i < 13:
try: try:
+73 -96
View File
@@ -1414,16 +1414,13 @@ class EISZeroOneDataDecoder(RecDataDecoder):
@staticmethod @staticmethod
def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]: def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
if cali_coeff != b'': if cali_coeff != b'':
cis_data_len = 20
cali_table = [] cali_table = []
hsrtia_a = [] hsrtia_a = []
hsrtia_b = [] hsrtia_b = []
hsrtia_c = [] rolloff = []
hsrtia_d = []
phase_coeff = [] phase_coeff = []
phase_offset = [] phase_offset = []
# phase_coeff = [[0]*4 for i in range(4)]
# phase_offset = [[0]*4 for i in range(4)]
phase_coeff = numpy.zeros([4, 4], dtype = int) phase_coeff = numpy.zeros([4, 4], dtype = int)
phase_offset = numpy.zeros([4, 4], dtype = int) phase_offset = numpy.zeros([4, 4], dtype = int)
@@ -1437,104 +1434,107 @@ class EISZeroOneDataDecoder(RecDataDecoder):
# ] # ]
####################################### #######################################
# print('cali_coeff', cali_coeff) #Lv[0] 160k
cutoff_freq = struct.unpack('>I', cali_coeff[1:5])[0] * 100 #4 cis_cali_packet = 1
# temp = struct.unpack('>B', cali_coeff[5:6])[0] #1 index = (cis_cali_packet - 1) * cis_data_len
# hsrtia_200r = struct.unpack('>B', cali_coeff[6:7])[0] #1 hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
# hsrtia_5k = struct.unpack('>H', cali_coeff[7:9])[0] #2 hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
# hsrtia_20k = struct.unpack('>H', cali_coeff[6:8])[0] #2 rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
# hsrtia_160k = struct.unpack('>I', cali_coeff[8:12])[0] #4
index = 20 cis_cali_packet = 2
index = (cis_cali_packet - 1) * cis_data_len
g = 0 g = 0
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0] phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0] phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0] phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0] phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 40 cis_cali_packet = 3
index = (cis_cali_packet - 1) * cis_data_len
g = 0 g = 0
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0] phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0] phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0] phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0] phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#Lv[0] 160k
index = 60
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big'))
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big'))
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big'))
#Lv[1] 20k #Lv[1] 20k
index = 80 cis_cali_packet = 4
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big')) index = (cis_cali_packet - 1) * cis_data_len
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big')) hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big')) hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 5
index = (cis_cali_packet - 1) * cis_data_len
g = 1
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 6
index = (cis_cali_packet - 1) * cis_data_len
g = 1
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#Lv[2] 5k #Lv[2] 5k
index = 100 cis_cali_packet = 7
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big')) index = (cis_cali_packet - 1) * cis_data_len
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big')) hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big')) hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 8
index = (cis_cali_packet - 1) * cis_data_len
g = 2
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 9
index = (cis_cali_packet - 1) * cis_data_len
g = 2
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#Lv[3] 200R #Lv[3] 200R
index = 120 cis_cali_packet = 10
hsrtia_a.append(int.from_bytes(cali_coeff[index+1:index+6], signed=True, byteorder='big')) index = (cis_cali_packet - 1) * cis_data_len
hsrtia_b.append(int.from_bytes(cali_coeff[index+6:index+11], signed=True, byteorder='big')) hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_c.append(int.from_bytes(cali_coeff[index+11:index+16], signed=True, byteorder='big')) hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
index = 140 cis_cali_packet = 11
g = 1 index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 160
g = 1
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 180
g = 2
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 200
g = 2
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 220
g = 3 g = 3
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0] phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0] phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0] phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0] phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
index = 240 cis_cali_packet = 12
index = (cis_cali_packet - 1) * cis_data_len
g = 3 g = 3
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0] phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0] phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0] phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0] phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
print('cutoff_freq', cutoff_freq)
print('hsrtia_a', hsrtia_a) print('hsrtia_a', hsrtia_a)
print('hsrtia_b', hsrtia_b) print('hsrtia_b', hsrtia_b)
print('hsrtia_c', hsrtia_c) print('rolloff', rolloff)
print('phase_coeff') print('phase_coeff')
print(phase_coeff) print(phase_coeff)
print('phase_offset') print('phase_offset')
print(phase_offset) print(phase_offset)
cali_table.append((cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d)) cali_table.append((phase_coeff, phase_offset, hsrtia_a, hsrtia_b, rolloff))
return cali_table return cali_table
else: else:
@@ -1591,9 +1591,8 @@ class EISZeroOneDataDecoder(RecDataDecoder):
if self.cali_coeff is not None and (self._mode == 0 or self._mode == 5): if self.cali_coeff is not None and (self._mode == 0 or self._mode == 5):
hsrtia_a = [] hsrtia_a = []
hsrtia_b = [] hsrtia_b = []
hsrtia_c = [] rolloff = []
hsrtia_d = [] phase_coeff, phase_offset, hsrtia_a, hsrtia_b, rolloff = self.cali_coeff[0]
cutoff_freq, phase_coeff, phase_offset, hsrtia_a, hsrtia_b, hsrtia_c, hsrtia_d = self.cali_coeff[0]
if (self._mode == 0 or self._mode == 5): if (self._mode == 0 or self._mode == 5):
img = ch1 img = ch1
@@ -1601,19 +1600,11 @@ class EISZeroOneDataDecoder(RecDataDecoder):
freq = ch3 freq = ch3
fre_idx = 0 fre_idx = 0
voltage_amp = round(ch4 / 1000) # Amp[mV] voltage_amp = round(ch4 / 1000) # Amp[mV]
rolloff_cali = rolloff[gain]
# rolloff_cali = cutoff_freq/1e5
rolloff_cali = hsrtia_c[gain]
voltage_mag = math.sqrt(img ** 2 + real ** 2) * (1 + freq ** 2 / rolloff_cali ** 2 / 1e4) voltage_mag = math.sqrt(img ** 2 + real ** 2) * (1 + freq ** 2 / rolloff_cali ** 2 / 1e4)
# if (gain == 3):
# current = hsrtia_a[gain] * math.exp(hsrtia_b[gain] * voltage_mag) + hsrtia_c[gain] * math.exp(hsrtia_d[gain] * voltage_mag)
# else:
current = (voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain]) / 1e8 #[nA] current = (voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain]) / 1e8 #[nA]
# current = voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain] + hsrtia_c[gain]
if (current != 0): if (current != 0):
# impedance[mOhm] = voltage_amp[mv] * 1000000 / 1.414213 / current[nA] #RMS=amp*SQRT(2), SQRT(2)=1.414213 # impedance[mOhm] = voltage_amp[mv] * 1000000 / 1.414213 / current[nA] #RMS=amp*SQRT(2), SQRT(2)=1.414213
impedance = voltage_amp * 707106.78 / current impedance = voltage_amp * 707106.78 / current
@@ -1635,20 +1626,8 @@ class EISZeroOneDataDecoder(RecDataDecoder):
phase = raw_phase - ideal_raw_phase phase = raw_phase - ideal_raw_phase
phase = phase % 180 if phase % 180<=90 else phase % 180-180 phase = phase % 180 if phase % 180<=90 else phase % 180-180
# last_phase_to90 = self._last_phase % 180 if self._last_phase % 180<=90 else self._last_phase % 180-180 imag_after_cal = round(impedance * math.sin(phase * math.pi / 180))
# diff = phase - last_phase_to90 real_after_cal = round(impedance * math.cos(phase * math.pi / 180))
# if (self._first_phase_flag):
# # self._last_phase = phase
# self._first_phase_flag = 0
# elif (abs(diff) >= 90):
# phase = self._last_phase + diff + (180 if diff<0 else-180)
# else:
# phase = self._last_phase + diff
# self._last_phase = phase
imag_after_cal = impedance * math.sin(phase * math.pi / 180)
real_after_cal = impedance * math.cos(phase * math.pi / 180)
if self._show_data: if self._show_data:
if (self._mode == 0 or self._mode == 5): if (self._mode == 0 or self._mode == 5):
@@ -1694,13 +1673,13 @@ class EISZeroOneDataDecoder(RecDataDecoder):
self._mode_stop = 0 self._mode_stop = 0
ret = RecordingData(self.device, int(time_stamp * 1000 / 2), 0) ret = RecordingData(self.device, int(time_stamp * 1000 / 2), 0)
if self._mode == 0 or self._mode == 5: #EIS Mode if self._mode == 0 or self._mode == 5:
ret.append_data(0, ch1) #raw_img ret.append_data(0, ch1) #raw_img
ret.append_data(1, ch2) #raw_real ret.append_data(1, ch2) #raw_real
ret.append_data(2, ch3 * 10) #Frequency [mHz] ret.append_data(2, ch3 * 10) #Frequency [mHz]
ret.append_data(3, cycle_number) #cycle ret.append_data(3, cycle_number) #cycle
ret.append_data(4, round(imag_after_cal)) #Z_imag [Ohm] ret.append_data(4, imag_after_cal) #Z_imag [Ohm]
ret.append_data(5, round(real_after_cal)) #Z_real [Ohm] ret.append_data(5, real_after_cal) #Z_real [Ohm]
ret.append_data(6, round(impedance)) #Impedance [Ohm] ret.append_data(6, round(impedance)) #Impedance [Ohm]
ret.append_data(7, round(phase*1000)) #Phase [millidegree] ret.append_data(7, round(phase*1000)) #Phase [millidegree]
ret.append_data(8, round(current)) #Current [nA] ret.append_data(8, round(current)) #Current [nA]
@@ -1712,8 +1691,6 @@ class EISZeroOneDataDecoder(RecDataDecoder):
ret.append_data(12, notify_three) ret.append_data(12, notify_three)
ret.append_data(13, voltage_amp) #amp[mV] ret.append_data(13, voltage_amp) #amp[mV]
else: #CV Mode else: #CV Mode
ret.append_data(0, ch1) #Iin [nA] ret.append_data(0, ch1) #Iin [nA]
ret.append_data(1, ch2) #Vset [nV] ret.append_data(1, ch2) #Vset [nV]
+14
View File
@@ -15,6 +15,9 @@ from .instruction import Instruction
from biopro.device.manager import DeviceManager from biopro.device.manager import DeviceManager
from biopro.text import * from biopro.text import *
from biopro.db.base import Session
from biopro.db.collection import Collection
key_list = { key_list = {
'deviceList': 'device', 'deviceList': 'device',
} }
@@ -60,6 +63,14 @@ class Project(threading.Thread):
fh = logging.FileHandler(f'/home/pi/logger/project/{self.uuid}.log', mode="w") fh = logging.FileHandler(f'/home/pi/logger/project/{self.uuid}.log', mode="w")
fh.setFormatter(self._formatter) fh.setFormatter(self._formatter)
self._logger.addHandler(fh) self._logger.addHandler(fh)
default_name = 'admin'
default_parent = {"folder": [1]}
collection = Collection.find_collection(default_name, default_parent)
parent = {"folder": [collection.id]}
# create project folder
collection = Collection.create_collection(self.name, parent)
self.setup_collection(collection)
def setup_project(self, project): def setup_project(self, project):
for (key, value) in project.items(): for (key, value) in project.items():
@@ -79,6 +90,9 @@ class Project(threading.Thread):
complete_device = self._device_manager.get_device(mac_address) complete_device = self._device_manager.get_device(mac_address)
complete_device.occupied_by_project = self._uuid complete_device.occupied_by_project = self._uuid
self._complete_device[device] = complete_device self._complete_device[device] = complete_device
def setup_collection(self, collection):
self._task_manager.create_collection(collection)
@property @property
def id(self) -> int: def id(self) -> int:
+17 -1
View File
@@ -5,6 +5,7 @@ from xml.dom.expatbuilder import parseString
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from biopro.text import * from biopro.text import *
from .task import Task from .task import Task
from biopro.db.collection import Collection
_RUNTIME_COMPILE = False _RUNTIME_COMPILE = False
@@ -67,6 +68,13 @@ class TaskManager():
if cycle['range'][1] == task.uuid: if cycle['range'][1] == task.uuid:
return index return index
def check_task_in_cycle(self, task_index):
for index, cycle in enumerate(self._cycle_list):
if self.get_index_by_uuid(cycle['range'][0]) <= task_index:
if self.get_index_by_uuid(cycle['range'][1]) >= task_index:
return True
return False
@property @property
def check_list(self): def check_list(self):
return [self._running_task, *self._next_task] return [self._running_task, *self._next_task]
@@ -162,4 +170,12 @@ class TaskManager():
def get_task(self, task_id): def get_task(self, task_id):
return self._task_list[task_id] return self._task_list[task_id]
def create_collection(self, parent):
for index, task in enumerate(self._task_list):
if self.check_task_in_cycle(index) == True:
if task.type == '':
collection = Collection.create_collection(task.name, {"folder": [parent.id]})
task.parent = {"folder": [collection.id]}
else:
task.parent = {"folder": [parent.id]}
+8 -8
View File
@@ -362,14 +362,14 @@ class DataServer(SocketServer, DataAPI):
self.log_verbose('device ID', device_id) self.log_verbose('device ID', device_id)
# project binding meta file # project binding meta file
project_id = None # project_id = None
_project = None # _project = None
if project_info != None: # if project_info != None:
_project = json.loads(project_info) # _project = json.loads(project_info)
self.database_process.put_queue(['project_insert', device_id, _project]) # self.database_process.put_queue(['project_insert', device_id, _project])
result = self._queue_ds_dict[int(device_id)].get() # result = self._queue_ds_dict[int(device_id)].get()
if result[0] == 'project_id': # if result[0] == 'project_id':
project_id = result[1] project_id = project_info
# while len(self._configurations) <= device_id: # while len(self._configurations) <= device_id:
# self._configurationsappend(None) # self._configurationsappend(None)
+4 -2
View File
@@ -222,7 +222,8 @@ class DataBaseProcess(Process):
try: try:
sql_cursor.execute(sql_str, sql_set) sql_cursor.execute(sql_str, sql_set)
except: except BaseException as e:
print('meta create error', e)
self._psql_conn.commit() self._psql_conn.commit()
sql_cursor.close() sql_cursor.close()
self._queue_error.put(device_id) self._queue_error.put(device_id)
@@ -249,7 +250,8 @@ class DataBaseProcess(Process):
try: try:
sql_cursor.execute(sql_str, sql_set) sql_cursor.execute(sql_str, sql_set)
except: except BaseException as e:
print('meta update error', e)
self._psql_conn.commit() self._psql_conn.commit()
sql_cursor.close() sql_cursor.close()
self._queue_error.put(device_id) self._queue_error.put(device_id)
+5 -3
View File
@@ -1102,6 +1102,7 @@ class ControlServer(SocketServer, ControlServerAPI):
client = self.data_server.client() client = self.data_server.client()
project = None project = None
project_meta_id = None
if client is not None: if client is not None:
info = self.file_manager.use(device) info = self.file_manager.use(device)
@@ -1114,10 +1115,11 @@ class ControlServer(SocketServer, ControlServerAPI):
info = self.file_manager.save(device, filename) info = self.file_manager.save(device, filename)
if device.occupied_by_project != None: if device.occupied_by_project != None:
project = json.dumps(self.project_manager.get(device.occupied_by_project).info_pass_data_server()) project = self.project_manager.get(device.occupied_by_project).info_pass_data_server()
project_meta_id = MetaProjectInfo.create_project_meta(project)
with client: with client:
client.update_device_configuration(device, info.meta_file, value, project) client.update_device_configuration(device, info.meta_file, value, project_meta_id)
def _device_set_disable_cache(self, device: CompletedDevice, disable): def _device_set_disable_cache(self, device: CompletedDevice, disable):
if disable: if disable: