Files
DashBoard/claude.md
beabigegg d5f0df3384 feat: 新增機台稼動歷史分析功能
新增 Resource History Analysis 功能模組:
- 後端服務:query_summary、query_detail、export_csv 查詢函數
- API 路由:/api/resource/history/* 端點 (options/summary/detail/export)
- 前端頁面:KPI 卡片、OU% 趨勢圖、E10 狀態堆疊圖、熱力圖、階層式表格
- 支援時間粒度切換(日/週/月/年)與多維度篩選
- 查詢範圍擴展至 730 天(兩年)

其他改進:
- 新增 filter_cache 服務統一管理工站與型號快取
- MesApi 修復 JSON 解析失敗時誤觸重試的問題
- 新增 _safe_float() 處理 NaN 值避免 JSON 序列化錯誤
- E10 狀態分布圖表 tooltip 顯示各狀態百分比
- 新增完整測試套件(單元/整合/E2E)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 08:53:32 +08:00

2.3 KiB

MES Dashboard - Claude Code Instructions

Project Overview

MES Dashboard 是一個工廠製造執行系統的儀表板應用,使用 Flask + Oracle 資料庫 + ECharts 前端圖表。

Before Starting Any Task

  1. Review architecture documentation: Read docs/architecture_findings.md to understand:
    • Database connection management patterns
    • Caching mechanisms and TTL constants
    • Filter cache (workcenter/family) usage
    • Frontend global components (Toast, MesApi)
    • Data table filtering rules and column mappings
    • E10 status definitions and OU% calculation
    • Testing conventions

When Making Changes

If any of the following patterns are modified or new patterns are discovered:

  • Database connection or pooling approach
  • Caching strategy or TTL values
  • Global frontend components usage
  • Data table column names or filtering rules
  • New shared utilities or services
  • Testing conventions or setup patterns

Update docs/architecture_findings.md to reflect the changes.

Key Architecture Rules

Database

  • Always use mes_dashboard.core.database.read_sql_df() for queries
  • Never create direct connections in services
  • Reset db._ENGINE = None in test setUp

Caching

  • Use mes_dashboard.core.cache for all caching operations
  • Use mes_dashboard.services.filter_cache for workcenter/family lookups
  • Always convert WORKCENTERNAME → WORKCENTER_GROUP for display

Frontend

  • Toast notifications: Use Toast.warning(), Toast.error(), Toast.success() (NOT MESToast)
  • API calls: Use MesApi.get() with proper timeout
  • Array operations: Remember .reverse() modifies in-place

Data Tables

  • DW_MES_RESOURCE: Use PJ_ASSETSSTATUS (not ASSETSTATUS), LOCATIONNAME (not LOCATION)
  • DW_MES_RESOURCESTATUS_SHIFT: HISTORYID maps to RESOURCEID
  • DW_PJ_LOT_V: Source for WORKCENTER_GROUP mapping

SQL

  • Use /*+ MATERIALIZE */ hint for Oracle CTEs used multiple times
  • Date range: TXNDATE >= start AND TXNDATE < end + 1
  • Apply EQUIPMENT_TYPE_FILTER, location exclusions, asset status exclusions

Testing

  • Unit tests: tests/test_*_service.py
  • Integration tests: tests/test_*_routes.py
  • E2E tests: tests/e2e/test_*_e2e.py
  • For parallel queries (ThreadPoolExecutor), mock with function-based side_effect, not list