Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (49 loc) · 1.73 KB
/
Copy pathmain.py
File metadata and controls
63 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import os
import glob
from pathlib import Path
from src.config_manager import ConfigManager
from src.data_processor import DataProcessor
from src.data_plotter import DataPlotter
def get_latest_dat_file(raw_dir="data/raw"):
"""获取 raw 目录下最新的 dat 文件"""
files = glob.glob(os.path.join(raw_dir, "*.dat"))
if not files:
raise FileNotFoundError(f"目录 {raw_dir} 下没有找到任何 dat 文件")
return max(files, key=os.path.getmtime)
def main():
# ========== 输入文件 ==========
if len(sys.argv) >= 2:
input_file = sys.argv[1]
else:
input_file = get_latest_dat_file("data/raw")
print(f"未指定输入文件,默认使用最新文件: {input_file}")
# ========== 配置文件 ==========
config_file = sys.argv[2] if len(sys.argv) >= 3 else "config/data_config.yml"
# try:
config_manager = ConfigManager(config_file)
processor = DataProcessor(config_manager)
# 处理数据
df = processor.process(input_file)
input_path = Path(input_file)
if input_path.parent.name == "raw":
parent_path = input_path.parent.parent
else:
parent_path = input_path.parent
csv_path = parent_path / "processed"
csv_path.mkdir(exist_ok=True)
csv_out = input_path.stem + ".csv"
processor.save_csv(df, csv_path / csv_out)
# 绘图
if len(df) > 0:
fig_path = parent_path / "waves"
fig_path.mkdir(exist_ok=True)
fig_out = input_path.stem + ".png"
fig_out = fig_path / fig_out
plotter = DataPlotter(config_manager, fig_out)
plotter.plot(df)
# except Exception as e:
# print(f"错误: {e}")
# sys.exit(1)
if __name__ == "__main__":
main()