Skip to content

ETAの駅突き合わせをstationGroupIdからstationIdに変更し環状区間の重複駅を確実に区別する - #6350

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

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

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 4, 2026 •

Copy link
Copy Markdown
Member

概要

先行してマージ済みの #6345 では、環状区間(都営大江戸線など)でETA APIのレスポンスに同じ駅が複数回出現する場合の誤ったETA表示を、stationGroupIdベースの区間探索アルゴリズムで対処していました。しかし都庁前の外回り/内回りのように、groupIdは共通でもstationIdは出現ごとに別々に採番されている駅があるため、groupIdベースのマッチングでは原理的に曖昧さが残っていました。本PRでは突き合わせキーを一意なstationIdに変更し、この曖昧さを根本的に解消します。

変更の種類

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

変更内容

  • useEstimateArrivalTimes.ts: ETAの区間マッチングをstationGroupIdから一意なstationIdベースに変更。曖昧さがなくなったため、以前追加した複雑な区間探索(bestMatchedIndices)ロジックが不要になり削除、シンプルなfilterベースの実装に戻した
  • LineBoardSaikyo/Toei/East/JRKyushu.tsx: ETA表示用のMap(estimatedMinutesByGroupId → estimatedMinutesByStationId)も同様にstationIdキーへ変更
  • useEstimateArrivalTimes.test.tsx: 同一groupId・別stationIdの2出現(都庁前の外回り/内回り相当)がある場合に正しい出現だけを拾えることを検証するテストに書き直し

テスト

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

関連Issue

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


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • 到着予想到達時間の参照を駅単位(stationId)に統一し、表示のズレを改善しました。
    • 環状路線などで同一駅が複数回出るケースでも、より適切な推定時間を表示します。
  • New Features
    • 駅単位(stationId)の推定到着時刻をまとめて取得できる新フックを追加しました。
  • Tests
    • モック/期待値を更新し、新フックに関するテストケースを追加しました。

claude added 5 commits July 4, 2026 06:04
leftStationsに1回しか出現しない駅(都庁前など)でも、区間内一致の再フィルタでは
API側の無関係な重複出現まで拾い、後段のMap化で後勝ちして誤ったETA(例: 58分)が
表示されていたため、区間探索時に特定済みの一致インデックスを直接使うよう修正。
都庁前のように外回り/内回りでgroupIdは共通だがstationIdは別々に採番される駅があり、
groupIdベースの区間マッチングでは無関係な出現を拾って誤ったETAが残る余地があった。
stationIdは出現ごとに一意なため、これに切り替えることで曖昧さのない突き合わせにし、
複雑だった区間探索ロジックも不要になったため削除した。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYPA7eobZEejKS4Y3MrRuA
@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 77d6b2ae-3be8-4194-84f0-626e93ec603a

📥 Commits

Reviewing files that changed from the base of the PR and between ab0a2da and fcd5815.

📒 Files selected for processing (2)
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardJRKyushu.test.tsx

📝 Walkthrough

Walkthrough

到着予想到達時間の参照・算出キーをstationGroupIdからstationIdへ変更した。useEstimateArrivalTimes の絞り込みロジック、useEstimatedMinutesByStationId の追加、LineBoard系4コンポーネントの参照先更新、関連テストの期待値修正を含む。

Changes

stationGroupIdからstationIdへの到着推定キー移行

Layer / File(s) Summary
matchedRouteのstationIdベースフィルタリング
src/hooks/useEstimateArrivalTimes.ts
currentStation.idでbaseMinutesを算出し、leftStationsのstationId集合でallStopsをフィルタし、現在駅と同一stationIdをrelativeStopsから除外するよう変更。useMemo依存配列もstationId参照に更新。
フックテストのstationId前提更新
src/hooks/useEstimateArrivalTimes.test.tsx
ルート選別、leftStations抽出、相対分換算、現在駅除外、環状路線重複出現の各テストケースのモックデータと期待値をstationIdベースに更新。
stationId別estimatedMinutesの導出
src/hooks/useEstimatedMinutesByStationId.ts, src/hooks/index.ts
stationIdベースのMapを返す新フックを追加し、hooksインデックスへ再エクスポート。
LineBoardでの到着分参照切替
src/components/LineBoardEast.tsx, src/components/LineBoardJRKyushu.tsx, src/components/LineBoardSaikyo.tsx, src/components/LineBoardToei.tsx
4つのLineBoardでMap生成を新フックに置き換え、StationNameCellへ渡すestimatedMinutesをstationId基準へ変更。
LineBoard側テストのモック更新
src/components/LineBoardEast.test.tsx, src/components/LineBoardJRKyushu.test.tsx, src/components/LineBoardSaikyo.test.tsx, src/components/LineBoardToei.test.tsx
追加されたフックを各テストの~/hooksモックに含め、空のMapを返すよう更新し、stationId紐づけの検証ケースを追加。
stationId別Map生成の単体テスト
src/hooks/useEstimatedMinutesByStationId.test.ts
null入力、stops未定義、stationId欠損の除外、stationIdごとのMap生成を検証するテストを追加。

Estimated code review effort: 4 (Complex) | ~50 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6320: useEstimateArrivalTimes の導入と、その後の stationId 前提への置き換えが同じ到着時刻計算系に関係している。
  • TrainLCD/MobileApp#6331: matchedRoute の基準時刻算出と除外条件を含む useEstimateArrivalTimes の流れを変更している。
  • TrainLCD/MobileApp#6345: 環状路線の重複駅出現を含む useEstimateArrivalTimes の停止駅抽出ロジックに関係している。

Poem

ぴょんと跳ねて キーを変える
グループIDから 駅IDへ
到着分も すっきり並ぶ
ぐるっと回る線でも 迷わない
にんじんぽりぽり できあがり 🥕🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはstationGroupIdからstationIdへの変更と環状区間の重複駅の区別という主変更を正確に要約しています。
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/components/LineBoardEast.tsx`:
- Around line 493-501: The stationId-based Map construction for estimated
minutes is duplicated across LineBoardEast, LineBoardJRKyushu, LineBoardSaikyo,
and LineBoardToei, so refactor it into a shared hook to avoid future drift.
Extract the current useMemo logic from estimatedMinutesByStationId into a
reusable helper such as useEstimatedMinutesByStationId, then replace each local
implementation with that shared hook while preserving the existing filtering and
stationId as number mapping behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: af7a48de-174e-4b72-bf67-1ea08e696c7c

📥 Commits

Reviewing files that changed from the base of the PR and between 95de837 and bf9f765.

📒 Files selected for processing (6)
  • src/components/LineBoardEast.tsx
  • src/components/LineBoardJRKyushu.tsx
  • src/components/LineBoardSaikyo.tsx
  • src/components/LineBoardToei.tsx
  • src/hooks/useEstimateArrivalTimes.test.tsx
  • src/hooks/useEstimateArrivalTimes.ts

Comment thread src/components/LineBoardEast.tsx Resolved

@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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/components/LineBoardJRKyushu.test.tsx (1)

13-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

stationIdベースの値取得を検証するテストが未追加

LineBoardEast.test.tsxと同様に、useEstimatedMinutesByStationIdのモックが常に空のMapを返すため、estimatedMinutesByStationId.get(s.id)がLineDotへ正しく伝播するケースが検証されていません。非空のMapを使ったテストケースの追加を推奨します。

As per coding guidelines, "挙動を変更する際は、同じ変更セット内でテストも更新または追加すること".

🤖 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/components/LineBoardJRKyushu.test.tsx` around lines 13 - 21, Add a test
case in LineBoardJRKyushu.test.tsx to cover stationId-based minute lookup
propagation. The current mock for useEstimatedMinutesByStationId always returns
an empty Map, so extend the setup to return a non-empty Map and assert that
LineBoardJRKyushu passes estimatedMinutesByStationId.get(s.id) through to
LineDot, similar to the coverage in LineBoardEast.test.tsx. Use the existing
mocks for useEstimatedMinutesByStationId, LineBoardJRKyushu, and LineDot to
locate and update the test.

Source: Coding guidelines

src/components/LineBoardEast.test.tsx (1)

13-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

stationIdベースの値取得を検証するテストが未追加

useEstimatedMinutesByStationIdのモックが常に空のMapを返すため、既存テストはestimatedMinutesByStationId.get(s.id)がLineDotへ正しく伝播するケースを一切検証していません。本PRの主眼であるstationId移行の正しさを担保するため、非空のMapを返すモックを使い、LineDotが期待するestimatedMinutes値を受け取ることを確認するテストケースの追加を推奨します。

As per coding guidelines, "挙動を変更する際は、同じ変更セット内でテストも更新または追加すること".

♻️ 追加テスト例
   it('LineDotコンポーネントが各駅に対してレンダリングされる', () => {
     const { LineDot } = require('./LineBoard/shared/components');
     render(
       <LineBoardEast
         stations={mockStations}
         lineColors={['`#9acd32`', '`#9acd32`']}
         hasTerminus={false}
       />
     );
     expect(LineDot).toHaveBeenCalled();
   });
+
+  it('stationIdに対応するestimatedMinutesがLineDotへ渡される', () => {
+    const { useEstimatedMinutesByStationId } = require('~/hooks');
+    useEstimatedMinutesByStationId.mockReturnValue(new Map([[2, 5]]));
+    const { LineDot } = require('./LineBoard/shared/components');
+    render(
+      <LineBoardEast
+        stations={mockStations}
+        lineColors={['`#9acd32`', '`#9acd32`']}
+        hasTerminus={false}
+      />
+    );
+    expect(LineDot).toHaveBeenCalledWith(
+      expect.objectContaining({ estimatedMinutes: 5 }),
+      undefined
+    );
+  });
🤖 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/components/LineBoardEast.test.tsx` around lines 13 - 21, The current
LineBoardEast tests never verify the stationId-based estimated minutes flow
because useEstimatedMinutesByStationId is mocked to always return an empty Map.
Update the test setup in LineBoardEast.test.tsx so
useEstimatedMinutesByStationId can return a non-empty Map keyed by stationId,
and add a case that asserts LineDot receives the expected estimatedMinutes from
estimatedMinutesByStationId.get(s.id). Use the existing LineBoardEast and
LineDot test paths to confirm the stationId migration is wired through
correctly.

Source: Coding guidelines

🤖 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.

Inline comments:
In `@src/hooks/index.ts`:
- Line 25: Add dedicated tests for useEstimatedMinutesByStationId to directly
cover its internal logic, since LineBoard tests mock the hook with jest.fn(() =>
new Map()) and won’t catch regressions. Focus the new tests on the hook’s
stationId filtering when stationId is null/undefined and on the
cumulativeMinutes-to-Map conversion behavior inside
useEstimatedMinutesByStationId, so the real hook implementation is exercised and
protected.

---

Outside diff comments:
In `@src/components/LineBoardEast.test.tsx`:
- Around line 13-21: The current LineBoardEast tests never verify the
stationId-based estimated minutes flow because useEstimatedMinutesByStationId is
mocked to always return an empty Map. Update the test setup in
LineBoardEast.test.tsx so useEstimatedMinutesByStationId can return a non-empty
Map keyed by stationId, and add a case that asserts LineDot receives the
expected estimatedMinutes from estimatedMinutesByStationId.get(s.id). Use the
existing LineBoardEast and LineDot test paths to confirm the stationId migration
is wired through correctly.

In `@src/components/LineBoardJRKyushu.test.tsx`:
- Around line 13-21: Add a test case in LineBoardJRKyushu.test.tsx to cover
stationId-based minute lookup propagation. The current mock for
useEstimatedMinutesByStationId always returns an empty Map, so extend the setup
to return a non-empty Map and assert that LineBoardJRKyushu passes
estimatedMinutesByStationId.get(s.id) through to LineDot, similar to the
coverage in LineBoardEast.test.tsx. Use the existing mocks for
useEstimatedMinutesByStationId, LineBoardJRKyushu, and LineDot to locate and
update the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ab574539-89e7-412b-b81c-333618949092

📥 Commits

Reviewing files that changed from the base of the PR and between bf9f765 and 1fc42e5.

📒 Files selected for processing (10)
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardEast.tsx
  • src/components/LineBoardJRKyushu.test.tsx
  • src/components/LineBoardJRKyushu.tsx
  • src/components/LineBoardSaikyo.test.tsx
  • src/components/LineBoardSaikyo.tsx
  • src/components/LineBoardToei.test.tsx
  • src/components/LineBoardToei.tsx
  • src/hooks/index.ts
  • src/hooks/useEstimatedMinutesByStationId.ts

Comment thread src/hooks/index.ts Resolved

@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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@src/components/LineBoardEast.test.tsx`:
- Around line 190-206: The mocked return value for
useEstimatedMinutesByStationId in LineBoardEast.test.tsx is leaking past this
test because afterEach only clears call history, not implementations. Update the
test around LineDot to use a one-time mock return (mockReturnValueOnce) or
explicitly restore the default empty Map afterward so the behavior stays
isolated to this case.

In `@src/components/LineBoardJRKyushu.test.tsx`:
- Around line 165-181: The test setup in LineBoardJRKyushu.test.tsx leaves the
mocked useEstimatedMinutesByStationId return value active beyond this case, so
update the mock in the LineDot assertion test to use a one-time return value
instead of a persistent one. Locate the test that requires
useEstimatedMinutesByStationId from ~/hooks and verifies LineDot, and change the
mock so only this scenario receives the Map([[2, 5]]) result while other tests
remain unaffected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 89b211d3-eef8-4480-b999-a403f4ab43e9

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc42e5 and ab0a2da.

📒 Files selected for processing (3)
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardJRKyushu.test.tsx
  • src/hooks/useEstimatedMinutesByStationId.test.ts

Comment thread src/components/LineBoardEast.test.tsx Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@TinyKitten
TinyKitten merged commit 3da93c8 into dev Jul 4, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/eta-station-id-reconciliation-977wq9 branch July 4, 2026 11:01
@TinyKitten TinyKitten mentioned this pull request Jul 4, 2026
4 of 9 tasks
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