Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/store/atoms/location.gpxEtaAssist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ARRIVED_MIN_THRESHOLD,
BAD_ACCURACY_THRESHOLD,
} from '~/constants/threshold';
import { getAccuracyBonus } from '~/utils/accuracyBonus';
import { getEtaPhaseNow } from '~/utils/etaPhaseNow';
import {
clamp,
Expand Down Expand Up @@ -57,9 +58,6 @@ jest.mock('~/lib/remoteConfig', () => ({
isForceNotArrivedOnLowAccuracyEnabled: () => true,
}));

// useRefreshStation のプライベート定数と同値。到着圏へ加える精度ボーナスの上限(m)。
const MAX_ACCURACY_BONUS = 150;

type Condition = {
label: string;
accuracy: number;
Expand Down Expand Up @@ -223,9 +221,9 @@ const replay = (
ARRIVED_MIN_THRESHOLD,
ARRIVED_MAX_THRESHOLD
);
// 到着圏はGPS精度だけで決まる(ETAは到着判定へ介入しない)
const arrivedRadius =
arrivedThreshold + Math.min(accuracy * 0.5, MAX_ACCURACY_BONUS);
// 到着圏はGPS精度だけで決まる(ETAは到着判定へ介入しない)。精度ボーナスは
// useRefreshStation と同じ関数で求める(式を写すと判定とずれても気付けない)
const arrivedRadius = arrivedThreshold + getAccuracyBonus(accuracy);

const arrived = nearestDistance <= arrivedRadius;
if (arrived && firstDetection[nearestIdx] === null) {
Expand Down
15 changes: 10 additions & 5 deletions src/utils/accuracyBonus.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { getAccuracyBonus, MAX_ACCURACY_BONUS } from './accuracyBonus';
import { getAccuracyBonus } from './accuracyBonus';

describe('getAccuracyBonus', () => {
it('精度の半分を補正として返す', () => {
expect(getAccuracyBonus(100)).toBe(50);
});

it('上限で頭打ちになる', () => {
// 地下の粗い測位(精度2000m)でも、判定圏が無制限に広がらないようにする
expect(getAccuracyBonus(2000)).toBe(MAX_ACCURACY_BONUS);
expect(getAccuracyBonus(300)).toBe(MAX_ACCURACY_BONUS);
// 上限はリテラルで固定する。実装側の定数と突き合わせるとトートロジーになり、
// 上限を 150m から動かしてもテストが通ってしまう。
it('補正の上限は150mで、精度300mで頭打ちになる', () => {
// 頭打ちの境界(精度300m → 半分が上限ちょうど)
expect(getAccuracyBonus(300)).toBe(150);
// 境界の手前では半分のまま
expect(getAccuracyBonus(299)).toBe(149.5);
// 地下の粗い測位でも上限を超えない
expect(getAccuracyBonus(2000)).toBe(150);
});

it('精度が無い・不正・非正の値では補正しない', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/accuracyBonus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** GPS精度に応じた閾値補正の上限(m) */
export const MAX_ACCURACY_BONUS = 150;
// GPS精度に応じた閾値補正の上限(m)。公開しない: 値そのものは
// accuracyBonus.test.ts がリテラルで固定しており、外から突き合わせる用途は無い。
// 公開して突き合わせに使うと、値を変えてもテストが通るトートロジーになる。
const MAX_ACCURACY_BONUS = 150;

/**
* GPS精度に応じて到着圏・接近圏へ加える補正(m)を返す。
Expand Down
Loading