returnResult.error(message="level0 data [%s]not found"%(level0_id))
sql_data=f"select * from ifs_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time >= '{level0_data.data.obs_time}' order by obs_time ASC limit 1"
r=self.db.select_one(sql_data)
ifr:
rec=CalMergeRecord().from_dict(r)
returnResult.ok_data(data=rec)
sql_data=f"select * from ifs_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time <= '{level0_data.data.obs_time}' order by obs_time DESC limit 1"
r=self.db.select_one(sql_data)
ifr:
rec=CalMergeRecord().from_dict(r)
returnResult.ok_data(data=rec)
returnResult.error(message="not found")
exceptExceptionase:
returnResult.error(message=str(e))
deffind(self,**kwargs):
''' retrieve calibration merge records from database
parameter kwargs:
detector_no: [str]
ref_type: [str]
obs_time: (start,end)
qc1_status : [int]
prc_status : [int]
file_name: [str]
limit: limits returns the number of records,default 0:no-limit
returnResult.error(message="level0 data [%s]not found"%(level0_id))
returnResult.error(message="level0 data [%s]not found"%(level0_id))
sql_data=f"select * from t_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time >= '{level0_data.data.obs_time}' order by obs_time ASC limit 1"
sql_data=f"select * from msc_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time >= '{level0_data.data.obs_time}' order by obs_time ASC limit 1"
r=self.db.select_one(sql_data)
r=self.db.select_one(sql_data)
ifr:
ifr:
rec=CalMergeRecord().from_dict(r)
rec=CalMergeRecord().from_dict(r)
returnResult.ok_data(data=rec)
returnResult.ok_data(data=rec)
sql_data=f"select * from t_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time <= '{level0_data.data.obs_time}' order by obs_time DESC limit 1"
sql_data=f"select * from msc_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time <= '{level0_data.data.obs_time}' order by obs_time DESC limit 1"
r=self.db.select_one(sql_data)
r=self.db.select_one(sql_data)
ifr:
ifr:
...
@@ -78,8 +79,8 @@ class CalMergeApi(object):
...
@@ -78,8 +79,8 @@ class CalMergeApi(object):
file_name=get_parameter(kwargs,"file_name")
file_name=get_parameter(kwargs,"file_name")
limit=get_parameter(kwargs,"limit",0)
limit=get_parameter(kwargs,"limit",0)
sql_count="select count(*) as c from t_cal_merge where 1=1"
sql_count="select count(*) as c from msc_cal_merge where 1=1"
sql_data=f"select * from t_cal_merge where 1=1"
sql_data=f"select * from msc_cal_merge where 1=1"
sql_condition=""
sql_condition=""
ifdetector_no:
ifdetector_no:
...
@@ -138,10 +139,10 @@ class CalMergeApi(object):
...
@@ -138,10 +139,10 @@ class CalMergeApi(object):
defget_by_id(self,id:str):
defget_by_id(self,id:str):
try:
try:
r=self.db.select_one(
r=self.db.select_one(
"select * from t_cal_merge where id=?",(id,))
"select * from msc_cal_merge where id=?",(id,))
ifr:
ifr:
sql_get_level0_id=f"select level0_id from t_cal2level0 where merge_id={r['id']}"
sql_get_level0_id=f"select level0_id from msc_cal2level0 where merge_id={r['id']}"
_,records=self.db.select_many(sql_get_level0_id)
_,records=self.db.select_many(sql_get_level0_id)
level0_ids=[r["level0_id"]forrinrecords]
level0_ids=[r["level0_id"]forrinrecords]
...
@@ -158,10 +159,10 @@ class CalMergeApi(object):
...
@@ -158,10 +159,10 @@ class CalMergeApi(object):
defget_by_cal_id(self,cal_id:str):
defget_by_cal_id(self,cal_id:str):
try:
try:
r=self.db.select_one(
r=self.db.select_one(
"select * from t_cal_merge where cal_id=?",(cal_id,))
"select * from msc_cal_merge where cal_id=?",(cal_id,))
ifr:
ifr:
sql_get_level0_id=f"select level0_id from t_cal2level0 where merge_id={r['id']}"
sql_get_level0_id=f"select level0_id from msc_cal2level0 where merge_id={r['id']}"
_,records=self.db.select_many(sql_get_level0_id)
_,records=self.db.select_many(sql_get_level0_id)
level0_ids=[r["level0_id"]forrinrecords]
level0_ids=[r["level0_id"]forrinrecords]
...
@@ -197,7 +198,7 @@ class CalMergeApi(object):
...
@@ -197,7 +198,7 @@ class CalMergeApi(object):
try:
try:
self.db.execute(
self.db.execute(
'update t_cal_merge set qc1_status=?, qc1_time=? where id=?',
'update msc_cal_merge set qc1_status=?, qc1_time=? where id=?',
(status,format_time_ms(time.time()),id)
(status,format_time_ms(time.time()),id)
)
)
self.db.end()
self.db.end()
...
@@ -229,14 +230,14 @@ class CalMergeApi(object):
...
@@ -229,14 +230,14 @@ class CalMergeApi(object):
try:
try:
existed=self.db.exists(
existed=self.db.exists(
"select * from t_cal_merge where id=?",
"select * from msc_cal_merge where id=?",
(id,)
(id,)
)
)
ifnotexisted:
ifnotexisted:
log.warning('%s not found'%(id,))
log.warning('%s not found'%(id,))
returnResult.error(message='%s not found'%(id,))
returnResult.error(message='%s not found'%(id,))
self.db.execute(
self.db.execute(
'update t_cal_merge set prc_status=?, prc_time=? where id=?',
'update msc_cal_merge set prc_status=?, prc_time=? where id=?',
(status,format_time_ms(time.time()),id)
(status,format_time_ms(time.time()),id)
)
)
self.db.end()
self.db.end()
...
@@ -278,14 +279,14 @@ class CalMergeApi(object):
...
@@ -278,14 +279,14 @@ class CalMergeApi(object):
)
)
try:
try:
self.db.execute(
self.db.execute(
'INSERT INTO t_cal_merge (cal_id,detector_no,ref_type,obs_time,exp_time,filename,file_path,prc_status,prc_time,create_time) \
'INSERT INTO msc_cal_merge (cal_id,detector_no,ref_type,obs_time,exp_time,filename,file_path,prc_status,prc_time,create_time) \
returnResult.error(message="level0 data [%s]not found"%(level0_id))
sql_data=f"select * from sls_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time >= '{level0_data.data.obs_time}' order by obs_time ASC limit 1"
r=self.db.select_one(sql_data)
ifr:
rec=CalMergeRecord().from_dict(r)
returnResult.ok_data(data=rec)
sql_data=f"select * from sls_cal_merge where detector_no='{level0_data.data.detector_no}' and ref_type='{ref_type}' and obs_time <= '{level0_data.data.obs_time}' order by obs_time DESC limit 1"
r=self.db.select_one(sql_data)
ifr:
rec=CalMergeRecord().from_dict(r)
returnResult.ok_data(data=rec)
returnResult.error(message="not found")
exceptExceptionase:
returnResult.error(message=str(e))
deffind(self,**kwargs):
''' retrieve calibration merge records from database
parameter kwargs:
detector_no: [str]
ref_type: [str]
obs_time: (start,end)
qc1_status : [int]
prc_status : [int]
file_name: [str]
limit: limits returns the number of records,default 0:no-limit