Skip to content

DevOverlayの診断ダンプに測位パイプラインの判定内訳とGPSの判定結果を追加 - #6990

Merged
TinyKitten merged 3 commits into
devfrom
claude/subway-eta-accuracy-s14ri8
Sep 16, 2026
Merged

TinyKitten merged 3 commits into
devfrom
claude/subway-eta-accuracy-s14ri8

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Sep 16, 2026

Copy link
Copy Markdown
Member

概要

実機(iOS / 都営大江戸線)で起きた測位の不具合 2 件を、DevOverlay の診断ダンプだけで再現できるようにする。

現状のダンプでは原因を特定できず、駅座標を StationAPI から引き、useThreshold を手で再実装して初めて再現できた。その手作業を潰すのが目的。src/utils/devDiagnosticsSnapshot.ts 自身が「棄却された測位の履歴や測位の出所は持ち出せない。判定箇所に記録を足さないと取れない」と書いていた穴を埋める。

測位の判定ロジックは変更していない。 ダンプに載せる値の追加のみ。

変更の種類

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

変更内容

追加したフィールド(16 件)

追加先 フィールド 何に答えるか
config forceNotArrivedOnLowAccuracy 到着判定の強制未到着分岐をゲートする既存リモート設定。config 節は「同じ測位でもこれが違えば挙動が変わる設定」を持つ節なので、欠落は漏れだった
location displacementHistory 位置が飛び続けているのか、一点だけ外れたのか
filter accuracyOutlier 直近の継続測位が精度フィルタで棄却されたか
filter counts 測位が届いていないのか / 届いているが捨てているのか / どの門で捨てたのか
state(新設) currentStationId currentStationName arrived approaching nearestStationId nearestStationName distanceToNearestStation arrivedThreshold approachingThreshold GPS が下している判定そのもの。座標と駅座標からの逆算は直通運転で成り立たない

counts は 1 件の測位に対する排他的な結果(accepted / rejectedByAccuracy / rejectedAsDuplicate / rejectedByEta / rejectedBySpeed)で、合計が入力件数と一致する。一致しないと「落ちていない」のか「数え漏らしている」のかが読めなくなるため。

とくに rejectedAsDuplicate には代替がない。handleTrackingLocation の重複排除は lastProcessedAtMs を更新するに return するので、経過時間からは「OS が呼んでいない」状態と区別が付かない。

実装上の判断

  • 集計は判定箇所そのもので行う。 呼び出し側で条件を組み直すと判定と表示が別々に育って食い違う(smoothingDecisionAtom が判定結果と入力を 1 つの atom に持っているのと同じ理由)。
  • isDevApp や feature flag で分岐させない。 カナリアやフラグでだけ通る経路を測位パイプラインへ作らないため。処理は整数のインクリメントと固定長配列への push のみで、atom を書かないので購読側の再レンダーも起きない。
  • displacementHistory の記録は精度フィルタより前に置く。 地下で最も知りたい「棄却された生座標がどれだけ飛んでいたか」は、rawLocationAtom が最新 1 件しか持たないためここでしか観測できない。setLocation を直接呼ぶ経路(手動での駅選択・起動時のワンショット取得)は意図的な瞬間移動なので対象外にしている。
  • distanceToNearestStation は到着判定と同じ 0.01m 精度で求める。 isPointWithinRadius の実体は getDistance(point, center, 0.01) < radius で、既定の 1m 丸めだと閾値ぎりぎりのときダンプ上だけ大小が逆に見える。

リファクタリング(判定への影響なし)

useRefreshStation のプライベート定数 MAX_ACCURACY_BONUS と精度ボーナスの式を src/utils/accuracyBonus.ts へ抽出し、DevOverlay と共有した。式・定数・ガード条件はいずれも変更なしの純粋な抽出。

ダンプへ「精度ボーナス込みの実効到着圏・接近圏」を載せるのに同じ式が要り、DevOverlay 側で組み直すと持ち出した実効閾値が実際の判定と食い違うため。

テスト

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

npm run lint(771 ファイル・エラーなし)/ npm test(289 suites・3165 tests 全件成功)/ npm run typecheck(エラーなし)。

Claude Fable 5.1 によるローカルレビューを 2 巡実施し、指摘 4 件(すべて minor)を修正済み。内訳は、ダンプの距離精度と到着判定の食い違い、飛び幅の記録位置(精度フィルタで棄却された測位が観測できていなかった)、JSDoc が実際の観測範囲より広かった箇所 2 件。

追加した回帰テストは、修正を戻すと実際に落ちることを確認済み(distanceToNearestStation の精度: Expected: 288.84 / Received: 289)。

実機・シミュレータでの動作確認は未実施。

関連Issue

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

UI 変更なし: src/components/DevOverlay.tsx を変更しているが、差分はフック呼び出しの追加とクリップボードへ載せる JSON の項目追加のみで、描画要素(JSX)に差分はない。オーバーレイの見た目は変わらない。

🤖 Generated with Claude Code

https://claude.ai/code/session_01KuvCXLRytCryvexood76po


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • 開発用診断情報に、駅への到着・接近状態、最近接駅までの距離、判定閾値を追加しました。
    • GPS精度を考慮した判定閾値の補正に対応しました。
    • 測位入力の変位履歴や、受理・棄却理由ごとの処理件数を確認できるようになりました。
    • 距離情報を0.01m単位で表示できるようになりました。
  • 改善

    • 到着判定と接近判定で、GPS精度に基づく補正値を共通化しました。

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

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 20d7b274-67d9-4ec4-9881-56e45c6ffb0f

📥 Commits

Reviewing files that changed from the base of the PR and between a9ac253 and 8fceebd.

📒 Files selected for processing (13)
  • src/components/DevOverlay.test.tsx
  • src/components/DevOverlay.tsx
  • src/hooks/useRefreshStation.ts
  • src/store/atoms/location.test.ts
  • src/store/atoms/location.ts
  • src/utils/accuracyBonus.test.ts
  • src/utils/accuracyBonus.ts
  • src/utils/devDiagnosticsSnapshot.test.ts
  • src/utils/devDiagnosticsSnapshot.ts
  • src/utils/handleTrackingLocation.test.ts
  • src/utils/handleTrackingLocation.ts
  • src/utils/locationPipelineStats.test.ts
  • src/utils/locationPipelineStats.ts

Included review availability: 1 review is currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

測位パイプラインの統計記録とGPS精度補正を追加しました。診断スナップショットと開発オーバーレイは、測位履歴、棄却件数、到着判定状態、最近接駅までの距離、実効閾値を出力します。

Changes

測位診断機能

Layer / File(s) Summary
GPS精度補正の共通化
src/utils/accuracyBonus.ts, src/utils/accuracyBonus.test.ts, src/hooks/useRefreshStation.ts
getAccuracyBonusを追加しました。無効値では0を返し、精度の50%を最大150mまで補正します。駅更新処理はこの関数を使用します。
測位パイプライン統計
src/utils/locationPipelineStats.ts, src/utils/locationPipelineStats.test.ts, src/utils/handleTrackingLocation.ts, src/utils/handleTrackingLocation.test.ts, src/store/atoms/location.ts, src/store/atoms/location.test.ts
受理件数、棄却理由別の件数、入力座標間の変位履歴を記録します。重複、精度、ETA、速度による棄却を分類します。状態リセット時に統計もリセットします。
診断スナップショットの状態出力
src/utils/devDiagnosticsSnapshot.ts, src/utils/devDiagnosticsSnapshot.test.ts
設定、位置情報、フィルタ情報に加えて、測位統計と到着判定状態をJSONへ出力します。到着状態、接近状態、最近接駅、距離、実効閾値を含みます。
開発オーバーレイへの診断接続
src/components/DevOverlay.tsx, src/components/DevOverlay.test.tsx
開発オーバーレイが診断用atomとフックを取得します。座標と最近接駅がある場合、距離を0.01m精度で計算します。テストは288.84mの出力を検証します。

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant LocationInput
  participant handleTrackingLocation
  participant locationPipelineStats
  participant locationAtom
  participant DevOverlay
  LocationInput->>handleTrackingLocation: 測位を渡す
  handleTrackingLocation->>locationPipelineStats: 入力距離と棄却理由を記録
  handleTrackingLocation->>locationAtom: 受理した位置を反映
  locationAtom->>locationPipelineStats: 受理・ETA・速度の結果を記録
  DevOverlay->>locationPipelineStats: 統計と変位履歴を取得
  DevOverlay->>DevOverlay: 最近接駅までの距離と実効閾値を診断情報へ設定
Loading

Merge Risk: ⚪ Minimal · up to 8fcee

The added diagnostics use the same location inputs as arrival evaluation, with no actionable merge risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、DevOverlayの診断ダンプに測位パイプラインの判定内訳とGPS判定結果を追加するという主変更を明確かつ簡潔に示しています。
Description check ✅ Passed 概要、変更種類、変更内容、テスト結果、関連Issue、スクリーンショットの各セクションがテンプレートに沿って記載されています。実機・シミュレータ未確認の事実も明記されています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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 claude/subway-eta-accuracy-s14ri8

うさぎは測位の足あとを数えます
受理と棄却を静かに分けます
GPSの霧には補正を添えます
駅までの距離を細かく測ります
診断画面に状態が並びます
月明かりの下でテストが跳ねます

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

@TinyKitten
TinyKitten merged commit f4342e5 into dev Sep 16, 2026
7 checks passed
@TinyKitten
TinyKitten deleted the claude/subway-eta-accuracy-s14ri8 branch September 16, 2026 00:41
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