Skip to content

direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正#1373

Merged
TinyKitten merged 2 commits into
devfrom
claude/fix-bus-stop-response-0Oz9F
Jan 7, 2026
Merged

direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正#1373
TinyKitten merged 2 commits into
devfrom
claude/fix-bus-stop-response-0Oz9F

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jan 7, 2026

Copy link
Copy Markdown
Member

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

Summary by CodeRabbit

リリースノート

  • バグ修正
    • ルート変種に属する停留所の取扱いを改善しました。これまではある方向IDに紐づかない停留所が除外されるケースがありましたが、今回の修正でそうした停留所も適切に考慮され、隣接する停留所情報がある場合は優先的に配置されるようになり、ルート表現の一貫性と完全性が向上しました。

✏️ Tip: You can customize this high-level summary in your review settings.

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。
@coderabbitai

coderabbitai Bot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

ウォークスルー

stationapi/src/import.rsbuild_stop_route_mappingで、バリアント停留所の選別ロジックが変更され、非NULLのdirection_idを持つトリップの存在を必須とするフィルタ(EXISTS句)が削除されました。代わりにmain_trip_stopsへのLEFT JOINを用い、隣接停留所の有無に基づく優先順位付けを行うORDER BYを追加しています。

変更内容

コホート / ファイル(s) 変更内容
クエリロジック変更
stationapi/src/import.rs
build_stop_route_mappingのクエリからEXISTS/フィルタを削除。main_trip_stopsへのLEFT JOINを追加し、prev/next隣接情報の有無でソートする優先順位付きORDER BYを導入。主系停留所を除外するNOT EXISTSは維持。

シーケンス図

(該当なし)

推定コード レビュー手数

🎯 3 (Moderate) | ⏱️ ~20 minutes

ポエム

🐰 クエリの扉をそっと開けて、
見えなかった停留所が顔を出すよ。
LEFT JOINで隣を確かめ、順序を整え、
小道も大通りも歌い始める。
新しい地図でぴょんと一歩! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルはPRの主要な変更内容を正確に反映しており、direction_idがNULLのトリップに存在するバス停の取り込みに関する修正という核心を明確に表現している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f206adb and 82a2010.

📒 Files selected for processing (1)
  • stationapi/src/import.rs
🧰 Additional context used
📓 Path-based instructions (2)
stationapi/src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Run cargo test --lib --package stationapi or make test-unit for unit tests focusing on entities and repository mocks without database

Files:

  • stationapi/src/import.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Before committing, run cargo fmt on all Rust code
Before committing, run cargo clippy --all-targets --all-features and resolve new Clippy warnings unless covered by existing #![allow] attributes

Files:

  • stationapi/src/import.rs
🧠 Learnings (1)
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`

Applied to files:

  • stationapi/src/import.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Suite
  • GitHub Check: Test Suite
🔇 Additional comments (1)
stationapi/src/import.rs (1)

1578-1871: I need the review comment to rewrite. Please provide the original review comment within <review_comment> tags or share the feedback you'd like me to verify and rewrite.


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

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

@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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
stationapi/src/import.rs (1)

1639-1666: direction_idがNULLのトリップに存在するバス停を正しく取り込む修正を承認します。

この変更により、以下の改善が実現されます:

  1. NULL direction_idトリップの包含: variant_only_with_neighborsCTE内にdirection_id IS NOT NULLフィルタがないため、NULL direction_idのトリップにのみ存在するバス停(原宿駅前など)が正しく含まれるようになります。

  2. 優先順位ベースの選択: LEFT JOINで隣接バス停がメイントリップに存在するかをチェックし、CASE式で優先順位付けすることで、位置推定の精度が最も高いレコードを選択します:

    • 優先度0: 両隣がメイントリップに存在(最良の位置推定)
    • 優先度1: 片隣がメイントリップに存在
    • 優先度2: どちらの隣もメイントリップに存在しない
  3. GTFS仕様への準拠: direction_idはオプショナルフィールドであるというGTFS仕様に正しく対応しています。

実装は論理的に正確で、DISTINCT ONとORDER BYの組み合わせにより、各(parent_stop_id, route_id)ペアに対して最適なレコードが選択されます。

コミット前に以下のコマンドを実行してください:

  • cargo fmt で Rust コードをフォーマット
  • cargo clippy --all-targets --all-features で警告を確認
  • cargo test --lib --package stationapi で単体テストを実行
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f206adb and 82a2010.

📒 Files selected for processing (1)
  • stationapi/src/import.rs
🧰 Additional context used
📓 Path-based instructions (2)
stationapi/src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Run cargo test --lib --package stationapi or make test-unit for unit tests focusing on entities and repository mocks without database

Files:

  • stationapi/src/import.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Before committing, run cargo fmt on all Rust code
Before committing, run cargo clippy --all-targets --all-features and resolve new Clippy warnings unless covered by existing #![allow] attributes

Files:

  • stationapi/src/import.rs
🧠 Learnings (1)
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`

Applied to files:

  • stationapi/src/import.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Suite
  • GitHub Check: Test Suite
🔇 Additional comments (1)
stationapi/src/import.rs (1)

1578-1871: I need the review comment to rewrite. Please provide the original review comment within <review_comment> tags or share the feedback you'd like me to verify and rewrite.

@TinyKitten TinyKitten merged commit 1094d30 into dev Jan 7, 2026
10 checks passed
@TinyKitten TinyKitten deleted the claude/fix-bus-stop-response-0Oz9F branch January 7, 2026 12:58
TinyKitten added a commit that referenced this pull request Jan 8, 2026
* SQLの致命的なバグをいくつか修正 (#1371)

* ひらがな混じりで駅検索ができないバグを修正

* get_train_types_by_station_idが動かないバグを修正

* GetStationsByLineGroupIdの修正

* ユニットテスト拡充

* cargo fmt

* バス路線はline_typeをOtherLineTypeに強制 (#1372)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正 (#1373)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

* バリアントバス停の位置推定でメイントリップに存在する隣接バス停を優先

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

---------

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
TinyKitten added a commit that referenced this pull request Mar 6, 2026
* master<-dev (#1337)

* GetRoutesMinimal RPCを実装 (#1334)

* Add minimal route retrieval functionality and related proto types

* Refactor code formatting for improved readability in grpc.rs and query.rs

* Add line symbols to LineMinimal in get_lines_by_station_group_id

* Update subproject commit reference in stationapi/proto

* Add get_lines_by_id_list method and update QueryUseCase trait

* Refactor import order for improved readability in grpc.rs

* Use entry method for inserting line_minimal in all_lines to avoid overwriting

* Refactor route_row_tree_map creation into a separate build_route_tree_map method for improved readability

* Enhance line symbol handling in QueryInteractor: populate line_symbols for all lines and update line_minimal entries conditionally

* Refactor line symbol handling in QueryInteractor: update all_lines conditionally based on line_symbols presence

* Add AGENTS.md for automation agent and contributor workflow guidelines

* Update AGENTS.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* 石橋阪大前駅ローカライズ修正 (#1336)

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* master<-dev (#1374)

* SQLの致命的なバグをいくつか修正 (#1371)

* ひらがな混じりで駅検索ができないバグを修正

* get_train_types_by_station_idが動かないバグを修正

* GetStationsByLineGroupIdの修正

* ユニットテスト拡充

* cargo fmt

* バス路線はline_typeをOtherLineTypeに強制 (#1372)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正 (#1373)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

* バリアントバス停の位置推定でメイントリップに存在する隣接バス停を優先

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

---------

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>

* 西鉄データ更新 (#1375)

* 春日原駅を特急停車駅に指定

* 聖マリア病院前の駅名修正

* master<-dev (#1391)

* GetStationsByLineIdList RPC追加

複数のline_idを一括で処理するバッチRPCを追加。
既存のGetStationByIdList/GetLineByIdListと同じバッチパターンに従う。

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

* cargo fmt

* get_by_line_id_vecのORDER BYを入力順序保持のCASE式に変更

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

* Merge pull request #1389 from TrainLCD/feature/tt-batch

GetStationsByLineGroupIdList RPC追加

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット (#1390)

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット

N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで
複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station
の両方にセットするよう修正。

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

* get_stations_by_line_group_id_vecのユニットテストを追加

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

* ネストされた駅のtrain_typeをis_some()で明示的に検証するよう修正

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

* train_typeをtrain_type_mapから常に上書きしてリーク防止

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* 近鉄種別修正

* 近鉄種別修正

駅コード修正

---------

Co-authored-by: Tsubasa SEKIGUCHI <oss@tinykitten.me>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants