Skip to content

環状区間の駅重複出現でETAの区間フィルタが無関係な出現を拾ってしまうバグを修正 - #6345

Merged
TinyKitten merged 2 commits into
devfrom
claude/eta-station-id-reconciliation-977wq9
Jul 4, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/eta-station-id-reconciliation-977wq9

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 4, 2026 •

Copy link
Copy Markdown
Member

概要

環状路線(都営大江戸線など)で同じ駅がETA APIのレスポンスに複数回出現する場合に、無関係な出現を誤って拾ってしまい、都庁前など特定の駅だけ大きく外れたETA(例: 58分)が表示される不具合を修正しました。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • useEstimateArrivalTimes.ts: leftStations とAPIレスポンス(allStops)の区間マッチングで、最良区間探索時に特定済みの一致インデックス(bestMatchedIndices)を直接使うよう変更。従来は区間内を stationGroupId の集合一致で再フィルタしていたため、環状区間でAPI側に同じ駅が複数回出現すると無関係な出現まで拾ってしまい、LineBoard側の Map 構築時に後勝ちで誤ったETAが残っていた
  • useEstimateArrivalTimes.test.tsx: leftStationsには1回しか出現しない駅が、API側の区間内では2回出現するケースを再現するリグレッションテストを追加

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • 同じ駅が複数回現れる路線でも、到達時刻の推定結果がより正確になるよう改善しました。
    • 区間内に同名駅の別の出現が混ざっていても、不要な重複を除外し、正しい停車駅と時刻を採用するようになりました。
    • これにより、環状区間などでも停車駅の並びと累積時間のずれが起きにくくなりました。

leftStationsに1回しか出現しない駅(都庁前など)でも、区間内一致の再フィルタでは
API側の無関係な重複出現まで拾い、後段のMap化で後勝ちして誤ったETA(例: 58分)が
表示されていたため、区間探索時に特定済みの一致インデックスを直接使うよう修正。
@github-actions github-actions Bot added the react label Jul 4, 2026
@coderabbitai

coderabbitai Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfee2502-6c4d-4075-82a5-1a329d362727

📥 Commits

Reviewing files that changed from the base of the PR and between 020e31b and 313b03a.

📒 Files selected for processing (1)
  • src/hooks/useEstimateArrivalTimes.ts
📝 Walkthrough

Walkthrough

useEstimateArrivalTimes フックの区間内停車駅絞り込みロジックが変更された。leftStations と allStops の対応インデックス(bestMatchedIndices)を新たに記録し、matchedStops をこのインデックスから直接構築することで、環状区間などでの同一駅重複出現による誤選択を防止する。対応するテストケースも追加された。

Changes

重複駅混同修正

Layer / File(s) Summary
一致インデックス探索と窓確定ロジック
src/hooks/useEstimateArrivalTimes.ts
候補区間探索ループで leftStations 各要素に対応する matchedIndices を組み立て、最短区間確定時に bestMatchedIndices として保持するよう変更した。
matchedStops構築の分岐とテスト検証
src/hooks/useEstimateArrivalTimes.ts, src/hooks/useEstimateArrivalTimes.test.tsx
windowStartIndex が特定できた場合は bestMatchedIndices から allStops を直接参照して matchedStops を構築し、特定できない場合のみ groupId 集合でフィルタするよう変更、対応するテストを追加した。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Hook as useEstimateArrivalTimes
  participant Window as 区間探索処理
  participant Stops as matchedStops構築処理

  Hook->>Window: leftStations[0]起点で最短区間を探索
  Window->>Window: leftStations各要素のmatchedIndicesを記録
  Window-->>Hook: windowStartIndex, bestMatchedIndices
  alt windowStartIndex特定済み
    Hook->>Stops: bestMatchedIndicesでallStopsから直接構築
  else 特定不可
    Hook->>Stops: groupId集合でwindowStopsをフィルタ
  end
  Stops-->>Hook: matchedStops
  Hook->>Hook: relativeStops算出(相対化・currentStation除外)
Loading

Possibly related PRs

  • TrainLCD/MobileApp#6320: useEstimateArrivalTimes.ts の窓マッチングと相対 cumulativeMinutes フィルタリングロジックの初期実装に直接関連する。
  • TrainLCD/MobileApp#6331: 同フックの区間内停車駅絞り込みと leftStations 起点フィルタ条件のロジック変更が重なっている。

Poem

ぴょんぴょん跳ねて駅を数え
環状線でも迷わない
重複駅も見分けられる
bestMatchedIndicesの魔法で
🐰 今日も正しい到着時刻
テストも通って大満足

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 主要な変更は環状区間でのETA区間フィルタの重複出現バグ修正で、タイトルはそれを的確に要約しています。
Description check ✅ Passed 概要、変更の種類、変更内容、テストが揃っており、必須テンプレートをほぼ満たしています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/eta-station-id-reconciliation-977wq9

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/hooks/useEstimateArrivalTimes.ts (1)

183-190: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

フォールバック分岐で visibleGroupIds の Set が要素ごとに再生成されている。

filter のコールバック内で Set を構築しているため、windowStops の各要素ごとに leftStations 全体を走査して Set を作り直しており、計算量が O(stops × leftStations) になります。コールバック外へ巻き上げてください。

♻️ 提案する修正
+    const visibleGroupIds = new Set(leftStations.map((ls) => ls.groupId));
     const matchedStops =
       windowStartIndex !== -1
         ? bestMatchedIndices.map((idx) => allStops[idx])
-        : windowStops.filter((s) => {
-            const visibleGroupIds = new Set(
-              leftStations.map((ls) => ls.groupId)
-            );
-            return (
-              s.stationGroupId != null && visibleGroupIds.has(s.stationGroupId)
-            );
-          });
+        : windowStops.filter(
+            (s) =>
+              s.stationGroupId != null && visibleGroupIds.has(s.stationGroupId)
+          );
🤖 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/useEstimateArrivalTimes.ts` around lines 183 - 190, In the fallback
branch of useEstimateArrivalTimes, the visibleGroupIds Set is being rebuilt
inside the windowStops.filter callback for every stop, which causes repeated
leftStations scans. Move the Set construction outside the filter callback so it
is created once before filtering, then reuse it inside the predicate while
keeping the existing stationGroupId membership check.
🤖 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/useEstimateArrivalTimes.ts`:
- Around line 183-190: In the fallback branch of useEstimateArrivalTimes, the
visibleGroupIds Set is being rebuilt inside the windowStops.filter callback for
every stop, which causes repeated leftStations scans. Move the Set construction
outside the filter callback so it is created once before filtering, then reuse
it inside the predicate while keeping the existing stationGroupId membership
check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 334fc2fd-211d-44a9-ac14-a9e41d222201

📥 Commits

Reviewing files that changed from the base of the PR and between b7c6fce and 020e31b.

📒 Files selected for processing (2)
  • src/hooks/useEstimateArrivalTimes.test.tsx
  • src/hooks/useEstimateArrivalTimes.ts

@TinyKitten
TinyKitten merged commit 8a16c08 into dev Jul 4, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/eta-station-id-reconciliation-977wq9 branch July 4, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants