Skip to content

地下鉄でも精度安定時はスムージングを適用する - #5670

Merged
TinyKitten merged 2 commits into
devfrom
claude/subway-smoothing-accuracy-RLimf
Mar 25, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/subway-smoothing-accuracy-RLimf

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • 地下鉄(LineType.Subway)で無条件にスムージングをスキップしていた処理を、精度の安定性を判定した上で制御するように変更
  • 精度履歴の変動係数(CV = 標準偏差/平均)が閾値未満かつ平均精度が200m未満の場合を「安定」と判定し、スムージングを適用
  • 精度が不安定な場合は従来通りスムージングをスキップ(既存動作を維持)

変更内容

  • src/store/atoms/location.ts: isAccuracyStable() 関数を追加し、skipSmoothing の条件を Subway && !isAccuracyStable(history) に変更
  • src/store/atoms/location.test.ts: 新規テスト5件(非地下鉄、地下鉄+不安定、地下鉄+安定、サンプル不足、安定だが高精度)

安定性判定の仕様

定数 値 説明
MIN_STABILITY_SAMPLES 4 判定に必要な最小サンプル数
MAX_STABLE_CV 0.5 変動係数の閾値(これ未満で安定)
BAD_ACCURACY_THRESHOLD 200m 平均精度がこれ以上なら不安定扱い(既存定数を再利用)

リグレッションリスク

  • 非地下鉄路線: LineType.Subway チェックで短絡評価されるため影響なし
  • 地下鉄 + 精度不安定: 従来通りスキップされるため影響なし
  • 地下鉄 + 精度安定: 新規動作(スムージング適用)

ローカル実行コマンド

npx biome ci ./src/store/atoms/location.ts ./src/store/atoms/location.test.ts
TZ=UTC jest --testPathPattern='src/store/atoms/location.test' --no-coverage

Test plan

  • 非地下鉄路線でスムージングが適用されることを確認
  • 地下鉄 + 精度不安定時にスムージングがスキップされることを確認
  • 地下鉄 + 精度安定時にスムージングが適用されることを確認
  • サンプル不足時にスムージングがスキップされることを確認
  • 平均精度200m以上の場合にスムージングがスキップされることを確認

https://claude.ai/code/session_0136uqgSRjobn4E4trATATDX

Summary by CodeRabbit

概要

  • バグ修正
    • GPS精度が安定している場合の位置情報スムージングロジックを改善しました。地下鉄などの環境で、安定した信号受信時にはより正確な座標が反映されます。
  • テスト
    • 位置更新とスムージング挙動を検証する自動テストを追加しました(地下鉄/非地下鉄や精度履歴の境界条件を含む)。
  • その他
    • テスト用に位置状態を初期化できるリセット機能を追加しました。

@github-actions github-actions Bot added the react label Mar 25, 2026
@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

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: d3aa86b4-da7d-4e0b-a142-c7fb7a04014d

📥 Commits

Reviewing files that changed from the base of the PR and between 72b9494 and 52a7dda.

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

📝 Walkthrough

ウォークスルー

位置情報ストアのテストスイートを追加し、地下鉄路線での位置スムージング判定を「精度履歴の安定性」に基づく条件付きに変更。テストは各種安定性/閾値ケースと非地下鉄でのスムージング適用を検証する。

変更内容

コホート / ファイル(s) 概要
テストスイート追加
src/store/atoms/location.test.ts
setLocation の動作を検証するJestテストを追加。地下鉄向けの精度履歴に基づくスムージングのスキップ/適用、サンプル不足、閾値境界などのケースを網羅。
位置ロジック改修
src/store/atoms/location.ts
精度の変動係数(CV)で安定性判定する isAccuracyStable を導入。地下鉄時のスキップ条件を「常時」から「精度が不安定な場合のみ」に変更。テスト用に resetLocationState() を新規エクスポート。

推定レビュー難度

🎯 3 (中程度) | ⏱️ ~20 分

関連する可能性のあるPR

詩

🐰 地下の線路で精度が踊る、
安定のときだけそっと撫でる。
テストが見張り、履歴を嗅ぎ分け、
うさぎは跳ねて、新しい道を祝う。

🚥 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 プルリクエストのタイトルは、地下鉄で精度が安定している時にスムージングを適用するという変更の主要な目的を明確に説明しており、実装内容と完全に一致しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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/subway-smoothing-accuracy-RLimf

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/store/atoms/location.test.ts (1)

109-120: 200m境界(>=)を直接検証するケースを追加するとより堅牢です。

現状は平均250mでの確認なので、仕様境界の平均ちょうど200mケースも1本あると回帰を防ぎやすいです。

✅ 追加例(境界200m)
+    it('平均精度がちょうど200mでもスムージングをスキップする', () => {
+      setStationLineType(LineType.Subway);
+      // 平均200m、CVは低い
+      store.set(accuracyHistoryAtom, [190, 200, 210, 200]);
+
+      const loc = makeLocation(35.0, 139.0, 200, 1000);
+      setLocation(loc);
+
+      const result = store.get(locationAtom);
+      expect(result?.coords.latitude).toBe(35.0);
+      expect(result?.coords.longitude).toBe(139.0);
+    });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/store/atoms/location.test.ts` around lines 109 - 120, Add a new unit test
that covers the 200m boundary by setting accuracyHistoryAtom to values whose
average is exactly 200 (e.g., [200,200,200,200] or mix that averages to 200),
then call setStationLineType(LineType.Subway), setLocation(makeLocation(...,
accuracy=200, ...)) and assert locationAtom returns the raw coords (same as the
existing test expectations); place this alongside the existing test so the
smoothing skip behavior for average >= 200 is explicitly verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/store/atoms/location.test.ts`:
- Around line 41-45: The tests leave lastFilteredLocationAtom state between
cases—add a test-only reset helper in the location module (e.g., export function
resetLocationTestState() or similar) that clears lastFilteredLocationAtom and
any other module-scoped state used by setLocation, then call that helper from
the test beforeEach alongside the existing store.set(locationAtom, null),
store.set(accuracyHistoryAtom, []), and setStationLineType(null); update
references to lastFilteredLocationAtom and setLocation in location.ts to ensure
the helper resets the same internal symbols the logic uses.

---

Nitpick comments:
In `@src/store/atoms/location.test.ts`:
- Around line 109-120: Add a new unit test that covers the 200m boundary by
setting accuracyHistoryAtom to values whose average is exactly 200 (e.g.,
[200,200,200,200] or mix that averages to 200), then call
setStationLineType(LineType.Subway), setLocation(makeLocation(..., accuracy=200,
...)) and assert locationAtom returns the raw coords (same as the existing test
expectations); place this alongside the existing test so the smoothing skip
behavior for average >= 200 is explicitly verified.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fff9233b-e386-4d86-8499-dbf6ebee26aa

📥 Commits

Reviewing files that changed from the base of the PR and between 3c56901 and 72b9494.

📒 Files selected for processing (2)
  • src/store/atoms/location.test.ts
  • src/store/atoms/location.ts

Comment thread src/store/atoms/location.test.ts Resolved
@TinyKitten
TinyKitten merged commit 139819a into dev Mar 25, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/subway-smoothing-accuracy-RLimf branch March 25, 2026 13:46
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