Skip to content

EstimateArrivalTimesの結果を始点から終点までの区間に絞り込む - #1575

Merged
TinyKitten merged 3 commits into
devfrom
fix/estimate-arrival-times-station-range
Jul 1, 2026
Merged

TinyKitten merged 3 commits into
devfrom
fix/estimate-arrival-times-station-range

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

概要

EstimateArrivalTimes RPC が、from_station_id から to_station_id までの区間ではなく、経路(line_group_cd/line_cd)上の全駅の到着時間を返してしまっていたバグを修正しました。

変更の種類

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

変更内容

  • estimate_route_arrival_times(stationapi/src/use_case/interactor/query.rs)で、経路候補(group_stops)内の from_station_id / to_station_id の位置を検出した後、その範囲でスライスせずに経路全体を推定関数に渡していたバグを修正
  • 両端点の位置(fi, ti)が両方見つかった場合のみ対象とし、fi < ti ならそのままスライス、fi > ti なら区間を反転して from→to 順に並べ替えるように統一(direction_id の有無に関わらず一貫して範囲を絞り込む)
  • 上記修正を検証するテストを2件追加
    • 範囲外の駅(要求区間の前後にある駅)が結果に含まれないことを確認するテスト
    • direction_id 指定時に fi > ti となる逆順ケースで、範囲外の駅が除外されつつ from→to 順に反転されることを確認するテスト
  • cargo sqlx prepare --workspace により不要になったクエリキャッシュ2件を削除

テスト

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

関連Issue

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

Summary by CodeRabbit

  • バグ修正
    • 出発〜到着の指定区間に含まれる駅のみを対象に、到着時刻の推定結果へ反映するよう改善しました。
    • 出発駅と到着駅の順序が逆の場合でも、結果の駅並びが常に出発→到着の順になるよう修正しました。
  • テスト
    • 区間外の駅が返らないこと、逆方向でも正しく絞り込まれ、順序と先頭の累積分が期待どおりになることを確認するテストを追加・更新しました。

group_stopsのfrom/to位置を検出しても範囲でスライスしておらず、
経路上の全駅を返していたバグを修正
@TinyKitten TinyKitten self-assigned this Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b63e3d5-e0cf-4776-a9f0-2f6b766b60d9

📥 Commits

Reviewing files that changed from the base of the PR and between e7f354d and 7cd4466.

📒 Files selected for processing (1)
  • stationapi/src/use_case/interactor/query.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • stationapi/src/use_case/interactor/query.rs

📝 Walkthrough

Walkthrough

estimate_route_arrival_times の推定対象が、group_stops 全体から from/to の両端を含む区間に限定された。from_pos/to_pos の確認と同一駅の除外が追加され、順方向・逆方向ともに from→to 順で推定するよう変更された。対応テストも追加された。

Changes

区間限定ロジックとテスト

Layer / File(s) Summary
from/to区間限定ロジックの実装
stationapi/src/use_case/interactor/query.rs
from_pos/to_pos を特定し、両端が存在しない場合や同一駅の場合は除外するよう変更。全体対象の分岐をやめ、from→to 区間のみをスライスまたは反転して estimate_arrival_minutes に渡すよう更新。
区間外駅除外の検証テスト
stationapi/src/use_case/interactor/query.rs
要求区間外の駅が結果に含まれないこと、逆方向でも direction_id 指定下で区間が反転して from→to 順になることを検証するテストを追加。

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

Possibly related PRs

Poem

ぴょんと区間をひとまたぎ
from から to へ すっきり進む
余分な駅はそっと外して
逆向きでも順番はきれい
うさぎも安心、テストで確認 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 変更内容の主軸であるEstimateArrivalTimesの区間絞り込み修正を簡潔に表しており、タイトルとして適切です。
Description check ✅ Passed 概要、変更内容、テストがテンプレートに沿って整理されており、必須項目も概ね揃っています。
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 fix/estimate-arrival-times-station-range

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

@github-actions github-actions Bot added fix 直した deploy-dev and removed fix 直した labels Jul 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

@TinyKitten I'll review the changes now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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/use_case/interactor/query.rs (1)

2413-2429: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

station_cd と station_g_cd を分けたデータで検証してください。

実装は station_cd で端点を探していますが、このテストデータは station_cd == station_g_cd なので、ID種別の取り違えを検出できません。station_cd を 102/103/104、station_g_cd を 2/3/4 のように分け、呼び出しは station_cd、返却順の検証は station_g_cd のままにすると回帰検出力が上がります。

Also applies to: 2445-2463

🤖 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/use_case/interactor/query.rs` around lines 2413 - 2429, The
route arrival time test currently uses identical values for station_cd and
station_g_cd, so it cannot catch ID mixups in the lookup logic. Update the
affected test cases around estimate_route_arrival_times and build_interactor to
use distinct station_cd values for the endpoints (for example 102/103/104) while
keeping station_g_cd as the returned sequence IDs (for example 2/3/4), and keep
the call site using station_cd with the assertions still checking station_g_cd.
🤖 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/use_case/interactor/query.rs`:
- Around line 2413-2429: The route arrival time test currently uses identical
values for station_cd and station_g_cd, so it cannot catch ID mixups in the
lookup logic. Update the affected test cases around estimate_route_arrival_times
and build_interactor to use distinct station_cd values for the endpoints (for
example 102/103/104) while keeping station_g_cd as the returned sequence IDs
(for example 2/3/4), and keep the call site using station_cd with the assertions
still checking station_g_cd.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6331a5ef-37ce-4eaf-b5b7-9fac8ba8a7ef

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8daaa and 7f24545.

📒 Files selected for processing (3)
  • .sqlx/query-6c3b77baaf7b51c4986b8d2a4cfb3f94275ee3595d31aa43938cc1bbd43f0268.json
  • .sqlx/query-c153bbe0cade8f513aeef1475527327a7240e45dd257123047ed4b4618c3c329.json
  • stationapi/src/use_case/interactor/query.rs
💤 Files with no reviewable changes (2)
  • .sqlx/query-6c3b77baaf7b51c4986b8d2a4cfb3f94275ee3595d31aa43938cc1bbd43f0268.json
  • .sqlx/query-c153bbe0cade8f513aeef1475527327a7240e45dd257123047ed4b4618c3c329.json

CodeRabbitの指摘に対応: station_cd=station_g_cdだとlookupロジックの
station_cd/station_g_cd混同バグを検出できないため区別する
@github-actions github-actions Bot added the fix 直した label Jul 1, 2026
CodeRabbitのDocstring Coverageチェック(75% < 80%)対応
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TinyKitten
TinyKitten merged commit cb4a5ff into dev Jul 1, 2026
10 checks passed
@TinyKitten
TinyKitten deleted the fix/estimate-arrival-times-station-range branch July 1, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant