東急バスをGTFS・ODPT JSONから統合#1600
Conversation
大田区・品川区・目黒区のコミュニティバスGTFSと、東急バス一般路線の ODPT JSON (BusroutePattern/BusstopPole/BusTimetable) をGTFS相当へ変換して統合。 company_cd=254 東急バスを追加。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 10 seconds Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthrough東急バスのODPT JSONを取得・キャッシュし、GTFS相当のデータへ変換して既存テーブルへ投入する処理を追加しました。認証付きURL、gzip対応、会社コード、コミュニティ路線除外、関連ドキュメントも更新しています。 Changes東急バスデータ統合
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant import_gtfs
participant ODPT
participant TokyuCache
participant gtfs_tables
import_gtfs->>ODPT: Tokyu Bus JSONを取得
ODPT-->>import_gtfs: patterns/stops/timetables
import_gtfs->>TokyuCache: Tokyuデータをキャッシュ
import_gtfs->>gtfs_tables: agencies/routes/stops/trips/stop_timesを投入
gtfs_tables-->>import_gtfs: 取り込み完了
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
stationapi/src/import.rs (2)
933-961: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win
insert_tokyu_stop_valuesは手動エスケープした文字列連結でSQLを構築しています。sqlx::QueryBuilderを使ったバインドパラメータ方式のほうが安全です。
escape_sql_stringによるエスケープはテストされていますが、複数値INSERTを毎回文字列フォーマットで組み立てる方式は、将来のカラム追加やエスケープ漏れに弱い構造です。sqlx::QueryBuilder::push_valuesを使えば型安全なバインドで同等のバルクINSERTが実現できます。♻️ 提案: QueryBuilderでバルクINSERT
let mut qb = sqlx::QueryBuilder::new( "INSERT INTO gtfs_stops (stop_id, stop_code, stop_name, stop_name_k, stop_name_r, stop_lat, stop_lon) ", ); qb.push_values(rows, |mut b, (stop_id, code, name, name_k, lat, lon)| { b.push_bind(stop_id) .push_bind(code) .push_bind(name) .push_bind(name_k) .push_bind(None::<String>) .push_bind(lat) .push_bind(lon); }); qb.push(" ON CONFLICT (stop_id) DO NOTHING"); qb.build().execute(&mut *conn).await?;Also applies to: 1063-1077
🤖 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/import.rs` around lines 933 - 961, Replace the manual SQL string construction used by insert_tokyu_stop_values with sqlx::QueryBuilder::push_values and bound parameters for every stop column, retaining the existing bulk batching and ON CONFLICT behavior. Update the corresponding stop insertion flow at the additional location as well, and remove reliance on escape_sql_string for these inserts.
488-554: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winキャッシュディレクトリの解決方法がコンパイル時パスに依存しており、実行環境によって破綻するリスクがあります。
env!("CARGO_MANIFEST_DIR")はコンパイル時にビルド環境の絶対パスを埋め込むマクロです。一方、同ファイル内の他のGTFSフィード (data/ToeiBus-GTFSなど、download_gtfs) は実行時のカレントディレクトリからの相対パスで解決しています。ビルド環境と実行環境のファイルシステムレイアウトが異なる場合(例: マルチステージDockerビルドでバイナリだけを別イメージにコピーする構成へ将来変更した場合など)、cache_dirがビルド時の絶対パスを指し続け、fs::metadata/fs::create_dir_allが失敗する可能性があります。他のフィードと同様に実行時カレントディレクトリ相対のパスに統一することを推奨します。♻️ 提案: 他フィードと同様に実行時相対パスに統一
- let cache_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../data/TokyuBus-ODPT"); + let cache_dir = Path::new("data/TokyuBus-ODPT");現在のDocker構成(
docker/api/Dockerfileが同一イメージ内でcargo buildとdata/コピーを行う想定)では問題にならない可能性がありますが、将来のビルド構成変更に対して脆弱です。Dockerfileの実際の構成を確認いただけますか。🤖 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/import.rs` around lines 488 - 554, Update the cache_dir initialization in download_odpt_json to resolve TokyuBus-ODPT from the runtime current working directory, matching the relative-path behavior used by download_gtfs and the other GTFS feeds. Remove the compile-time env!("CARGO_MANIFEST_DIR") dependency while preserving the existing cache read and write flow.
🤖 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 `@stationapi/src/import.rs`:
- Around line 916-929: Update the gtfs_routes INSERT in the inserted_routes
block to bind route_long_name_r separately from route_long_name_r, storing NULL
for route_long_name_r because tokyu_route_name returns Japanese text. In
insert_tokyu_stop_values, likewise store NULL in stop_name_r instead of
stop.title, while preserving the Japanese values in the non-_r name columns and
existing fallback behavior.
---
Nitpick comments:
In `@stationapi/src/import.rs`:
- Around line 933-961: Replace the manual SQL string construction used by
insert_tokyu_stop_values with sqlx::QueryBuilder::push_values and bound
parameters for every stop column, retaining the existing bulk batching and ON
CONFLICT behavior. Update the corresponding stop insertion flow at the
additional location as well, and remove reliance on escape_sql_string for these
inserts.
- Around line 488-554: Update the cache_dir initialization in download_odpt_json
to resolve TokyuBus-ODPT from the runtime current working directory, matching
the relative-path behavior used by download_gtfs and the other GTFS feeds.
Remove the compile-time env!("CARGO_MANIFEST_DIR") dependency while preserving
the existing cache read and write flow.
🪄 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: CHILL
Plan: Pro
Run ID: f74c6699-78a6-4a8c-871f-9f1eee2cb166
⛔ Files ignored due to path filters (2)
Cargo.lockis excluded by!**/*.lockdata/1!companies.csvis excluded by!**/*.csv
📒 Files selected for processing (6)
.gitignoreAGENTS.mdREADME.mddocs/architecture.mdstationapi/Cargo.tomlstationapi/src/import.rs
Fixes Applied SuccessfullyFixed 1 file(s) based on 1 CodeRabbit feedback item(s). Files modified:
Fix: Commit: The latest autofix changes are on the |
devに先行マージされた京王バスGTFS統合(#1601, #1602)と東急バス統合の コンフリクトを解消。 - data/1!companies.csv / import.rs: 京王バスがcompany_cd=254を先に取得済み のため、東急バスをcompany_cd=254から255へ振り直して衝突を回避 (company_cd_for_gtfs_route・gtfs_agencies INSERT・関連テストを更新) - import.rs: トークン付与ヘルパーを両ブランチ重複追加していたため、 devのappend_consumer_key(url, token)に統一しgtfs_download_url_with_token を削除。呼び出し箇所とテストを追従 - GTFS_FEEDS: 東急コミュニティバス3フィードと京王バスの両方を保持 - .gitignore / AGENTS.md / README.md / docs/architecture.md: 両ブランチのバス統合記述・データ提供元・無視対象を統合 検証: cargo fmt --check / cargo clippy -D warnings / cargo test (SQLX_OFFLINE=true, 36 passed) / cargo run -p data_validator ([VALID]) 通過 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNY8jqgNN2xpnRSrK758h8
|
@coderabbitai review |
✅ Action performedReview finished.
|
概要
東急バスを StationAPI に統合する。大田区・品川区・目黒区のコミュニティバスは公式 GTFS フィードから、東急バスの一般路線は ODPT の JSON API (
BusroutePattern/BusstopPole/BusTimetable) を GTFS 相当の表現へ変換して取り込む。変更の種類
変更内容
stationapi/src/import.rs:GTFS_FEEDSに追加。URL はdate=current・ODPT_ACCESS_TOKEN必須。BusroutePattern/BusstopPole/BusTimetable)をダウンロードし、gtfs_*テーブルへ変換して取り込むimport_tokyu_odpt_data()を追加。パターン ID をshape_idとして扱い、路線バリエーションをバス TrainType として保持。DeserializeSeedで東急バス分のみ抽出し、7 日間キャッシュをdata/TokyuBus-ODPT/に保存。HH:MM形式の ODPT 時刻を GTFS のHH:MM:SSへ整えるparse_odpt_time()を追加。company_cd_for_gtfs_route()にtokyu_プレフィックス(company_cd=254)を追加。gtfs_download_url_with_token()を追加。data/1!companies.csv:company_cd=254東急バス(東急バス株式会社)を追加。stationapi/Cargo.toml/Cargo.lock:reqwestにgzipfeature を追加(async-compression依存を追加)。.gitignore: 東急バス関連の GTFS / キャッシュディレクトリを追加。AGENTS.md/docs/architecture.md/README.md: 東急バス統合とデータ提供元の記載を追記。テスト
cargo fmt --all -- --checkが通ることcargo clippy -- -D warningsが通ることcargo test(SQLX_OFFLINE=true)が通ることSQLX_OFFLINE=true cargo testは 35 passed / 0 failed。データ変更を含むためcargo run -p data_validatorも実行し[VALID] No errors reported.を確認。関連Issue
スクリーンショット(任意)
Summary by CodeRabbit