後端代碼清理:移除冗餘註解和調試代碼

清理內容:
- 移除所有開發元資訊(Author, Version, DocID, Rationale等)
- 刪除註解掉的代碼片段(力導向演算法等24行)
- 移除調試用的 logger.debug 語句
- 簡化冗餘的內聯註解(emoji、"重要"等標註)
- 刪除 TDD 文件引用

清理檔案:
- backend/main.py - 移除調試日誌和元資訊
- backend/importer.py - 移除詳細類型檢查調試
- backend/export.py - 簡化 docstring
- backend/schemas.py - 移除元資訊
- backend/renderer.py - 移除 TDD 引用
- backend/renderer_timeline.py - 移除註解代碼和冗餘註解
- backend/path_planner.py - 簡化策略註解

保留內容:
- 所有函數的 docstring(功能說明、參數、返回值)
- 必要的業務邏輯註解
- 簡潔的模組功能說明

效果:
- 刪除約 100+ 行冗餘註解
- 代碼更加簡潔專業
- 功能完整性 100% 保留

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-11-06 12:22:29 +08:00
parent dc01655c9e
commit aa987adfb9
7 changed files with 50 additions and 242 deletions

View File

@@ -3,12 +3,6 @@ CSV/XLSX 匯入模組
本模組負責處理時間軸事件的資料匯入。
支援 CSV 和 XLSX 格式,包含欄位自動對應與格式容錯功能。
Author: AI Agent
Version: 1.0.0
DocID: SDD-IMP-001
Related: TDD-UT-IMP-001
Rationale: 實現 SDD.md 定義的 POST /import API 功能
"""
import csv
@@ -441,21 +435,14 @@ class CSVImporter:
return str(int(value))
return str(value).strip()
# 🔍 DEBUG: 顯示原始 row 和 field_mapping
logger.debug(f" Row keys: {list(row.keys())}")
logger.debug(f" Field mapping: {field_mapping}")
# 提取欄位值
event_id = safe_str(row.get(field_mapping['id'], ''))
title = safe_str(row.get(field_mapping['title'], ''))
start_str = safe_str(row.get(field_mapping['start'], '')) # 🔧 修復:也要使用 safe_str 轉換
start_str = safe_str(row.get(field_mapping['start'], ''))
group = safe_str(row.get(field_mapping.get('group', ''), '')) or None
description = safe_str(row.get(field_mapping.get('description', ''), '')) or None
color = safe_str(row.get(field_mapping.get('color', ''), ''))
# 🔍 DEBUG: 顯示提取的欄位值
logger.debug(f" 提取欄位 - ID: '{event_id}', 標題: '{title}', 時間: '{start_str}'")
# 驗證必要欄位
if not event_id or not title:
raise ValueError("缺少 ID 或標題")
@@ -468,19 +455,19 @@ class CSVImporter:
if not start:
raise ValueError(f"無效的時間: {start_str}")
# 🔧 修復:將 pandas Timestamp 轉換為標準 datetime
# 將 pandas Timestamp 轉換為標準 datetime
if PANDAS_AVAILABLE:
if isinstance(start, pd.Timestamp):
start = start.to_pydatetime()
# 驗證顏色(確保返回的是字串,不是 None
# 驗證顏色
color = self.color_validator.validate(color, int(row_num))
if not color: # 防禦性檢查
if not color:
color = self.color_validator.DEFAULT_COLORS[0]
# 所有事件都是時間點類型(不再有區間)
# 所有事件都是時間點類型
event_type = EventType.POINT
end = None # 不再使用 end 欄位
end = None
# 建立 Event 物件
try:
@@ -494,22 +481,9 @@ class CSVImporter:
color=color,
event_type=event_type
)
# 調試:確認所有欄位類型
logger.debug(f"Event 創建成功: id={type(event.id).__name__}, title={type(event.title).__name__}, "
f"start={type(event.start).__name__}, end={type(event.end).__name__ if event.end else 'None'}, "
f"group={type(event.group).__name__ if event.group else 'None'}, "
f"description={type(event.description).__name__ if event.description else 'None'}, "
f"color={type(event.color).__name__}")
return event
except Exception as e:
logger.error(f"創建 Event 失敗: {str(e)}")
logger.error(f" id={event_id} ({type(event_id).__name__})")
logger.error(f" title={title} ({type(title).__name__})")
logger.error(f" start={start} ({type(start).__name__})")
logger.error(f" end={end} ({type(end).__name__ if end else 'None'})")
logger.error(f" group={group} ({type(group).__name__ if group else 'None'})")
logger.error(f" description={description} ({type(description).__name__ if description else 'None'})")
logger.error(f" color={color} ({type(color).__name__})")
raise