From 456ea8e67472d4f0609cd1172c54fb230bdc4507 Mon Sep 17 00:00:00 2001 From: esea_info Date: Wed, 19 Apr 2023 18:22:41 +0800 Subject: [PATCH] bugfix dealserver output_path --- Ramses.py | 46 ++++++++++++++++++++-------------------------- awrams.py | 34 ++++++++++++++++++++++++++-------- tools/mypath.py | 5 ++--- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Ramses.py b/Ramses.py index 505ef71..adeff13 100644 --- a/Ramses.py +++ b/Ramses.py @@ -26,17 +26,16 @@ class Ramses(object): @param : 23 ..07 .... 06 05 04 03 02 01 00 ip信息不包含 @Returns : realWavelength Intensity - @ 积分时间 04 07 , 选 07 + @ 积分时间 04 07 ,后一位高位, 选 07 """ - self.buf = b'' - self.mode = 0 # 默认0 空气中,1:水中 - self.buf_ip = b'' - self.it = None - self.light_int = None # 未标定的整数值 - self.spectrum = None # 光谱强度 - self.ip = [] - self.cal_cfg = {} # 单个传感器标定文件还是多个传感器的? - # self.current_cal = {} # 当前传感器的序列号 + self.mode = 0 # 默认0 空气中,1:水中 + self.buf = b'' + self.buf_ip = b'' + self.it = None + self.light_int = None # 未标定的整数值 + self.spectrum = None # 光谱强度 + self.ip = [] + self.cal_cfg = {} # 单个传感器标定文件还是多个传感器的? pass def setBuf( self, buf: bytes ): @@ -74,15 +73,7 @@ class Ramses(object): self.spectrum = None # 光谱强度 pass - def printPara(self, ): - print(f"**************Ramses printPara*******************") - print(f"{self.buf}") - print(f"{self.cal_cfg}") - print(f"{self.it}") - print(f"{self.light_int}") - print(f"{self.spectrum}") - print(f"**************Ramses printPara*******************") - pass + def dealBuf(self, ip_included:bool=False): """ @@ -110,10 +101,6 @@ class Ramses(object): self.buf[295:359] + self.buf[367:431] + \ self.buf[439:503] + self.buf[511:575] self.ConvertAndCalibrate( temp_buf ) - # print(len(temp_buf)) - # temp = self.__ConvertBytesToInt(temp_buf) - # res.update( { i+1: temp } ) - # print(res) pass def ConvertAndCalibrate(self,) -> None: @@ -126,9 +113,7 @@ class Ramses(object): # 转换一个传感器的部分 def __ConvertBytesToInt(self ) -> None: - res = {} - d = [] # List [ Tuple[ it:int, sing_set:tuple[int] ] ] - + self.it = 2 << int(self.buf[1]) # integrated time # self.it = 2 << int(self.buf[0]) # integrated time @@ -259,6 +244,15 @@ class Ramses(object): return ret pass + def printPara(self, ): + print(f"**************Ramses printPara*******************") + print(f"{self.buf}") + print(f"{self.cal_cfg}") + print(f"{self.it}") + print(f"{self.light_int}") + print(f"{self.spectrum}") + print(f"**************Ramses printPara*******************") + pass if __name__ == "__main__": log.info(f"******** Awarms server initiate *********", __name__, "", "") diff --git a/awrams.py b/awrams.py index 4a63604..b418894 100644 --- a/awrams.py +++ b/awrams.py @@ -496,7 +496,7 @@ class AWRAMS(object): except: log.error( f"处理信息文件" + "/" +self.info_path_fname.stem - + "出现错误", __name__, "dealAllMeasurements" ) + + "出现错误", __name__, "dealAllMeasurements_Server" ) raise MyException( "处理文件"+ self.info_path_fname + "出现错误") pass @@ -522,15 +522,16 @@ class AWRAMS(object): self.get_ymdhms() # get Lw Rs self.getLwRs() + # 设置保存路径 self.output_path + self.get_save_csv_path() # 保存 data info self.saveOnefileForLskyEskyLwaterLwRS() # 通知ui self.__set_msg("data", {"tm":self.ymdhms, "res":self.res} ) pub.sendMessage("update" , msg=self.msg) - - self.__set_msg('notice', '处理文件完成') - pub.sendMessage('update' , msg=self.msg) + self.__set_msg( 'notice', '处理文件完成' ) + pub.sendMessage( 'update' , msg=self.msg ) log.info(f"Finished !! ", __name__, "dealAllMeasurements") # return True,self.error_result pass @@ -582,10 +583,26 @@ class AWRAMS(object): + f"{self.info_dict['hour']:02d}" + '_' \ + f"{self.info_dict['minute']:02d}" + '_' \ + f"{self.info_dict['second']:02d}" + # self.output_path = self.output_path.joinpath( self.ymdhms ) + # print(self.output_path) + # time.sleep(30)save_csv_path + + def get_save_csv_path(self, ): + if self.mode == 0: + self.mydir.setBaseDir(DATA_DIR) + else: + self.mydir.setBaseDir(SERVER_DIR) + dir_tuple = ( "output", self.info_dict['year'],self.info_dict['month'],self.info_dict['day']) + self.mydir.setDir( t = dir_tuple) + self.mydir.newDirIfNot() + self.mydir.newFileIfNot( self.ymdhms+SAVE_EXT_NAME) + self.output_path = self.mydir.current_filepath + # self.output_path = self.output_path.joinpath( self.ymdhms ) # print(self.output_path) # time.sleep(30) + def decode_sensor_buf(self,) : # 处理Buf,对多组数据取平均 self.intensity_before_avg = [] @@ -824,8 +841,7 @@ class AWRAMS(object): self.res.update({ "Lw" : Lw }) Rs = self.res["Lw"] / self.res["Esky"] self.res.update({ "Rs" : Rs }) - - + def getLwRsAndSave(self, ) -> bool: """ 并计算Lw Rs并保存 @@ -872,8 +888,10 @@ class AWRAMS(object): except Exception as e: return ret log.debug(temp,__name__,"decode_info") - time_ = "20"+str(temp[0]) + "-" + str(temp[1]) + "-" + str(temp[2]) + " " \ - + str(temp[3]) + ":" + str(temp[4]) + ":" + str(temp[5]) + # time_ = "20"+str(temp[0]) + "-" + str(temp[1]) + "-" + str(temp[2]) + " " \ + # + str(temp[3]) + ":" + str(temp[4]) + ":" + str(temp[5]) + time_ = "20" + f"{str(temp[0])}" + "-" + f"{str(temp[1])}" + "-" + f"{str(temp[2])}" + " " \ + + f"{str(temp[3])}" + ":" + f"{str(temp[4])}" + ":" + f"{str(temp[5])}" ret.update({"time": time_}) ret.update({"year": temp[0]}) ret.update({"month": temp[1]}) diff --git a/tools/mypath.py b/tools/mypath.py index b8f1064..3bb32d9 100644 --- a/tools/mypath.py +++ b/tools/mypath.py @@ -30,6 +30,7 @@ class MyDir(object): pass def setDir(self, t:tuple=()): + ''' set''' self.dir_tuple = t if len(self.dir_tuple) == 0 : self.current_dir = self.base_dir @@ -167,7 +168,7 @@ class MyDir(object): '''fmt: * */* */*/*''' ret = [] tmp_dir = self.current_dir.glob(fmt) - print(tmp_dir) + # print(tmp_dir) for td in tmp_dir: if td.is_file(): ret.append(td) @@ -228,8 +229,6 @@ class MyDir(object): # dirs_lst.sort() - - def check_dirs(self, dirs:list, begin:int =0, step:int=1): '''检查目录是否从begin开始递增''' len_dirs = len(dirs)