Skip to content

到着時間推定(ETA)機能の一連の改善をmasterへ反映 - #1582

Merged
TinyKitten merged 17 commits into
masterfrom
dev
Jul 3, 2026
Merged

到着時間推定(ETA)機能の一連の改善をmasterへ反映#1582
TinyKitten merged 17 commits into
masterfrom
dev

Conversation

@TinyKitten

Copy link
Copy Markdown
Member

概要

dev に溜まっていた到着時間推定(ETA)機能の一連の改善(#1563#1581)を master へ反映する。監視スタックの削除・ECSデプロイワークフローの削除・gRPC APIの拡張も含む。

変更の種類

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

変更内容

到着時間推定(ETA)関連

インフラ・CI

その他

テスト

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

関連Issue

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

TinyKitten and others added 17 commits June 29, 2026 23:18
* 予定到着時間(累積分数)推定をEstimateArrivalTimes RPCで公開

gRPCProto submoduleを更新し、EstimateArrivalTimes RPCと
EstimatedArrivalResponse/Route/Stopメッセージを追加。
gRPCコントローラに既存のestimate_route_arrival_timesユースケースへの
結線を実装し、経路ごとにグルーピングしたレスポンスを返す。

Closes #1562

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* rustfmt: import順をアルファベット順に修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: line_group_cdがNoneの経路を誤マージしないよう防御的に修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* clippy: map_orをis_some_andに修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* 平均駅間距離をOSM線路ジオメトリから実距離で再計算するスクリプトを追加

average_distance は従来「駅座標の直線距離 × 路線種別ごとの固定係数(1.05〜1.25)」
という推定値だった。OpenStreetMap のルート関係から当該路線の線路ジオメトリを取得し、
隣接駅間を線路に沿って経路探索することで実際の平均駅間距離を求める
scripts/compute_average_distance.py を追加する。

- 路線名+カバレッジ(全駅≤200m)でルート関係を厳密にマッチング
- 各駅を半径70m内の全ノードに対応付けた多始点・多終点ダイクストラで複線/環状にも対応
- 経路不能/妥当範囲外の区間や、関係が取れない路線は従来式の推定値にフォールバック
- 取得したOSMデータはローカルキャッシュ

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUVEm4aJvtViD1agkwLV8g

* average_distance を OSM 線路ジオメトリに基づく実距離へ更新

路線情報CSVの average_distance を、従来の「駅座標の直線距離 × 固定係数」推定値から、
OpenStreetMap の線路ジオメトリに沿って計算した実際の平均駅間距離へ置き換える。
全601路線中503路線を実距離で更新し、OSMルート関係が取得できない98路線は従来式の
推定値にフォールバックした(average_distance 列のみ変更)。

算出ロジック改善:
- 駅を線路セグメントへ投影し、投影点間の線路沿い距離を多始点・多終点ダイクストラで測定
- 実距離は駅間直線距離を下限として丸め(駅が線路から横にずれることによる過小評価を防止)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUVEm4aJvtViD1agkwLV8g

* レビュー指摘対応: relation判定の精度向上・失敗区間の推定・lint修正

CodeRabbit のレビュー指摘に対応する scripts/compute_average_distance.py の修正。

- relation のカバレッジ判定を way 頂点距離から線分への投影距離(_project_to_segment)へ変更。
  長い線分の途中にある駅を過大に遠いと誤判定して有効な relation を取りこぼし、
  不要なフォールバックになるのを防ぐ。
- 経路探索に失敗した区間を直線距離そのまま(実距離の下限)で代替すると平均が過小評価
  されるため、旧来式(直線距離 x 固定係数)で軌道距離を推定するよう変更。
- main() の内包表記のあいまいな変数名 l を line にリネーム(Ruff E741)。

同一線分上の2駅を投影点間で直接結ぶ指摘は、隣接駅間(通常1km以上)が単一の線路セグメント
(通常数十m)上に乗ることは実質起こらず、MAX_RATIO ガードで過大値も弾けるため見送り。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUVEm4aJvtViD1agkwLV8g

* average_distance を改善ロジックで再生成し docstring を追加

レビュー対応で改善した算出ロジック(relation カバレッジの線分投影判定、失敗区間の
旧来式推定)で data/2!lines.csv の average_distance を再生成。OSM 実距離で算出できる
路線が 503 から 508 に増加(フォールバックは 98 から 93 に減少)。
更新後の平均駅間距離/直線距離は中央値 1.042・最大 1.437・直線未満 0 件。

あわせて scripts/compute_average_distance.py の未記載関数に docstring を追加
(docstring カバレッジ 36% -> 84%)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUVEm4aJvtViD1agkwLV8g

* コメントの全角括弧をASCII括弧に修正 (Ruff RUF003)

format_distance 内コメントの全角括弧が Ruff RUF003 で検出されるため ASCII 括弧に置換。
コメントのみの変更で算出ロジックや出力値に影響なし。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUVEm4aJvtViD1agkwLV8g

---------

Co-authored-by: Claude <noreply@anthropic.com>
* 予定到着時間(累積分数)推定をEstimateArrivalTimes RPCで公開

gRPCProto submoduleを更新し、EstimateArrivalTimes RPCと
EstimatedArrivalResponse/Route/Stopメッセージを追加。
gRPCコントローラに既存のestimate_route_arrival_timesユースケースへの
結線を実装し、経路ごとにグルーピングしたレスポンスを返す。

Closes #1562

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* rustfmt: import順をアルファベット順に修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: line_group_cdがNoneの経路を誤マージしないよう防御的に修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* clippy: map_orをis_some_andに修正

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: GetTrainRoute gRPCクエリを追加(走行シミュレーション用)

A駅→B駅を指定列車種別(line_group_id)で走行する際の各駅情報を
1リクエストで返すGetTrainRouteを実装。各駅に停車/通過フラグ・
直前駅からの距離(m, Haversine)・最高速度/加減速度(SI単位)を
付与し、MobileAppのuseSimulationModeが端末内で行っていた
経路・速度プロファイル準備をサーバ側に集約する。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: EstimateArrivalTimes関連コードを除去(別PRで実装)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* rustfmt: 末尾の余分な空行を除去

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: MockQueryUseCaseにestimate_route_arrival_timesを追加

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* EstimateArrivalTimesの入力をstation_idに変更しvia_line_idsを配列化

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* gRPCProto サブモジュールを bump

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* get_route_stopsのSQLをstation_g_cdに戻しEstimateArrivalTimes専用のget_route_stops_by_station_cdを新設

get_routes/get_routes_minimal/get_train_typesはstation_group_idを受け取るため
station_g_cdで検索する必要がある。station_cdで検索するのはEstimateArrivalTimes専用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
LINE_TYPE_SHINKANSENの値を実データに合わせて7→1に修正し、
路線種別ごとの基本速度(新幹線250/地下鉄75/路面電車40/AGT60/ケーブル12/在来線85km/h)と
迂回係数(新幹線1.15/地下鉄1.20/路面電車1.40/AGT1.20/ケーブル1.10/在来線1.30)を設定。
速達種別は基本速度×1.2で算出するように変更。


Claude-Session: https://claude.ai/code/session_01Ag6fgiLJj5ExLa9bqnfAhj

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* EstimateArrivalTimesの結果を始点から終点までの区間に絞り込む

group_stopsのfrom/to位置を検出しても範囲でスライスしておらず、
経路上の全駅を返していたバグを修正

* テストのstation_cdとstation_g_cdを別値にしてIDの取り違えを検出可能にする

CodeRabbitの指摘に対応: station_cd=station_g_cdだとlookupロジックの
station_cd/station_g_cd混同バグを検出できないため区別する

* estimate_route_arrival_timesにdocstringを追加

CodeRabbitのDocstring Coverageチェック(75% < 80%)対応
運動学モデルは「最大加速→最高速度で巡航→最大減速」の理想走行を仮定するため、
実ダイヤに含まれる途中の速度制限・惰行・回復余裕のぶん、全路線で所要時間を
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分)となる。

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


Claude-Session: https://claude.ai/code/session_01SvuzKrssremkx9vuHTu7BZ

Co-authored-by: Claude <noreply@anthropic.com>
* EstimatedArrivalStopに累積出発時刻を追加しクライアントが発車基準ETAを計算できるようにする

始点からの累積出発時刻 departure_cumulative_minutes を EstimatedStop に追加。
中間停車駅では「到着 + 停車時間(dwell)」、通過駅では通過時刻、終点では
到着時刻と同じ値を返す。クライアントは「到着(k) − 出発(基準駅)」で
基準駅の発車を基準とした正確な残り時間を計算できる。

gRPCProto 側の EstimatedArrivalStop に
double departure_cumulative_minutes = 5; の追加が必要(別リポジトリ)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G5CBXke7dskNEHsP8BN8HM

* gRPCProtoをdeparture_cumulative_minutes追加後のコミットに更新

---------

Co-authored-by: Claude <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: db1ef082-9e7f-496f-b106-a94edbd2f4e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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

@TinyKitten
TinyKitten merged commit 9e675ec into master Jul 3, 2026
15 checks passed
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.

1 participant