refactor(p1-06/07): daily_sales 純函數抽到 services/
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
- 新增 utils/df_helpers.py 放共用 find_col(避免 routes/services 雙向依賴) - 新增 services/daily_sales_service.py 收: * get_taiwan_holiday(date) * prepare_calendar_data(df, selected_month) * prepare_marketing_summary(df, ...) - routes/daily_sales_routes.py 改為 import service,行數 949 → 713(-236) - 行為 100% 保留,僅檔案位置搬移
This commit is contained in:
18
utils/df_helpers.py
Normal file
18
utils/df_helpers.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""DataFrame 共用工具 — 跨 routes/services 共享。"""
|
||||
|
||||
|
||||
def find_col(df_cols, keywords):
|
||||
"""從欄位列表中,根據關鍵字列表找出最匹配的欄位名稱。
|
||||
|
||||
Args:
|
||||
df_cols: DataFrame 的欄位名稱 iterable
|
||||
keywords: 關鍵字列表,依優先序
|
||||
|
||||
Returns:
|
||||
匹配的欄位名稱字串,找不到則回傳 None
|
||||
"""
|
||||
for k in keywords:
|
||||
for col in df_cols:
|
||||
if k in str(col):
|
||||
return col
|
||||
return None
|
||||
Reference in New Issue
Block a user