parent
d0bf3e328b
commit
893cd1f11d
@ -0,0 +1,109 @@ |
||||
import numpy as np |
||||
from myconfig import OUTPUT_DIR |
||||
from tools.mylogger import log |
||||
from pathlib import Path |
||||
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, ): |
||||
''' |
||||
一个文件包含 Esky .....Rs 五组数据 |
||||
获得csv文件,转移不同的行到不同文件 |
||||
第一列要转为时间 |
||||
''' |
||||
# ret = [] |
||||
fs = None |
||||
self.filelist = [] |
||||
fs = self.dir.glob( "*/*/*/*.csv" ) |
||||
for f in fs: |
||||
print(f) |
||||
tmp = np.loadtxt( fs, dtype=str, delimiter=';',skiprows=1 ) |
||||
self.addNdarray2File(tmp[0]) |
||||
|
||||
def addNdarray2File( self, data:np.ndarray ): |
||||
pass |
||||
|
||||
|
||||
# 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_handheld() |
||||
|
Loading…
Reference in new issue