Skip to content

到着時間推定に運転余裕率を導入し実ダイヤとの系統誤差を補正する - #1577

Merged
TinyKitten merged 1 commit into
devfrom
claude/estimate-arrival-times-accuracy-dfg2b6
Jul 1, 2026
Merged

TinyKitten merged 1 commit into
devfrom
claude/estimate-arrival-times-accuracy-dfg2b6

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

概要

EstimateArrivalTimes の運動学モデルが理想走行(最大加速→最高速度で巡航→最大減速)を仮定しているため、実ダイヤに含まれる途中の速度制限・惰行・回復余裕のぶん全路線で所要時間を13〜25%過小に見積もっていた問題を、実時刻表との較正で補正する。

#1576 以前は迂回係数が上限1.6に張り付くバグによる距離水増しが偶然この過小評価を相殺していたため、バグ修正後に過小評価が顕在化していた(例: 都営大江戸線 落合南長崎→光が丘 実車11分に対し8.9分)。

変更の種類

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

変更内容

  • 走行時間に運転余裕率 run_margin(既定 1.15)を導入。segment_run_minutes と assign_segment_times の両経路で走行時間のみに乗算し、停車時間には掛けない
  • 中間停車駅の停車時間 dwell_minutes を 0.4分 → 0.6分(出発余裕込みの実効値)に変更
  • 在来線の基本最高速度を 85km/h → 80km/h に変更(地下鉄75・新幹線250などは据え置き)
  • パラメータは実時刻表が既知の6区間(都営大江戸線 落合南長崎→光が丘、銀座線 浅草→渋谷、丸ノ内線 池袋→荻窪、山手線 池袋→東京、中央・総武線各停 三鷹→新宿、両毛線 伊勢崎→国定)とのグリッドサーチで較正。検証セットの平均絶対誤差は 16.7% → 約3%
  • 大江戸線 落合南長崎→光が丘 の実座標・実測時刻(2/5/7/9/11分)を使い、各駅の推定が±1分以内に収まることを検証する回帰テストを追加
  • 代表値: 大江戸線 落合南長崎→光が丘 8.9分 → 10.8分(実車11分)、両毛線 伊勢崎→国定 4.5分 → 5.4分(実車5〜6分)

テスト

  • cargo fmt --all -- --check が通ること
  • cargo clippy -- -D warnings が通ること
  • cargo test(SQLX_OFFLINE=true)が通ること

関連Issue

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01SvuzKrssremkx9vuHTu7BZ


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • 列車の到着予測で、走行時間に補正係数を適用できるようになりました。
    • 予測の既定値が見直され、より実運行に近い見積もりになりました。
  • バグ修正

    • 区間ごとの時刻割り当てで、走行時間の算出がより一貫するよう改善しました。
    • 一部路線の予測精度を調整し、回帰の起きやすい区間の挙動を安定化しました。

運動学モデルは「最大加速→最高速度で巡航→最大減速」の理想走行を仮定するため、
実ダイヤに含まれる途中の速度制限・惰行・回復余裕のぶん、全路線で所要時間を
13〜25%過小に見積もっていた(旧実装では迂回係数が1.6に張り付くバグが偶然
これを相殺していたため、修正後に過小評価が顕在化した)。

実時刻表が既知の6区間(都営大江戸線 落合南長崎→光が丘、銀座線 浅草→渋谷、
丸ノ内線 池袋→荻窪、山手線 池袋→東京、中央・総武線各停 三鷹→新宿、
両毛線 伊勢崎→国定)で較正し、以下を調整:

- 走行時間に運転余裕率 run_margin(1.15)を導入
- 中間停車時間 dwell を 0.4分 → 0.6分(出発余裕込みの実効値)
- 在来線の基本最高速度を 85km/h → 80km/h

検証セットの平均絶対誤差は 16.7% → 約3% に改善。
大江戸線 落合南長崎→光が丘 は 8.9分 → 10.8分(実車11分)、
両毛線 伊勢崎→国定 は 4.5分 → 5.4分(実車5〜6分)となる。

大江戸線の実座標・実測時刻を使った回帰テストを追加。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvuzKrssremkx9vuHTu7BZ
@TinyKitten TinyKitten self-assigned this Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

到着時刻推定モデルのEstimationParamsにrun_margin(走行余裕率)フィールドを追加し、走行時間計算に補正係数として適用しました。併せてdwell_minutesの既定値と路線種別未定義時の基本最高速度を変更し、テストの期待値を新パラメータに合わせて更新しました。

Changes

run_margin導入と走行時間補正

Layer / File(s) Summary
モデル説明とパラメータ定義の更新
stationapi/src/domain/arrival_estimation.rs
モデル説明コメントに運転余裕率の注記を追加し、EstimationParamsにrun_margin: f64フィールドを新設。
既定値と基本最高速度の変更
stationapi/src/domain/arrival_estimation.rs
EstimationParams::default()のdwell_minutesを0.4から0.6に、run_marginを1.15に設定し、基本最高速度のフォールバックを85.0から80.0に変更。
走行時間計算へのrun_margin適用
stationapi/src/domain/arrival_estimation.rs
segment_run_minutesおよびassign_segment_timesの分数計算にparams.run_marginを乗じるよう変更。
テストの追加・調整
stationapi/src/domain/arrival_estimation.rs
run_marginのスケーリングを検証する新テストを追加し、既存回帰テストの期待値・速度パラメータを更新。

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

Possibly related PRs

  • TrainLCD/StationAPI#1572: 同ファイルの到着推定における速度・補正係数計算ロジックを再設計している点で関連。

Suggested labels: feature

Poem

にんじん片手に走行余裕率、
1.15倍でぴょんと跳ねる速度計。
60分の60秒、その先に補正あり、
テストも新たに整えたよ、ぴょこぴょこ確認。
🐰 到着時刻、今日も少し丁寧に。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 運転余裕率の導入と実ダイヤとの差の補正という主変更を簡潔に表しています。
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/estimate-arrival-times-accuracy-dfg2b6

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)
stationapi/src/domain/arrival_estimation.rs (1)

478-486: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Clippy の field_reassign_with_default を回避するため構造体リテラルで初期化してください。

EstimationParams::default() の直後に p.run_margin = ... で上書きする書き方は、Clippy の field_reassign_with_default(warn-by-default)で警告されます。コーディングガイドラインに従い、新規 Clippy 警告は解消してください。

♻️ 提案する修正
-        let mut p = EstimationParams::default();
-        p.run_margin = 1.0;
-        let base = segment_run_minutes(5_000.0, 80.0, &p);
-        p.run_margin = 1.15;
-        let with_margin = segment_run_minutes(5_000.0, 80.0, &p);
+        let base = segment_run_minutes(
+            5_000.0,
+            80.0,
+            &EstimationParams { run_margin: 1.0, ..Default::default() },
+        );
+        let with_margin = segment_run_minutes(
+            5_000.0,
+            80.0,
+            &EstimationParams { run_margin: 1.15, ..Default::default() },
+        );
         approx(with_margin, base * 1.15);

As per coding guidelines: "Run cargo clippy --all-targets --all-features before committing. Resolve new Clippy warnings unless an existing #![allow] covers the case."

🤖 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 `@stationapi/src/domain/arrival_estimation.rs` around lines 478 - 486, The test
in run_margin_scales_run_time_but_not_dwell should avoid Clippy’s
field_reassign_with_default warning by not creating EstimationParams with
default() and then mutating run_margin. Update the setup in this test to
initialize EstimationParams with a struct literal (using default values for the
other fields as needed) and use that value for the two segment_run_minutes
calls, keeping the same assertions.

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.

Nitpick comments:
In `@stationapi/src/domain/arrival_estimation.rs`:
- Around line 478-486: The test in run_margin_scales_run_time_but_not_dwell
should avoid Clippy’s field_reassign_with_default warning by not creating
EstimationParams with default() and then mutating run_margin. Update the setup
in this test to initialize EstimationParams with a struct literal (using default
values for the other fields as needed) and use that value for the two
segment_run_minutes calls, keeping the same assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00dc9157-973f-4b02-900c-1c30d7bab34d

📥 Commits

Reviewing files that changed from the base of the PR and between 390b566 and 3a34d05.

📒 Files selected for processing (1)
  • stationapi/src/domain/arrival_estimation.rs

@TinyKitten
TinyKitten merged commit 55d9eeb into dev Jul 1, 2026
11 checks passed
@TinyKitten
TinyKitten deleted the claude/estimate-arrival-times-accuracy-dfg2b6 branch July 1, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants