年月日 位数

desktop
esea_info 3 years ago
parent 7ffa190093
commit 1f8e29f7c1
  1. 35
      awrams.py
  2. 138
      gatherdata.py

@ -471,12 +471,13 @@ class AWRAMS(object):
self.output_path = OUTPUT_DIR
self.current_filepath = fpath
self.current_measure_time = self.hhp.getCurrentMeasureTimeFromPath(fpath)
self.ymdhms = "20"+ str(self.info_dict['year']) + '_' \
+ str(self.info_dict['month']) + '_' \
+ str(self.info_dict['day']) + '_' \
+ str(self.info_dict['hour']) + '_' \
+ str(self.info_dict['minute']) + '_' \
+ str(self.info_dict['second'])
self.get_ymdhms()
# self.ymdhms = "20"+ str(self.info_dict['year']) + '_' \
# + str(self.info_dict['month']) + '_' \
# + str(self.info_dict['day']) + '_' \
# + str(self.info_dict['hour']) + '_' \
# + str(self.info_dict['minute']) + '_' \
# + str(self.info_dict['second'])
self.output_path = self.output_path.joinpath( self.ymdhms )
log.debug(f"current_measure_time: {self.current_measure_time}", __name__, "dealOneMeasurement")
# 读取buf
@ -500,12 +501,12 @@ class AWRAMS(object):
pub.sendMessage("update" , msg=self.msg)
def get_ymdhms(self, ):
self.ymdhms = "20"+ str(self.info_dict['year']) + '_' \
+ str(self.info_dict['month']) + '_' \
+ str(self.info_dict['day']) + '_' \
+ str(self.info_dict['hour']) + '_' \
+ str(self.info_dict['minute']) + '_' \
+ str(self.info_dict['second'])
self.ymdhms = "20"+ f"{self.info_dict['year']:02d}" + '_' \
+ f"{self.info_dict['month']:02d}" + '_' \
+ f"{self.info_dict['day']:02d}" + '_' \
+ 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)
@ -564,9 +565,13 @@ class AWRAMS(object):
def saveOnefileForLskyEskyLwaterLwRS(self, ) -> bool:
log.info(f" ", __name__, "saveOnefileForLskyEskyLwaterLwRS")
self.mydir.setBaseDir(self.output_path) #基路径
year = "20"+ f"{self.info_dict['year']:02d}"
month = f"{self.info_dict['month']:02d}"
day = f"{self.info_dict['day']:02d}"
save_path = OUTPUT_DIR.joinpath(year,month,day)
self.mydir.setBaseDir(save_path) #基路径
self.mydir.newDirIfNot()
self.mydir.newFileIfNot("data" + SAVE_EXT_NAME)
self.mydir.newFileIfNot(self.ymdhms + SAVE_EXT_NAME)
self.mydir.setHeader( self.wavelength.tolist(), TOKEN, "device_id_"+str(self.device_id) )
header = self.mydir.header_str
@ -579,7 +584,7 @@ class AWRAMS(object):
save_path_csv.write_text(header+data_str)
# info.txt
self.mydir.newFileIfNot("info.txt")
self.mydir.newFileIfNot(self.ymdhms+"_info.txt")
path_info_txt:Path = self.mydir.current_filepath
self.save_dict_to_file( self.info_dict, path_info_txt )

@ -0,0 +1,138 @@
import numpy as np
from myconfig import DATA_DIR,OUTPUT_DIR
from tools.mylogger import log
from pathlib import Path
import time
# from handheld import HandHeldPath
class GatherData(object):
"""对数据进行汇总后分析 csv"""
def __init__(self, ):
super(GatherData, self).__init__()
self.dir = OUTPUT_DIR
self.extname = ".csv"
def setDir(self, fpath):
self.dir = fpath
pass
def setExtname(self, extname):
self.extname = extname
pass
def getChildDirs(self, ):
'''
按时间排放每个目录下有五个文件 Esky....Rs
文件直接保存到 output下的五个文件 Esky ..... Rs
'''
childdirs = []
for path in Path(self.dir).iterdir():
# if path.is_dir():
# print(path)
if not path.is_dir():
continue
childdirs.append(path)
return childdirs
pass
def gather_handheld(self, ):
log.info(f" ",__name__,'gather_handheld')
childDirs = self.getChildDirs()
for cdir in childDirs:
tmp_path:Path = cdir.joinpath("Lw"+self.extname)
self.transfer_data(tmp_path)
tmp_path:Path = cdir.joinpath("Rs"+self.extname)
self.transfer_data(tmp_path)
pass
def transfer_data(self, fpath:Path):
log.info(f" ",__name__,'transfer_data')
log.info(fpath)
old_path:Path = fpath
new_path:Path = self.dir.joinpath( old_path.stem + self.extname)
if not new_path.exists():
new_path.touch()
if old_path.exists():
count = 0
with open( new_path, "a" ) as fnew:
with open( old_path, "r" ) as f:
while True:
line = f.readline()
if not line :
break
if count != 0:
fnew.write(line)
count+=1
def gather_awrams(self, ):
'''
一个文件data.csv包含 Esky .....Rs 五组数据
获得csv文件,转移不同的行到不同文件
第一列要转为时间
'''
log.info(f" ",__name__,'gather_awrams')
fs = None
self.filelist = []
fs = self.dir.glob( "*/*/*/*.csv" )
for f in fs:
# print(f)
with open(f, 'r') as fhandle:
while True:
line = fhandle.readline()
if not line:
break
self.addLine2File(f.stem, line)
pass
def addLine2File( self, fname, line:str ):
log.info(f"+++++ {fname} -- {line}",__name__,'addLine2File')
tm = fname[0:4] +"-"+ fname[5:7] +"-"+ fname[8:10] +" "+fname[11:13] +":"+fname[14:16] +":"+fname[17:19]
func = "Lw"
if line.startswith(func+";"):
log.info(f"===== Lw")
tmp_str = tm +line[len(func):]
self.save_str_by_func(tmp_str,func)
func = "Rs"
if line.startswith(func+";"):
log.info(f"===== Rs")
tmp_str = tm +line[len(func):]
self.save_str_by_func(tmp_str,func)
pass
def save_str_by_func(self, str, func):
log.info(f" {func} -- {str}",__name__,'save_str_by_func')
savepath = OUTPUT_DIR
save_fname= savepath.joinpath(func + self.extname)
if not save_fname.exists():
save_fname.touch()
with open(save_fname,"a") as fhandle:
fhandle.write(str)
# def transfer_line_without_firstline(self, oldpath:Path, newPath:Path):
# count = 0
# with open( newPath, "a" ) as fnew:
# with open( oldpath, "r" ) as f:
# line = f.readline()
# if count != 0:
# fnew.write(line)
# pass
# pass
def getFileList_awrams(self, ):
'''
一个文件包含 Esky .....Rs 五组数据
获得csv文件,转移不同的行到不同文件
'''
# ret = []
fs = None
self.filelist = []
fs = self.dir.glob( "*/*.csv" )
pass
if __name__ == "__main__":
gd = GatherData()
gd.gather_awrams()
Loading…
Cancel
Save