UNPKG

bowling-analysis-system

Version:

A comprehensive system for analyzing bowling techniques using video processing and metrics calculation

87 lines (74 loc) 2.48 kB
/** * @module bowling_analysis/utils/EventValidator * @description Centralized event validation utility */ const { getStandardEventName } = require('./EventNameMapper'); /** * Validate event sequence and adjust confidence scores * @param {Object} events - Events object * @returns {Object} Validated events with adjusted confidence scores */ function validateEvents(events) { if (!events) { return { valid: false, events: null, error: 'No events provided' }; } // Standardize event names const standardizedEvents = {}; for (const [key, value] of Object.entries(events)) { const standardName = getStandardEventName(key); standardizedEvents[standardName] = value; } const { backFootLanding, frontFootLanding, releasePoint } = standardizedEvents; // Check required events if (!backFootLanding || !frontFootLanding || !releasePoint) { return { valid: false, events: standardizedEvents, error: 'Missing required events' }; } // Validate sequence const isValidSequence = ( backFootLanding.frameIndex < frontFootLanding.frameIndex && frontFootLanding.frameIndex < releasePoint.frameIndex ); if (!isValidSequence) { // Adjust confidence scores based on sequence violation const adjustedEvents = { ...standardizedEvents }; if (backFootLanding.frameIndex >= frontFootLanding.frameIndex) { adjustedEvents.backFootLanding.confidence *= 0.8; adjustedEvents.frontFootLanding.confidence *= 0.8; } if (frontFootLanding.frameIndex >= releasePoint.frameIndex) { adjustedEvents.frontFootLanding.confidence *= 0.8; adjustedEvents.releasePoint.confidence *= 0.8; } return { valid: false, events: adjustedEvents, error: 'Invalid event sequence' }; } return { valid: true, events: standardizedEvents, error: null }; } /** * Check if frame indices form a valid sequence * @param {number} backFootFrame - Back foot landing frame * @param {number} frontFootFrame - Front foot landing frame * @param {number} releaseFrame - Release point frame * @returns {boolean} True if sequence is valid */ function isValidFrameSequence(backFootFrame, frontFootFrame, releaseFrame) { return ( backFootFrame < frontFootFrame && frontFootFrame < releaseFrame ); } module.exports = { validateEvents, isValidFrameSequence };