Skip to content

最大許容精度を1.5kmに戻し精度超過時は走行中扱いにする - #6122

Merged
TinyKitten merged 4 commits into
devfrom
claude/max-precision-1-5km-eXCs4
Jun 4, 2026
Merged

TinyKitten merged 4 commits into
devfrom
claude/max-precision-1-5km-eXCs4

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

概要

地下鉄路線における位置情報の信頼度に応じて到着判定を出し分けるための改修。GPS精度が1.5km以内に収まる路線(例: 都営大江戸線)では従来どおり位置情報を信用してそのまま使い、精度1.5km超が観測される路線(例: 東京メトロ副都心線)では位置情報を信用せず走行中として扱う。

変更の種類

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

変更内容

  • MAX_PERMIT_ACCURACY を 2000 から 1.5km(1500) に戻す(最大許容精度を1.5kmから2kmに緩和 #6116 の緩和を取り消し)
  • handleTrackingLocation でワープ対策フィルタが棄却した測位を locationAccuracyOutlierAtom(外れ値フラグ)に記録する。棄却時は座標を破棄して位置が前回値で凍結し、精度悪化が locationAtom に現れないことへの対処
  • useRefreshStation の到着判定で外れ値フラグが立っている場合は座標が良好でも arrived=false(走行中)に強制する。フィルタを経由しないワンショット取得・手動選択向けに、保持している精度の直接チェックも併用
  • 外れ値フラグの解除を受理側の setLocation に集約し、ワンショット取得・手動選択など handleTrackingLocation を経由しない経路の良好な測位でも確実に解除されるようにする(フラグが残り arrived が false に張り付く問題への対処)
  • 上記の到着判定ガード・フラグ連携・フラグ解除のユニットテストを追加

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

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


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • GPS精度の許容閾値を見直し、許容精度をより厳しくしました。
    • 精度が基準を超える(不安定な測位)場合に「到着」判定を取り消すよう到着判定を改善しました。
    • 不正確な測位を下流へ通知するフラグを導入し、誤検知を減らします。

@TinyKitten TinyKitten self-assigned this Jun 4, 2026
@github-actions github-actions Bot added the react label Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

このPRは、GPS測位精度が許容値を超えた場合に外れ値フラグを立てて下流へ伝播させ、到着判定ロジックでそれを参照することで、信頼性の低い位置情報を段階的に除外するようにします。精度閾値を2000から1500に引き下げ、新しいJotai atom・setter・テストで完全に統合。

Changes

GPS精度外れ値フラグの追加と到着判定改善

Layer / File(s) Summary
精度閾値の引き下げと外れ値状態の定義
src/constants/location.ts, src/store/atoms/location.ts, src/store/atoms/location.test.ts
MAX_PERMIT_ACCURACY を 2000→1500 に変更。locationAccuracyOutlierAtom を追加し、setLocationAccuracyOutlier() と reset/setLocation によるフラグ解除を導入。関連テストを追加。
位置追跡フィルタで精度判定と外れ値フラグ設定
src/utils/handleTrackingLocation.ts, src/utils/handleTrackingLocation.test.ts
handleTrackingLocation が精度閾値超過時に setLocationAccuracyOutlier(true) を呼んで座標を破棄し、閾値以下では setLocation を呼ぶように変更。テストで両ケースを検証。
到着判定ロジックで外れ値フラグを参照
src/hooks/useRefreshStation.ts, src/hooks/useRefreshStation.test.tsx
useRefreshStation が isArrived 計算時に外れ値フラグと直接精度(MAX_PERMIT_ACCURACY)を確認し、どちらかで信頼性が低い場合は arrived=false を返すように変更。テストを拡張。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6098: MAX_PERMIT_ACCURACY を 1500 にする変更点が重複しており、閾値整合に関連。
  • TrainLCD/MobileApp#6116: 同じ定数周りの調整で到着/フィルタ挙動に影響する関連変更。
  • TrainLCD/MobileApp#6103: handleTrackingLocation の精度フィルタ実装に関する変更がコード上で関連。

Suggested labels

react

Poem

🐰 GPSの微かな揺らぎ捉え、
外れ値フラグで道を正し、
到着の鐘は確かな足跡へ、
閾値下げて誤差を避け、
小さな旅路を静かに守る。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは変更内容の主要ポイント(最大許容精度を1.5kmに変更し、精度超過時は走行中扱い)を明確に示しており、差分内容と完全に一致している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description check ✅ Passed PRの説明は要件テンプレートの全セクションをカバーしており、変更内容、テスト実施、技術的詳細が明確に記述されています。

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

✨ 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 claude/max-precision-1-5km-eXCs4

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

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

Caution

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

⚠️ Outside diff range comments (1)
src/store/atoms/location.ts (1)

54-76: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

外れ値フラグが継続測位以外の経路で解除されません。

setLocationAccuracyOutlier(false) は handleTrackingLocation の正常系でしか実行されませんが、handleTrackingLocation のコメントどおりワンショット取得や手動選択は setLocation() を直接呼びます。いったんこのフラグが true になると、その後に良好な位置を direct setLocation() で反映しても useRefreshStation の Line 92-95 で arrived = false が維持されます。受理した位置更新でフラグをクリアするか、継続測位由来の状態にだけ紐づくようにしてください。

🤖 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 `@src/store/atoms/location.ts` around lines 54 - 76, The outlier flag set by
setLocationAccuracyOutlier(true) is never cleared when locations are applied via
direct setLocation calls, causing arrived to stay false; modify the code so that
whenever setLocation (the function that applies a newly accepted location from
one-shot/manual selection) successfully updates locationAtom/rawLocationAtom you
also call setLocationAccuracyOutlier(false) (or clear the flag inside
setLocation), or alternatively scope the flag to “continuous-tracking” by tying
it to lastFilteredLocationAtom updates; update setLocation and/or
handleTrackingLocation accordingly so accepted direct updates clear the outlier
state and downstream useRefreshStation logic sees arrived correctly.
🤖 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.

Outside diff comments:
In `@src/store/atoms/location.ts`:
- Around line 54-76: The outlier flag set by setLocationAccuracyOutlier(true) is
never cleared when locations are applied via direct setLocation calls, causing
arrived to stay false; modify the code so that whenever setLocation (the
function that applies a newly accepted location from one-shot/manual selection)
successfully updates locationAtom/rawLocationAtom you also call
setLocationAccuracyOutlier(false) (or clear the flag inside setLocation), or
alternatively scope the flag to “continuous-tracking” by tying it to
lastFilteredLocationAtom updates; update setLocation and/or
handleTrackingLocation accordingly so accepted direct updates clear the outlier
state and downstream useRefreshStation logic sees arrived correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 483a5033-ec47-4583-b2bb-728bc0ae177a

📥 Commits

Reviewing files that changed from the base of the PR and between 35277ef and 3d648d3.

📒 Files selected for processing (6)
  • src/constants/location.ts
  • src/hooks/useRefreshStation.test.tsx
  • src/hooks/useRefreshStation.ts
  • src/store/atoms/location.ts
  • src/utils/handleTrackingLocation.test.ts
  • src/utils/handleTrackingLocation.ts

@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 (2)
src/utils/handleTrackingLocation.test.ts (1)

41-44: ⚡ Quick win

jest.clearAllMocks() は afterEach に寄せてください。

今は beforeEach でクリアしていますが、このリポジトリのテスト規約は afterEach 指定です。ここも合わせておくと、モックの後始末の責務が揃います。

As per coding guidelines: "テストの afterEach で jest.clearAllMocks() を呼び出してください"

Also applies to: 46-52

🤖 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 `@src/utils/handleTrackingLocation.test.ts` around lines 41 - 44, Move the
jest.clearAllMocks() call out of the beforeEach block and into an afterEach
block so mock cleanup follows the repository test convention; keep mockIsDevApp
= false initialization in beforeEach, and update the other test groups
referenced (the other beforeEach at lines ~46-52) to remove their
clearAllMocks() as well, adding a single afterEach(() => jest.clearAllMocks())
near the top of the test file to cover all tests.
src/store/atoms/location.test.ts (1)

75-102: ⚡ Quick win

resetLocationState 側の解除契約もここで固定したいです。

この追加分で setLocation 経路は押さえられていますが、今回の変更範囲にある resetLocationState の外れ値フラグ解除は未カバーです。そこが戻ると前回の outlier 状態を引きずって到着判定が false に張り付くので、同じ describe に 1 ケース足しておくと安心です。

Based on learnings: "When modifying behavior, update or add tests in the same change set; document skipped tests with TODOs and owner rationale"

🤖 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 `@src/store/atoms/location.test.ts` around lines 75 - 102, Add a test that
exercises resetLocationState to ensure it clears the outlier flag
(locationAccuracyOutlierAtom) just like setLocation does: arrange a prior state
with store.set(locationAccuracyOutlierAtom, true) and a previous location via
setLocation(...), call resetLocationState() (or the exported function named
resetLocationState) and assert that store.get(locationAccuracyOutlierAtom) is
false and that locationAtom remains the expected value; place this spec inside
the existing "外れ値フラグの解除" describe so the change set covers both setLocation and
resetLocationState behaviors.
🤖 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 `@src/store/atoms/location.test.ts`:
- Around line 75-102: Add a test that exercises resetLocationState to ensure it
clears the outlier flag (locationAccuracyOutlierAtom) just like setLocation
does: arrange a prior state with store.set(locationAccuracyOutlierAtom, true)
and a previous location via setLocation(...), call resetLocationState() (or the
exported function named resetLocationState) and assert that
store.get(locationAccuracyOutlierAtom) is false and that locationAtom remains
the expected value; place this spec inside the existing "外れ値フラグの解除" describe so
the change set covers both setLocation and resetLocationState behaviors.

In `@src/utils/handleTrackingLocation.test.ts`:
- Around line 41-44: Move the jest.clearAllMocks() call out of the beforeEach
block and into an afterEach block so mock cleanup follows the repository test
convention; keep mockIsDevApp = false initialization in beforeEach, and update
the other test groups referenced (the other beforeEach at lines ~46-52) to
remove their clearAllMocks() as well, adding a single afterEach(() =>
jest.clearAllMocks()) near the top of the test file to cover all tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 023f5985-314d-4302-89ba-0fd6ef6445a2

📥 Commits

Reviewing files that changed from the base of the PR and between 3d648d3 and 927303a.

📒 Files selected for processing (4)
  • src/store/atoms/location.test.ts
  • src/store/atoms/location.ts
  • src/utils/handleTrackingLocation.test.ts
  • src/utils/handleTrackingLocation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/store/atoms/location.ts

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.

2 participants