Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 2x 2x 2x 9x 45x 9x 7x 1x 6x 6x 6x 6x 30x 6x | import { ExtremumType, Interaction, InteractionType, InteractionVelocity } from '@reflex/shared-types';
import { Observable, map, of } from 'rxjs';
import { CalibrationService } from 'src/shared/services/calibration.service';
const positionKeys = [
'measuredPosition',
'smoothedPosition',
'matchingPosition',
'predictedPositionBasic',
'predictedPositionAdvanced'
] as const;
/** Calibrate all displayed positions together, retaining sensor values in the source snapshots. */
export function calibratePredictions(data: Array<InteractionVelocity>, service: CalibrationService): Observable<Array<InteractionVelocity>> {
Iif (!data.length) {
return of([]);
}
const positions: Array<Interaction> = data.flatMap((item) => positionKeys.map((key) => ({
touchId: item.touchId,
position: { ...item[key] },
confidence: item.confidence,
time: item.timestampSeconds,
type: InteractionType.None,
extremumDescription: { type: ExtremumType.Undefined, numFittingPoints: 0, percentageFittingPoints: 0 }
})));
return service.computeCalibratedPosition(positions).pipe(map((response) => {
if (!response.ok || response.body?.length !== positions.length) {
throw new Error('Could not calibrate prediction positions.');
}
const calibrated = response.body;
return data.map((item, index) => {
const result = { ...item };
positionKeys.forEach((key, offset) => {
result[key] = { ...calibrated[(index * positionKeys.length) + offset].position };
});
return result;
});
}));
}
|