UNPKG

bowling-analysis-system

Version:

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

165 lines (138 loc) 5.13 kB
/** * @module bowling_analysis/legacy-compatibility * @description Compatibility layer for legacy code during transition * @deprecated This module provides compatibility for deprecated code and should not be used in new implementations */ const BiasCalculator = require('./processors/BiasCalculator'); const { processFrames } = require('./index'); const { defaultLogger } = require('../utils/logger'); const systemConfig = require('../config/system-config'); /** * Legacy compatibility for BiasGenerator * @deprecated Use BiasCalculator directly instead */ const BiasGenerator = { /** * Generate bias from metrics * @param {Object} metrics - Metrics data * @param {Object} options - Options for bias generation * @returns {Promise<Object>} Bias data */ generateBias: async (metrics, options = {}) => { defaultLogger.warn('BiasGenerator.generateBias is deprecated, use BiasCalculator instead'); const biasCalculator = new BiasCalculator({ ...options, logger: options.logger || defaultLogger.child('legacy-bias-generator') }); const biasResult = await biasCalculator.calculateBias(metrics); return biasResult; }, /** * Legacy method to detect events from bias data * @param {Object} metrics - Metrics data * @param {Object} biasData - Bias data * @param {Object} options - Options for event detection * @returns {Object} Detected events */ detectEvents: async (metrics, biasData, options = {}) => { defaultLogger.warn('BiasGenerator.detectEvents is deprecated, use BiasCalculator.detectEventsWithBias instead'); const biasCalculator = new BiasCalculator({ ...options, logger: options.logger || defaultLogger.child('legacy-bias-generator') }); const events = await biasCalculator.detectEventsWithBias(metrics, biasData); // Map event names to legacy format if needed const legacyEvents = {}; for (const eventName in events) { const legacyName = getLegacyEventName(eventName); legacyEvents[legacyName] = { ...events[eventName], frameIndex: events[eventName].frame, // Add legacy property }; } return legacyEvents; } }; /** * Legacy compatibility for EventDetection * @deprecated Use BiasCalculator.detectEventsWithBias instead */ const EventDetection = { /** * Detect events from metrics data * @param {Object} metrics - Metrics data * @param {Object} options - Options for event detection * @returns {Object} Detected events */ detectEvents: async (metrics, options = {}) => { defaultLogger.warn('EventDetection.detectEvents is deprecated, use BiasCalculator instead'); const biasCalculator = new BiasCalculator({ ...options, logger: options.logger || defaultLogger.child('legacy-event-detection') }); // Calculate bias first const biasData = await biasCalculator.calculateBias(metrics); // Then detect events const events = await biasCalculator.detectEventsWithBias(metrics, biasData); // Map to legacy format const legacyEvents = {}; for (const eventName in events) { const legacyName = getLegacyEventName(eventName); legacyEvents[legacyName] = { ...events[eventName], frameIndex: events[eventName].frame }; } return legacyEvents; } }; /** * Get the legacy event name for a standard event * @param {string} standardEventName - Standard event name * @returns {string} Legacy event name */ function getLegacyEventName(standardEventName) { // Find legacy name in the legacy map (if it exists) for (const [legacyName, standardName] of Object.entries(systemConfig.LEGACY_EVENT_MAP)) { if (standardName === standardEventName) { return legacyName; } } // If not found, return the standard name return standardEventName; } /** * Legacy compatibility wrapper for processBowlingMetrics * @param {Array} frames - Array of frame data * @param {Object} options - Processing options * @returns {Promise<Object>} Processed metrics */ async function legacyProcessBowlingMetrics(frames, options = {}) { defaultLogger.warn('legacyProcessBowlingMetrics is deprecated, use processFrames instead'); // Call the new implementation const result = await processFrames(frames, options); // Add legacy properties if (result.metadata && result.metadata.validFrameIndices) { result.validIndices = result.metadata.validFrameIndices; } // Map event names to legacy format if needed if (result.events) { const legacyEvents = {}; for (const eventName in result.events) { const legacyName = getLegacyEventName(eventName); legacyEvents[legacyName] = { ...result.events[eventName], frameIndex: result.events[eventName].frame }; } result.events = legacyEvents; } return result; } module.exports = { BiasGenerator, EventDetection, processBowlingMetrics: legacyProcessBowlingMetrics, // Export the new implementation with its proper name for clarity processFrames };