公開GTFS時刻表から速度較正テーブルを自動生成するスクリプトを追加 - #1592
Conversation
compute_average_distance.py と同じ validate/apply パターンで、公共交通 オープンデータセンター等の GTFS フィードから路線×種別ごとの実効最高速度を 較正する scripts/compute_speed_table.py を追加する。 - GTFS の stop_times から平日日中の列車ごとの所要時間を取り、駅名正規化+ 座標(500m/最近傍200m)で自リポジトリの駅データへ名寄せする - 停車パターンを station_station_types の種別グループと照合して kind を判定 - arrival_estimation.rs の運動学モデル(迂回係数較正・通過ペナルティ・ 運転余裕率込み)を Python で再現し、実ダイヤ所要時間の中央値を再現する 実効最高速度を二分探索でフィッティングする - 一般則(路線種別×種別倍率)から±10%以上乖離した路線だけを speed_table.rs の自動生成ブロック(手動テーブルと重複するキーは除外、 手動テーブル優先で lookup)へ書き込む フィード構成: 函館市電(認証不要)、京都市営地下鉄・横浜市営地下鉄 (要 ODPT_ACCESS_TOKEN、https://developer.odpt.org/ で無料発行)。 初回適用として函館市電の較正結果を収録: 市街地併用軌道の実勢に合わせ 2系統 20km/h・5系統 25km/h(一般則の路面電車 40km/h では所要時間を 40〜50% 過小評価していた)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsvFBx2rLj486tvj64M9eP
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsvFBx2rLj486tvj64M9eP
📝 WalkthroughWalkthroughODPT公開GTFS時刻表から路線×列車種別ごとの実効最高速度を較正するPythonスクリプト ChangesGTFSベースの速度較正パイプライン
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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 `@scripts/compute_speed_table.py`:
- Around line 269-287: In fetch_feed, the cache file is written directly and the
returned ZipFile is never closed, so a non-ZIP error response can be cached
permanently and keep causing BadZipFile failures. Update fetch_feed to write
into a temporary file, validate it as a ZIP before committing, then atomically
move it into CACHE_DIR with os.replace; also ensure callers such as main use a
with block around the ZipFile returned from fetch_feed so the handle is always
closed.
In `@stationapi/src/domain/speed_table.rs`:
- Around line 123-129: The gtfs_generated_entries_are_looked_up test only checks
presence via line_speed_override_kmh(...).is_some(), so it does not verify that
manual entries win when the same (line_cd, kind) exists in both manual and
GTFS-generated tables. Update this test in speed_table.rs to cover the
precedence rule by choosing or constructing a duplicate-key case and asserting
the manual-path value is returned by line_speed_override_kmh, using the existing
line_speed_override_kmh and gtfs_generated_entries_are_looked_up symbols to
locate the logic.
🪄 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: 5d1e38e1-1b3c-45d6-98f2-79e5cfb489d9
📒 Files selected for processing (3)
.gitignorescripts/compute_speed_table.pystationapi/src/domain/speed_table.rs
一時ファイルへ書いてZIP検証後に os.replace で確定し、ZipFile は with で クローズする。あわせて手動テーブル優先の lookup を回帰検知するテストを追加。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsvFBx2rLj486tvj64M9eP
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…0kfdt' into claude/eta-estimation-accuracy-j0kfdt
概要
速度較正テーブル(#1591)のフォローアップ。公共交通オープンデータセンター等の公開GTFS時刻表から路線×種別ごとの実効最高速度を自動較正する
scripts/compute_speed_table.pyを追加する(compute_average_distance.pyと同じ validate/apply パターン)。較正結果として函館市電・横浜市営地下鉄ブルーライン(快速)・京都市営地下鉄東西線ぶんを収録。変更の種類
変更内容
scripts/compute_speed_table.py(新規): GTFS のstop_timesから平日日中の列車ごとの所要時間を取り、arrival_estimation.rsの運動学モデル(迂回係数較正・通過ペナルティ・運転余裕率込み)を Python で再現して、実ダイヤ所要時間の中央値を再現する実効最高速度を二分探索でフィッティングする5!station_station_typesの種別グループと照合して kind を判定(全駅停車は Default)os.replaceで原子的に確定し、非 ZIP 応答(エラーボディ)を恒久キャッシュしてしまう事故を防ぐspeed_table.rs: 自動生成ブロック(LINE_SPEED_OVERRIDES_GTFS、マーカー間をスクリプトが再生成)を追加。手動テーブルと重複するキーはスクリプト側で除外し、lookup は手動テーブル優先(キー衝突時に手動値が返ることの回帰テストも追加).gitignoreにscripts/.gtfs_cache/(GTFSキャッシュ)と__pycache__/を追加フィード構成とライセンス:
ODPT_ACCESS_TOKEN必要ODPT_ACCESS_TOKEN必要トークンは https://developer.odpt.org/ で無料発行できます。京都・横浜ぶんの較正エントリは本PRに収録済みです(基本ライセンスのフィードを使うため、アプリのクレジット表記への出典追加が必要)。なお東武・京王のGTFSは「オープンデータチャレンジ限定ライセンス」のため対象外にしています。
テスト
cargo fmt --all -- --checkが通ることcargo clippy -- -D warningsが通ることcargo test(SQLX_OFFLINE=true)が通ること--applyを2回実行して出力が冪等であること、生成ブロックのエントリが lookup されることの単体テストも確認済み。関連Issue
スクリーンショット(任意)
🤖 Generated with Claude Code
https://claude.ai/code/session_01TsvFBx2rLj486tvj64M9eP
Generated by Claude Code
Summary by CodeRabbit
New Features
Bug Fixes