From 6628f663b636675bcaea316f2deaddf337de480e Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期五, 13 三月 2026 10:23:31 +0800
Subject: [PATCH] feat(米重分析): 新增稳态识别和预测功能页面并优化现有模型
---
app/services/data_processing_service.py | 56 ++++++++++++++++++++------------------------------------
1 files changed, 20 insertions(+), 36 deletions(-)
diff --git a/app/services/data_processing_service.py b/app/services/data_processing_service.py
index 5a2d3aa..6adee4b 100644
--- a/app/services/data_processing_service.py
+++ b/app/services/data_processing_service.py
@@ -18,24 +18,15 @@
# 澶勭悊缂哄け鍊�
cleaned_df = cleaned_df.fillna(0)
- # 纭繚鏁版嵁绫诲瀷姝g‘
- cleaned_df['count_under'] = cleaned_df['count_under'].astype(int)
- cleaned_df['count_in_range'] = cleaned_df['count_in_range'].astype(int)
- cleaned_df['count_over'] = cleaned_df['count_over'].astype(int)
+ # 纭繚鏁版嵁绫诲瀷姝g‘锛堜粎褰撳垪瀛樺湪鏃讹級
+ for col in ['count_under', 'count_in_range', 'count_over']:
+ if col in cleaned_df.columns:
+ cleaned_df[col] = cleaned_df[col].astype(int)
# 纭繚time鏄痙atetime绫诲瀷骞跺鐞嗘椂鍖�
if 'time' in cleaned_df.columns:
# 杞崲涓篸atetime绫诲瀷
cleaned_df['time'] = pd.to_datetime(cleaned_df['time'])
-
- # 澶勭悊鏃跺尯
- # 妫�鏌ユ槸鍚﹀凡缁忔湁鏃跺尯淇℃伅
- if cleaned_df['time'].dt.tz is None:
- # 濡傛灉娌℃湁鏃跺尯淇℃伅锛屽亣璁炬槸UTC鏃堕棿骞舵坊鍔犳椂鍖�
- cleaned_df['time'] = cleaned_df['time'].dt.tz_localize('UTC')
-
- # 杞崲涓轰笂娴锋椂鍖猴紙UTC+8锛�
- cleaned_df['time'] = cleaned_df['time'].dt.tz_convert('Asia/Shanghai')
return cleaned_df
except Exception as e:
@@ -53,26 +44,18 @@
try:
stats = {
- 'total_records': len(df),
- 'count_under': {
- 'mean': df['count_under'].mean(),
- 'sum': df['count_under'].sum(),
- 'max': df['count_under'].max(),
- 'min': df['count_under'].min()
- },
- 'count_in_range': {
- 'mean': df['count_in_range'].mean(),
- 'sum': df['count_in_range'].sum(),
- 'max': df['count_in_range'].max(),
- 'min': df['count_in_range'].min()
- },
- 'count_over': {
- 'mean': df['count_over'].mean(),
- 'sum': df['count_over'].sum(),
- 'max': df['count_over'].max(),
- 'min': df['count_over'].min()
- }
+ 'total_records': len(df)
}
+
+ # 浠呭綋鍒楀瓨鍦ㄦ椂璁$畻缁熻淇℃伅
+ for col in ['count_under', 'count_in_range', 'count_over']:
+ if col in df.columns:
+ stats[col] = {
+ 'mean': df[col].mean(),
+ 'sum': df[col].sum(),
+ 'max': df[col].max(),
+ 'min': df[col].min()
+ }
return stats
except Exception as e:
print(f"璁$畻缁熻淇℃伅澶辫触: {e}")
@@ -228,20 +211,21 @@
try:
# 璇嗗埆鏋佸�肩偣
extreme_points = self.identify_local_maxima(df)
-
+ # print("璇嗗埆鏋佸�肩偣:", extreme_points)
# 璇嗗埆闃舵鏈�澶у��
- phase_maxima = self.identify_phase_maxima(df)
+ # phase_maxima = self.identify_phase_maxima(df)
+ # print("璇嗗埆闃舵鏈�澶у��:", phase_maxima)
# 璁$畻姣忎釜鏋佸�肩偣鐨勫悎鏍肩巼
if not extreme_points.empty:
extreme_points['pass_rate'] = extreme_points.apply(self.calculate_pass_rate, axis=1)
# 璁$畻鏁翠綋鍚堟牸鐜�
- overall_pass_rate = self.calculate_overall_pass_rate(df)
+ overall_pass_rate = self.calculate_overall_pass_rate(extreme_points)
return {
'extreme_points': extreme_points,
- 'phase_maxima': phase_maxima,
+ 'phase_maxima': pd.DataFrame(),
'overall_pass_rate': overall_pass_rate
}
except Exception as e:
--
Gitblit v1.9.3