Repository navigation
逆走通知のバッテリー消費を抑えるため検知ロジックをatomに集約し通知重複防止とヒステリシスを強化 - #5934
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughGPSベースの逆方向検出がコンポーネント内状態からJotai atomへ移動。新しい effect フックが検出を実行して atom に書き込み、購読フックは atom を読み取る。アプリレイアウトで effect を一度起動し、通知ロジックは駅単位で重複を抑制する。 ChangesWrong Direction Detection Refactoring
Sequence Diagram(s)sequenceDiagram
participant locationAtom as locationAtom
participant detector as useWrongDirectionDetectorEffect
participant wrongAtom as wrongDirectionAtom
participant refresher as useRefreshStation
locationAtom->>detector: location updates
detector->>detector: compute distance delta & hysteresis
detector->>wrongAtom: writeState({isWrongDirection, isLoopLineWrongDirection})
wrongAtom->>refresher: subscriber reads flags
refresher->>refresher: compare nextStationId with lastNotifiedWrongDirectionStationIdRef
refresher->>refresher: send notification if not already notified
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/hooks/useWrongDirectionDetector.ts (1)
82-88: ⚡ Quick win
resetDetectionStateの依存配列からisLoopLineを除外することを推奨
resetDetectionStateがisLoopLineに依存しているため、ループ路線の判定が変わるとselectedBoundId変更用のuseEffect(Line 98-102)が再実行され、検知状態が意図せずリセットされる可能性があります。
writeState(false, isLoopLine)はdetected=falseの場合、isLoopLineの値に関係なく両フラグがfalseになるため、ここではisLoopLineは不要です。♻️ 修正案
const resetDetectionState = useCallback(() => { prevDistanceRef.current = null; consecutiveIncreaseCountRef.current = 0; cumulativeIncreaseRef.current = 0; notifiedForStationIdRef.current = undefined; - writeState(false, isLoopLine); - }, [isLoopLine, writeState]); + writeState(false, false); + }, [writeState]);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useWrongDirectionDetector.ts` around lines 82 - 88, The resetDetectionState callback depends on isLoopLine unnecessarily causing resets when loop-route status changes; update the resetDetectionState definition to remove isLoopLine from its dependency array and call writeState with only the detected value (e.g., writeState(false)) or otherwise compute the necessary flags without reading isLoopLine, so that resetting detection no longer re-triggers when isLoopLine toggles; adjust the dependency array to [writeState] and keep the body setting prevDistanceRef, consecutiveIncreaseCountRef, cumulativeIncreaseRef, and notifiedForStationIdRef as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/hooks/useWrongDirectionDetector.ts`:
- Around line 82-88: The resetDetectionState callback depends on isLoopLine
unnecessarily causing resets when loop-route status changes; update the
resetDetectionState definition to remove isLoopLine from its dependency array
and call writeState with only the detected value (e.g., writeState(false)) or
otherwise compute the necessary flags without reading isLoopLine, so that
resetting detection no longer re-triggers when isLoopLine toggles; adjust the
dependency array to [writeState] and keep the body setting prevDistanceRef,
consecutiveIncreaseCountRef, cumulativeIncreaseRef, and notifiedForStationIdRef
as before.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7cbdde2c-ea12-431c-a2fc-ea453eb1f7dd
📒 Files selected for processing (6)
src/components/Permitted.tsxsrc/hooks/index.tssrc/hooks/useRefreshStation.tssrc/hooks/useWrongDirectionDetector.test.tsxsrc/hooks/useWrongDirectionDetector.tssrc/store/atoms/wrongDirection.ts
`cumulativeIncreaseRef` は正の増加だけを足し込む一方、 `WRONG_DIRECTION_NOISE_TOLERANCE` (10m) 以内の減少は無視して累積を維持していた。 この非対称性により、静止していてもGPSの揺れだけで累積が単調に伸び、 `WRONG_DIRECTION_MIN_DISTANCE` (300m) に到達しうる (#6967)。 累積を「最接近点 (`nearestDistanceRef`) からの正味距離」で測るよう変更する。 無視した小さな減少も起点の更新を通じて距離へ反映されるため、静止中の揺れでは 正味距離が伸びない。連続カウンタ側のヒステリシス (#5934 の意図) はそのまま残す。 Claude-Session: https://claude.ai/code/session_01W43wAgGXf7Sank3yirTJD2 Co-authored-by: Claude Opus 5 <[email protected]>
概要
設定画面で逆走通知を ON にするとバッテリー消費が速くなる問題への対処。逆方向検知ロジックを atom に集約して二重計算を解消し、GPS ノイズによる通知の連続再発火を防ぐ。
変更の種類
変更内容
src/store/atoms/wrongDirection.tsを新設し、検知結果を{ isWrongDirection, isLoopLineWrongDirection }形で一元管理。useWrongDirectionDetectorを atom 読み取り専用に縮退し、計算ロジック本体はuseWrongDirectionDetectorEffectとして切り出してPermitted.tsxで 1 度だけマウントするよう変更(従来はuseRefreshStationとuseWarningInfoの 2 箇所から呼ばれており、位置更新ごとにgetDistance計算と state 更新が二重に実行されていた)。wrongDirectionDetectedをfalseに戻さず、完全リセットはarrived/selectedBound変更 / 次駅変更 / 前提条件不成立時のみに限定。useRefreshStationの逆走通知発火 effect で、重複防止 ref を boolean から 次駅 ID ベースに変更。isWrongDirectionの一時的な false 復帰だけでは再発火させず、同一区間で通知が連続して鳴るのを防ぐ。useWrongDirectionDetector.test.tsxを追加(ヒステリシス成立・小ノイズで判定が維持されること・到着でリセットされること・公開フックの初期値)。回帰リスクと緩和
useWarningInfo) の表示は ON/OFF に関係なく従来通り動作する(atom 経由で同じ結果を購読)。arrived/selectedBound/ 次駅変更 / GPS精度劣化のいずれかで完全リセットされるため、本来の「区間移行」場面での誤検知持ち越しは発生しない。テスト
npm run lintが通ることnpm testが通ること(1531 件、全パス)npm run typecheckが通ること関連Issue
スクリーンショット(任意)
Generated by Claude Code
Summary by CodeRabbit
New Features
バグ修正
テスト