更新 html的解析中 对于 cell 的解析,excel的处理中对于cell 的解析。以及温度处理中 对于 数据的处理增加 时间戳的换算。
This commit is contained in:
@@ -27,10 +27,10 @@ class TemperatureDataAnalyzer:
|
||||
# 常见中文字体候选(跨平台)
|
||||
candidates = [
|
||||
"Microsoft YaHei", "Microsoft YaHei UI", # Windows
|
||||
"SimHei", "SimSun", # Windows(黑体/宋体)
|
||||
"PingFang SC", "Heiti SC", # macOS
|
||||
"SimHei", "SimSun", # Windows(黑体/宋体)
|
||||
"PingFang SC", "Heiti SC", # macOS
|
||||
"Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", # Linux
|
||||
"Arial Unicode MS" # 覆盖广的 Unicode 字体
|
||||
"Arial Unicode MS" # 覆盖广的 Unicode 字体
|
||||
]
|
||||
available = {f.name for f in font_manager.fontManager.ttflist}
|
||||
for name in candidates:
|
||||
@@ -60,7 +60,7 @@ class TemperatureDataAnalyzer:
|
||||
return True
|
||||
|
||||
def load_and_process_data(self):
|
||||
"""加载和处理数据"""
|
||||
"""加载和处理数据,并保存带时间戳的新文件"""
|
||||
try:
|
||||
# 读取CSV文件,无表头
|
||||
self.data = pd.read_csv(self.file_path, header=None)
|
||||
@@ -71,6 +71,19 @@ class TemperatureDataAnalyzer:
|
||||
# 转换时间戳格式(文本例如:10/29/2025 2:20:41 PM)
|
||||
self.data['datetime'] = pd.to_datetime(self.data['timestamp'], format='%m/%d/%Y %I:%M:%S %p')
|
||||
|
||||
# 将转换后的datetime对象存储到D列(原数据只有3列,所以新增第4列)
|
||||
self.data['converted_timestamp'] = self.data['datetime']
|
||||
|
||||
|
||||
# 新增第5列:存储转换后的时间戳( UTC的时间戳,精确到ms)
|
||||
# self.data['utc_timestamp_ms'] = (self.data['datetime'].astype('int64') // 10**6)
|
||||
self.data['utc_timestamp_ms'] = (self.data['datetime'].astype('int64') // 10**9)
|
||||
|
||||
|
||||
|
||||
# 保存带时间戳的新CSV文件
|
||||
self._save_csv_with_timestamp()
|
||||
|
||||
# 提取处理后的数据
|
||||
self.timestamps = self.data['datetime']
|
||||
self.temperatures = self.data['temperature']
|
||||
@@ -83,6 +96,28 @@ class TemperatureDataAnalyzer:
|
||||
print(f"数据处理错误: {e}")
|
||||
return False
|
||||
|
||||
def _save_csv_with_timestamp(self):
|
||||
"""保存带时间戳的新CSV文件"""
|
||||
try:
|
||||
# 生成新文件名(原文件名+时间戳)
|
||||
base_filename = os.path.splitext(os.path.basename(self.file_path))[0]
|
||||
timestamp_str = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
output_filename = f"{base_filename}_with_timestamp_{timestamp_str}.csv"
|
||||
output_dir = os.path.dirname(self.file_path)
|
||||
output_path = os.path.join(output_dir, output_filename)
|
||||
|
||||
# # 选择需要保存的列:原始三列 + 转换后的时间戳列
|
||||
# columns_to_save = ['timestamp', 'temperature', 'status', 'converted_timestamp']
|
||||
# 选择需要保存的列:原始三列 + 转换后的时间戳列 + 格式化时间戳列
|
||||
columns_to_save = ['timestamp', 'temperature', 'status', 'converted_timestamp', 'utc_timestamp_ms']
|
||||
|
||||
self.data[columns_to_save].to_csv(output_path, index=False, header=False)
|
||||
|
||||
print(f"已保存带时间戳的新CSV文件: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"保存带时间戳CSV文件时出错: {e}")
|
||||
|
||||
def create_scatter_plots(self):
|
||||
"""创建散点图"""
|
||||
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10))
|
||||
|
||||
Reference in New Issue
Block a user