Skip to content

カナリアの磁気併用停車判定を駅間ごとに保存・比較する - #40

Merged
TinyKitten merged 1 commit into
mainfrom
feat/39-stop-comparison
Nov 30, 2026
Merged

TinyKitten merged 1 commit into
mainfrom
feat/39-stop-comparison

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Closes #39
関連 TrainLCD/MobileApp#7583

同じ乗車の両方式の候補と任意の実発着時刻を保存し、乗車セッションと区間番号で再送を重複排除します。observer の集計で全区間の不一致・磁気欠測と、ラベルのある区間の誤停車増減・到着検出数を確認できます。

PostgreSQL と HTTP の送受信を通す検証を CI に追加しました。本番での受信確認と実乗車の効果測定はデプロイ後の作業です。

Summary by CodeRabbit

  • 新機能
    • 磁気データを用いた停車判定の比較データを記録し、セッションや区間ごとの集計結果を確認できるようになりました。
    • 集計では、候補時刻の不一致、誤検出の解消・発生、到着の検出状況などを確認できます。
  • ドキュメント
    • 比較データの送信条件、集計内容、検証方法を追加しました。
  • テスト
    • サーバー起動後に比較データの送信と集計結果を検証するチェックを追加しました。

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

停車比較データのGraphQL送信、PostgreSQLへの保存、方式別の集計を追加しました。検証スクリプトが認証と集計結果を確認し、CIがサーバー起動後にスクリプトを実行します。

Changes: 停車比較の収集と集計

Layer / File(s) Summary
入力と永続化
src/stop_comparison.rs, src/stop_comparison_table.sql, src/main.rs, src/storage.rs
GraphQL入力型と保存時の検証を追加しました。stop_comparisonsテーブルを作成し、Storage::prepareで準備します。保存時は時刻配列を昇順にし、同じセッションと区間の重複挿入を無視します。
GraphQL送信と集計
src/stop_comparison.rs, src/stop_comparison_summary.sql, src/graphql.rs
telemetry権限がある場合にデータを保存するmutationを追加しました。observer権限がある場合に集計を返すqueryを追加しました。集計には、方式間の不一致、磁気データの欠落・フォールバック、誤検出の変化、到着検出数が含まれます。
検証スクリプトとCI
scripts/check-stop-comparison.py, README.md, .github/workflows/test.yml
検証スクリプトは合成データを送信し、権限エラーと集計値を確認します。READMEに入力条件、集計例、実行手順を記載しました。CIはサーバーのhealth endpointを確認してからスクリプトを実行し、終了時にサーバーを停止します。

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

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions as GitHub Actions
  participant Check as check-stop-comparison.py
  participant THQ as THQ GraphQL
  participant PostgreSQL
  GitHubActions->>THQ: サーバーを起動
  GitHubActions->>Check: health確認後にスクリプトを実行
  Check->>THQ: 停車比較データを送信
  THQ->>PostgreSQL: 比較データを保存
  Check->>THQ: 停車比較サマリーを照会
  THQ->>PostgreSQL: 集計結果を取得
  THQ-->>Check: 集計結果を返す
Loading
Merge Risk: Minimal · up to 363b0

This change adds storage and aggregation of stop-comparison data, plus a verification script that CI runs. No merge-blocking risk was identified. Checking the data on production and measuring the effect on real rides remain post-deploy work.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed タイトルは「カナリアの磁気併用停車判定を駅間ごとに保存・比較する」で、変更の主題と一致します。PR の目的は、磁気あり・なしの停車候補を駅間ごとに保存し、observer の集計で比較することです。変更内容(stop_comparison の保存、テーブル定義、集計 SQL、GraphQL の追加、検証スクリプト)もこの主題に含まれます。タイトルは簡潔で、具体的な作業内容を示しています。
Linked Issues check Passed [#39] 直接リンクの Issue は、駅間ごとの両方式の停車候補、磁気の欠測・フォールバック、任意の実発着時刻、乗車セッション・区間順・発着駅・アプリ/OS 情報の保存を求めています。

確認結果:
- src/stop_comparison_table.sql: stop_comparisons は主キーを (session_id, segment_index) とし、発着駅、app_v…
Out of Scope Changes check Passed 変更はすべて #39 の データ収集・保存・集計、およびその検証に関係します。
- src/stop_comparison.rs、src/stop_comparison_table.sql、src/stop_comparison_summary.sql: 収集データの保存と集計そのものです。
- src/graphql.rs(sendStopComparison / stopComparisonS…
Full details: Linked Issues check

Explanation

[#39] 直接リンクの Issue は、駅間ごとの両方式の停車候補、磁気の欠測・フォールバック、任意の実発着時刻、乗車セッション・区間順・発着駅・アプリ/OS 情報の保存を求めています。

確認結果:

  • src/stop_comparison_table.sql: stop_comparisons は主キーを (session_id, segment_index) とし、発着駅、app_version、platform、os_version、with_magnetic / without_magnetic(BIGINT[])、magnetic_missing、magnetic_fallback、departure_ms / arrival_ms(NULL 許容)を保存します。配列型のため候補 0 件・複数件を表現できます。
  • src/stop_comparison.rs store: ON CONFLICT (session_id, segment_index) DO NOTHING により再送を重複排除します。時刻は昇順に並べ、非負の安全な整数に限定します。生のセンサー系列や座標は保存しません。
  • src/stop_comparison_summary.sql: 全区間を disagreement_segments、magnetic_missing_segments、magnetic_fallback_segments に集計します。labeled_segments(発着時刻あり)のみ誤停車の解消・発生を判定するため、未ラベル区間は正誤採点から外れます。到着の前後 5 秒以内の検出数(detected_with_magnetic / detected_without_magnetic)と対象駅数(target_arrivals)も出力します。
  • src/storage.rs: Storage::prepare が テーブル定義を実行し、既存の認証・保存経路を再利用します。

未確認事項: src/graphql.rs と CI ワークフローは要約のみで確認しました。また、停止中の THQ の本番受信確認はデプロイ後の作業であり、PR 説明でも明記されています。コーディング要件としては CI の PostgreSQL・HTTP 検証で代替されると判断しました。統計的な改善判断(複数乗車での評価)は本 PR のコードではなく運用データで行う作業です。

Full details: Out of Scope Changes check

Explanation

変更はすべて #39 の データ収集・保存・集計、およびその検証に関係します。

  • src/stop_comparison.rs、src/stop_comparison_table.sql、src/stop_comparison_summary.sql: 収集データの保存と集計そのものです。
  • src/graphql.rs(sendStopComparison / stopComparisonSummary)、src/main.rs、src/storage.rs: 既存の認証・保存経路への接続です。
  • .github/workflows/test.yml、scripts/check-stop-comparison.py: PostgreSQL と HTTP 送受信の CI 検証です。PR 説明の内容と一致します。
  • README.md: 送信条件と集計ルールの文書化です。

既存の機能を変更する無関係な処理は確認されませんでした。未確認事項: graphql.rs と CI ワークフローは要約に基づく判断です。

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

うさぎは時刻を並べて送る
区間ごとの記録が蓄積
磁気あり、磁気なしを比べ
到着の窓をそっと確かめる
集計の答えをCIが受け取る
ぴょんと跳ねて、検証完了

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 757f1a9f-da3f-4d40-a399-b34d4a6221c8
Commits

Reviewing files that changed from the base of the PR and between 37208ef and 363b059.

Files selected for processing: 9

  • .github/workflows/test.yml
  • README.md
  • scripts/check-stop-comparison.py
  • src/graphql.rs
  • src/main.rs
  • src/stop_comparison.rs
  • src/stop_comparison_summary.sql
  • src/stop_comparison_table.sql
  • src/storage.rs

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

@TinyKitten
TinyKitten merged commit 1e6c448 into main Nov 30, 2026
2 checks passed
@TinyKitten
TinyKitten deleted the feat/39-stop-comparison branch November 30, 2026 13:16
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.

カナリアの停車判定を駅間ごとに集計し、磁気併用の効果を検証する

1 participant