From faa25a85c10aa0fa2df824318a4bfa542f6a5a46 Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期二, 20 一月 2026 13:26:55 +0800
Subject: [PATCH] feat(services): 添加主流程服务并重构时间处理逻辑

---
 app/services/data_processing_service.py |   47 +++++++++++++++--------------------------------
 1 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/app/services/data_processing_service.py b/app/services/data_processing_service.py
index 5a2d3aa..3a7bc05 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}")

--
Gitblit v1.9.3