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

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