receive.py year month day

server
esea_info 3 years ago
parent 834a2ac707
commit ea9338cac9
  1. 122
      receive.py
  2. 14
      tcp_awrams.py

@ -207,65 +207,65 @@ class DealData:
# self.awrams.readOneFolder( )
@staticmethod
def deal2(id: int, con: int) -> None: # 取字典中的 payload
log.info(f" 修改目录为时间格式,并处理 device_id: {id}, measure_con: {con} ")
src_dir = DATA_DIR.joinpath( str(id), str(con) )
bin_file_list = src_dir.glob( '*.bin' )
info_frame= DealData.read_bin( src_dir.joinpath('info.bin') )
if info_frame == None:
raise MyException("处理数据时,信息帧读取数据为空")
info_dict:dict= DealData.decode_info(info_frame)
if info_dict =={}:
raise MyException("从文件读取信息帧后,解析信息帧遇到异常")
# id/year/month/day/con
dst_dir = DATA_DIR.joinpath("20"+str(info_dict["year"]), str(info_dict["month"]),str(info_dict["day"]), str(con))
log.info( f"dst_dir: {dst_dir}")
if dst_dir.exists() == False:
dst_dir.mkdir(parents=True)
# 保存info_dict到新的目录
DealData.save_dict_to_file(info_dict, dst_dir.joinpath(
"info_20"+str(info_dict["year"])
+str(info_dict["month"])+"_"
+str(info_dict["day"])+"_"
+str(info_dict["hour"])+"_"
+str(info_dict["minute"])+"_"
+str(info_dict["second"])+"_"
+".txt"))
log.info(f" Src File path: {bin_file_list}" )
# 将bin文件存到新的目录
for bfl in bin_file_list:
fname_without_path= bfl.name
new_path = None
if fname_without_path == "pic.bin":
new_path = dst_dir.joinpath("pic.jpg" )
else:
new_path= dst_dir.joinpath( fname_without_path )
bfl.replace(new_path )
# shutil.move( bfl, new_path )
pass
# 判断目录是否为空,删除旧的目录
flist = src_dir.glob('*.*')
try:
next(flist)
log.warning(" 旧的文件夹还存在文件,不能删除,请仔细检测! ")
raise MyException("旧的文件夹还存在文件,不能删除,请仔细检测!")
except StopIteration:
src_dir.rmdir()
if DealData.check_spectrum_data(dst_dir):
log.warning(" 目录光谱数据有异常 ")
raise MyException(f"{dst_dir} 目录光谱数据有异常")
pass
DealData.calibrate_spectrum_data(dst_dir)
DealData.retrieve_data(dst_dir)
# @staticmethod
# def deal2(id: int, con: int) -> None: # 取字典中的 payload
# log.info(f" 修改目录为时间格式,并处理 device_id: {id}, measure_con: {con} ")
# src_dir = DATA_DIR.joinpath( str(id), str(con) )
# bin_file_list = src_dir.glob( '*.bin' )
# info_frame= DealData.read_bin( src_dir.joinpath('info.bin') )
# if info_frame == None:
# raise MyException("处理数据时,信息帧读取数据为空")
# info_dict:dict= DealData.decode_info(info_frame)
# if info_dict =={}:
# raise MyException("从文件读取信息帧后,解析信息帧遇到异常")
# # id/year/month/day/con
# dst_dir = DATA_DIR.joinpath("20"+str(info_dict["year"]), str(info_dict["month"]),str(info_dict["day"]), str(con))
# log.info( f"dst_dir: {dst_dir}")
# if dst_dir.exists() == False:
# dst_dir.mkdir(parents=True)
# # 保存info_dict到新的目录
# DealData.save_dict_to_file(info_dict, dst_dir.joinpath(
# "info_20"+str(info_dict["year"])
# +str(info_dict["month"])+"_"
# +str(info_dict["day"])+"_"
# +str(info_dict["hour"])+"_"
# +str(info_dict["minute"])+"_"
# +str(info_dict["second"])+"_"
# +".txt"))
# log.info(f" Src File path: {bin_file_list}" )
# # 将bin文件存到新的目录
# for bfl in bin_file_list:
# fname_without_path= bfl.name
# new_path = None
# if fname_without_path == "pic.bin":
# new_path = dst_dir.joinpath("pic.jpg" )
# else:
# new_path= dst_dir.joinpath( fname_without_path )
# bfl.replace(new_path )
# # shutil.move( bfl, new_path )
# pass
# # 判断目录是否为空,删除旧的目录
# flist = src_dir.glob('*.*')
# try:
# next(flist)
# log.warning(" 旧的文件夹还存在文件,不能删除,请仔细检测! ")
# raise MyException("旧的文件夹还存在文件,不能删除,请仔细检测!")
# except StopIteration:
# src_dir.rmdir()
# if DealData.check_spectrum_data(dst_dir):
# log.warning(" 目录光谱数据有异常 ")
# raise MyException(f"{dst_dir} 目录光谱数据有异常")
# pass
# DealData.calibrate_spectrum_data(dst_dir)
# DealData.retrieve_data(dst_dir)
@staticmethod
def read_bin(fpath:Path):
@ -288,8 +288,8 @@ class DealData:
except Exception as e:
log.info( "decode info 有误, 收到info frame 字节有误" )
return ret
time_ = "20"+str(temp[0]) + "-" + str(temp[1]) + "-" + str(temp[2]) + " " \
+ str(temp[3]) + ":" + str(temp[4]) + ":" + str(temp[5])
time_ = "20"+f"{temp[0]:02d}" + "-" + f"{temp[1]:02d}" + "-" + f"{temp[2]:02d}" + " " \
+ f"{temp[3]:02d}" + ":" + f"{temp[4]:02d}" + ":" + f"{temp[5]:02d}"
ret.update({"time": time_})
ret.update({"year": temp[0]})
ret.update({"month": temp[1]})

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save