Skip to content

オートモードを到着時間推定の見込みで走らせ、ETAとGPXと同じ時間で駅に着いて停まるようにした - #7158

Merged
TinyKitten merged 2 commits into
devfrom
feature/align-auto-mode-with-eta
Oct 1, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/align-auto-mode-with-eta

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

概要

オートモードを、StationAPI の到着時間推定の見込み(trainRoute の model: Estimated)で走らせるようにしました。各停車駅には見込みの到着時刻に着き、推定の停車時間だけ止まります。

TrainLCD/StationAPI#1715 で、ETA(estimateArrivalTimes)も Estimated と同じ値になります。GPX の生成もオートモードと同じ計算を使うので、オートモードの移動時間・ETA・GPX の移動時間がそろいます。

変更の種類

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

変更内容

  • オートモード(src/hooks/useSimulationMode.ts)
    • trainRoute を model: Estimated で引きます(GET_ESTIMATED_TRAIN_ROUTE、GET_ESTIMATED_CONNECTED_TRAIN_ROUTE)。
    • 停車駅から次の停車駅までの時間は「次の駅の到着 − この駅の出発」です。この時間で走り切る速度列を作り、途中駅では推定の停車時間(出発 − 到着)だけ止まります。
    • 区間ごとの 1 秒未満の端数は、次の区間で計画上の到着時刻に戻します。終点までに積み上がりません。
    • 乗換経路では、乗換駅が降車と乗車の 2 行で返ります。出発の見込みは乗車の行から取り、乗換の徒歩と待ち時間を乗換駅での停車にしました。
    • 推定が通過扱いにしている駅に停まるときは、停車時間の見込みがありません。この場合は、これまでと同じ 2 ティックだけ止まります。
    • 見込みが返らない区間(バスの経路など)は、これまでどおり区間の最高速度で走ります。
  • 本番の StationAPI への備え
    • 本番の StationAPI は、まだ model 引数を知りません。Estimated の問い合わせがエラーになったら、これまでの問い合わせ(Legacy)に戻して走ります。
    • model を宣言した文書は、知らない API では検証エラーになります。そのため、$sortBy と同じく別の文書に分けました。
  • 速度列(src/utils/trainRouteTiming.ts)
    • 台形の位置の式から、1 秒ごとの進みを並べる speedProfileForDuration を足しました。列の長さは求めた秒数ちょうどで、合計は区間の距離になります。
    • generateTrainSpeedProfile は加速・巡航・減速を 1 秒単位で切り上げて並べます。そのため、巡航速度を選び直しても列の長さが 1 秒ずれることがありました。距離・加減速・秒数を振った 233,160 通りで測ると、約 4 分の 1 でずれていました。新しい関数では 0 件です。
    • cruiseSpeedForDuration と planLegTimings を GPX 生成スクリプトから移し、オートモードと共有しました。このファイルは Node からも直接読むので、何も import しません。
  • 乗換経路の突き合わせ(src/utils/currentLineGroupStations.ts)
    • alignConnectedTrainRouteSegments に、同じ駅グループが続く行をまとめる関数を渡せるようにしました。
  • GPX(scripts/generate-location-gpx.mjs、assets/gpx/)
    • 見込みに合わせる区間の速度列を、オートモードと同じ speedProfileForDuration で作るようにしました。
    • 同梱の 4 本(片町線・総武快速線・京王線特急・Fライナー)を、ステージングの StationAPI で作り直しました。全停車駅で、見込みとの差は 1.5 秒以内です。SampleTohokuShinkansen.gpx は --line で作っているので変わりません。
    • FLinerSeibu.gpx の最長の欠測が 326 秒から 327 秒になりました。location.subwayGpx.test.ts の実測値と docs/location-simulation.md の記述を合わせました。欠測の件数(7 件、うち 5 件が 90 秒超)は変わりません。
  • テスト
    • useSimulationMode.test.tsx で、主に引く文書を Estimated 側に替えました。乗換経路では区間を渡し、1 系統の問い合わせはしないという検査は、そのまま残しています。
    • 足したテストは次のとおりです。
      • 見込みの到着時刻に着き、推定の停車時間だけ止まる。
      • 推定が通過扱いの駅に停まっても、終点の時刻がずれない。
      • 乗換駅では、到着から次の区間の出発まで止まる。
      • Estimated がエラーなら、1 系統でも乗換経路でも Legacy に戻す。
    • src/utils/trainRouteTiming.test.ts を足しました。

リリースの順序

StationAPI#1715 が本番に入る前にこのアプリが出ても、オートモードは Legacy の値で今までどおり走ります。ETA とそろうのは、StationAPI の本番に model: Estimated が入ってからです。

テスト

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

npm run lint、npm run typecheck、npm test(322 スイート・3,589 件)はすべて成功しました。npm run test:scripts(109 件)も成功しました。実機・エミュレータでの動作確認はしていません。

関連Issue

Refs TrainLCD/StationAPI#1715

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

UI 変更なし: オートモードの走行の時間配分と開発用の GPX(assets/gpx/ はアプリに同梱されません)の変更で、画面の見た目は変わりません。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 機能改善
    • シミュレーションで、駅の到着・出発見込みに合わせた走行時間と停車時間を反映するようになりました。乗換駅での待機時間も考慮します。
    • GPXデータの区間時間や速度変化が、シミュレーションと共通の計算基準に基づくようになりました。
  • 不具合修正
    • 見込み時間を取得できない場合は従来の走行方式に切り替わるようになりました。

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

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Repository guideline files applied to this review (1)
.github/copilot-instructions.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: aff1b647-343b-4192-a9bb-085498deff0c

📥 Commits

Reviewing files that changed from the base of the PR and between 3db0f29 and 1f33945.

📒 Files selected for processing (14)
  • assets/gpx/FLinerSeibu.gpx
  • assets/gpx/KatamachiRapid.gpx
  • assets/gpx/KeioSpecialExpress.gpx
  • assets/gpx/SobuRapid.gpx
  • docs/location-simulation.md
  • scripts/generate-location-gpx.mjs
  • src/hooks/useSimulationMode.test.tsx
  • src/hooks/useSimulationMode.ts
  • src/lib/graphql/queries.ts
  • src/store/atoms/location.subwayGpx.test.ts
  • src/utils/currentLineGroupStations.test.ts
  • src/utils/currentLineGroupStations.ts
  • src/utils/trainRouteTiming.test.ts
  • src/utils/trainRouteTiming.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

推定到着・出発時刻を使う走行計画を追加しました。オートモードは推定モデルの経路を取得し、クエリ失敗時は従来の経路クエリに切り替えます。GPX生成も共通の時間計画関数を使います。

Changes

推定時刻ベースの走行計画

Layer / File(s) Summary
区間時間と速度プロファイルの計算
src/utils/trainRouteTiming.ts, src/utils/trainRouteTiming.test.ts
駅の到着・出発時刻から区間走行時間と停車時間を計画する関数を追加しました。指定時間に合わせた速度プロファイルの計算と、そのテストも追加しました。
オートモードの経路取得と走行への反映
src/lib/graphql/queries.ts, src/hooks/useSimulationMode.ts, src/hooks/useSimulationMode.test.tsx, src/utils/currentLineGroupStations.ts, src/utils/currentLineGroupStations.test.ts
Estimatedモデルの経路クエリを追加しました。オートモードは推定時刻を走行計画に使い、Estimatedクエリが失敗した場合はLegacyクエリを使います。乗換駅の重複セグメントを統合する処理と関連テストも追加しました。
GPX生成での共通計算利用
scripts/generate-location-gpx.mjs, docs/location-simulation.md, src/store/atoms/location.subwayGpx.test.ts
GPX生成スクリプトを共通の時間計画関数に切り替えました。ドキュメントとテストのGPX点数・最大欠測時間の値を更新しました。

Priority: ➖ Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant useSimulationMode
  participant GraphQLAPI as GraphQL API
  participant trainRouteTiming
  useSimulationMode->>GraphQLAPI: Estimated経路クエリ
  GraphQLAPI-->>useSimulationMode: 推定時刻を含む経路、またはエラー
  alt Estimatedクエリがエラー
    useSimulationMode->>GraphQLAPI: Legacy経路クエリ
    GraphQLAPI-->>useSimulationMode: Legacy経路データ
  end
  useSimulationMode->>trainRouteTiming: 区間時間と速度プロファイルの計算
  trainRouteTiming-->>useSimulationMode: 計画時間と速度プロファイル
Loading

Merge Risk: ⚪ Minimal · up to 1f339

Auto mode now follows estimated arrival times and dwell times, and falls back to the previous behavior if the new query fails. No blocking issues were found; the change has not been tested on a device.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、オートモードを到着時間推定に合わせ、ETAおよびGPXと同じ時間で走行・停車させる主要変更を明確に示しています。
Description check ✅ Passed 概要、変更内容、変更種別、テスト結果、関連Issue、スクリーンショットの各項目を記載しています。必須テストの実行結果と、UI変更がない理由も明確です。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 9…
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
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


うさぎは時刻表をひらき
駅から駅へ秒を数える
列車は予定の時刻に走り
GPXの点も道をたどる
新しい計画に耳を揺らす

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

@TinyKitten
TinyKitten merged commit 94e721b into dev Oct 1, 2026
9 checks passed
@TinyKitten
TinyKitten deleted the feature/align-auto-mode-with-eta branch October 1, 2026 01:28
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