Skip to content

オートモードのアプローチ変更 - #5322

Merged
TinyKitten merged 2 commits into
devfrom
fix/automode
Feb 18, 2026
Merged

TinyKitten merged 2 commits into
devfrom
fix/automode

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

サンライズ出雲で途中駅で戻ったり進んだりするバグを修正

Summary by CodeRabbit

リリースノート

  • テスト

    • 重複する駅IDに対応したシミュレーション動作の新規テストスイートを追加。複数パターンでの進行状況と距離計算の検証を強化。
  • バグ修正

    • 重複駅IDや座標欠落時の挙動を改善。区間距離・速度プロファイル生成とウェイポイント進行の計算をより堅牢に処理し、異常進行を防止。

@TinyKitten TinyKitten self-assigned this Feb 18, 2026
@github-actions github-actions Bot added the react label Feb 18, 2026
@coderabbitai

coderabbitai Bot commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

シミュレーションフックの速度プロファイル生成とウェイポイント進行をインデックスベースで再実装し、座標検証・距離計算・プロファイル正規化を導入。重複駅IDを扱うテストスイートを追加。

Changes

Cohort / File(s) Summary
Speed Profile & Waypoint Refactoring
src/hooks/useSimulationMode.ts
速度プロファイル生成をインデックスベースへ再設計。current/between/next のポイント列を作成して距離を算出し、行種別に応じた加減速値で generateTrainSpeedProfile を呼ぶ。indexOf ベースのセグメント探索、進行ロジックとガード条件(座標検証、waypoint 必要数など)を追加。
Duplicate Station ID Test Suite
src/hooks/useSimulationMode.test.tsx
「重複する駅IDの処理」テストスイートを追加(3テスト)。隣接・非隣接での重複時の速度プロファイル距離、シミュレーション進行(時間経過での位置更新)、中間通過駅を含むケースでの正しいウェイポイント選択を検証。

Sequence Diagram(s)

sequenceDiagram
    participant Hook as useSimulationMode
    participant Stations as StationList
    participant Gen as generateTrainSpeedProfile
    participant Store as LocationStore

    Hook->>Stations: currentIndex, nextIndex, between stations を indexOf で取得
    Hook->>Stations: ポイント列(cur + between + next) の座標を取得
    Hook->>Gen: 距離・加減速パラメータで速度プロファイル生成を要求
    Gen-->>Hook: 正規化された速度プロファイルを返却
    Hook->>Store: ウェイポイント進行に基づく位置・経路更新を適用
    Store-->>Hook: 更新結果(位置/到達情報)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 駅が重なっても僕は跳んでく、
インデックスで道を辿り、
距離を測り加速を覚え、
シミュレーションはまた進むよ、
にんじん片手に祝杯だ! 🚂✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトル「オートモードのアプローチ変更」は、useSimulationMode.tsの速度プロファイル生成ロジックの大幅な リファクタリングと、重複する駅IDの処理に関するテストの追加という主な変更内容を適切に要約しており、変更セット全体と関連性が高い。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/automode

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

@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

🧹 Nitpick comments (1)
src/hooks/useSimulationMode.test.tsx (1)

61-93: テストヘルパー関数の再利用検討

mockStation や mockPassStation のようなヘルパー関数は他のテストでも有用な可能性があります。将来的に src/utils/test/ へ抽出を検討してください。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useSimulationMode.test.tsx` around lines 61 - 93, Extract the test
helpers mockStation and mockPassStation from useSimulationMode.test.tsx into a
shared test-helper module and import them back into this test; update their
exports so other test files can reuse them and adjust any imports in tests that
previously redefined these helpers. Ensure the helpers keep the same signatures
and types (e.g., mockStation(id:number, groupId:number, lat:number, lon:number,
lineId?:number): Station) and update any type casts or dependencies
(OperationStatus, StopCondition, LineType, YAMANOTE_LINE_ID) to be imported from
their original modules in the new helper module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 212-214: Guard against division by zero when computing
distanceRatio: after computing profileDistance (from speedProfile) check if
profileDistance === 0 and, if so, set correctedProfile to an array of zeros
(e.g., speedProfile.map(()=>0)) instead of dividing; otherwise compute
distanceRatio and correctedProfile as before. Update the logic around
profileDistance, distanceRatio and correctedProfile in useSimulationMode.ts
(referencing speedProfile, profileDistance, distanceRatio, correctedProfile and
generateTrainSpeedProfile) to ensure no Infinity values are produced.

---

Nitpick comments:
In `@src/hooks/useSimulationMode.test.tsx`:
- Around line 61-93: Extract the test helpers mockStation and mockPassStation
from useSimulationMode.test.tsx into a shared test-helper module and import them
back into this test; update their exports so other test files can reuse them and
adjust any imports in tests that previously redefined these helpers. Ensure the
helpers keep the same signatures and types (e.g., mockStation(id:number,
groupId:number, lat:number, lon:number, lineId?:number): Station) and update any
type casts or dependencies (OperationStatus, StopCondition, LineType,
YAMANOTE_LINE_ID) to be imported from their original modules in the new helper
module.

Comment thread src/hooks/useSimulationMode.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: 1

Caution

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

⚠️ Outside diff range comments (1)
src/hooks/useSimulationMode.ts (1)

269-305: ⚠️ Potential issue | 🟠 Major

step 側も同じ indexOf 問題で区間が戻る可能性

stationsWithoutPass.indexOf(currentSegmentStation) は重複参照で先頭一致になり、nextStopStation が過去側に戻る可能性があります。ここも currentSegmentStationIndex から前方検索に統一してください。

🛠 修正案
-      const currentSegmentStopIndex = stationsWithoutPass.indexOf(
-        currentSegmentStation
-      );
-      const nextStopStation = stationsWithoutPass[currentSegmentStopIndex + 1];
+      const nextStopStationIndex = maybeRevsersedStations.findIndex(
+        (s, idx) => idx > currentSegmentStationIndex && !getIsPass(s)
+      );
+      const nextStopStation =
+        nextStopStationIndex === -1
+          ? undefined
+          : maybeRevsersedStations[nextStopStationIndex];
@@
-      const nextStopStationIndex =
-        maybeRevsersedStations.indexOf(nextStopStation);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useSimulationMode.ts` around lines 269 - 305, The code uses
stationsWithoutPass.indexOf(currentSegmentStation) which can match an earlier
duplicate and make nextStopStation jump backwards; change the search to start
after the current segment index by replacing that call with
stationsWithoutPass.indexOf(currentSegmentStation, currentSegmentStationIndex +
1) (or otherwise use the existing currentSegmentStationIndex as the fromIndex)
so nextStopStation is always found forward; update any related logic that
assumes currentSegmentStopIndex accordingly (references:
stationsWithoutPass.indexOf(currentSegmentStation), currentSegmentStationIndex,
nextStopStation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 146-167: The current map callback in maybeRevsersedStations uses
stationsWithoutPass.indexOf(cur) which breaks when identical station objects
appear multiple times; instead, starting from curMapIndex scan arr forward (from
curMapIndex+1) to find the first element where !getIsPass(s) and treat that as
the next stop. Update the logic in the map callback (the function using cur,
curMapIndex, arr and variables stationsWithoutPass, curIdx, next,
nextStationIndex, betweenNextStation) to compute nextStationIndex by
forward-searching arr for the next non-pass station rather than using
stationsWithoutPass.indexOf(cur), then slice between using those indices as
before.

---

Outside diff comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 269-305: The code uses
stationsWithoutPass.indexOf(currentSegmentStation) which can match an earlier
duplicate and make nextStopStation jump backwards; change the search to start
after the current segment index by replacing that call with
stationsWithoutPass.indexOf(currentSegmentStation, currentSegmentStationIndex +
1) (or otherwise use the existing currentSegmentStationIndex as the fromIndex)
so nextStopStation is always found forward; update any related logic that
assumes currentSegmentStopIndex accordingly (references:
stationsWithoutPass.indexOf(currentSegmentStation), currentSegmentStationIndex,
nextStopStation).

Comment thread src/hooks/useSimulationMode.ts Resolved
@TinyKitten
TinyKitten merged commit c56dedd into dev Feb 18, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the fix/automode branch February 18, 2026 13:09
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.

1 participant