bowling-analysis-system
Version:
A comprehensive system for analyzing bowling techniques using video processing and metrics calculation
265 lines (240 loc) • 6.33 kB
JavaScript
/**
* @module core/utils/PatternDetectionConfig
* @description Standardized configuration options for pattern detection
*/
/**
* Default configuration for pattern detection
* @type {Object}
*/
const DEFAULT_CONFIG = {
// Window size for pattern detection
windowSize: 5,
// Whether to use adaptive window sizing based on data length
adaptiveWindow: true,
// Minimum peak prominence (relative to local range)
minPeakProminence: 0.2,
// Minimum valley prominence (relative to local range)
minValleyProminence: 0.2,
// Minimum distance between detected features (in frames)
minDistance: 3,
// Smoothing factor for noise reduction (0 = no smoothing, 1 = max smoothing)
smoothingFactor: 0.2,
// Whether to detect inflection points
detectInflections: true,
// Threshold for inflection point detection
inflectionThreshold: 0.1
};
/**
* Configuration for foot landing detection
* @type {Object}
*/
const FOOT_LANDING_CONFIG = {
...DEFAULT_CONFIG,
// Specialized settings for foot landing detection
windowSize: 7,
minValleyProminence: 0.15,
smoothingFactor: 0.3
};
/**
* Configuration for release point detection
* @type {Object}
*/
const RELEASE_POINT_CONFIG = {
...DEFAULT_CONFIG,
// Specialized settings for release point detection
windowSize: 5,
minPeakProminence: 0.25,
smoothingFactor: 0.15
};
/**
* Configuration for correlation analysis
* @type {Object}
*/
const CORRELATION_CONFIG = {
...DEFAULT_CONFIG,
// Specialized settings for correlation analysis
windowSize: 9,
adaptiveWindow: true,
smoothingFactor: 0.25
};
/**
* Configuration for bias analysis
* @type {Object}
*/
const BIAS_ANALYSIS_CONFIG = {
...DEFAULT_CONFIG,
// Specialized settings for bias analysis
windowSize: 7,
adaptiveWindow: true,
smoothingFactor: 0.3,
minPeakProminence: 0.18,
minValleyProminence: 0.18
};
/**
* Configuration for velocity analysis
* @type {Object}
*/
const VELOCITY_ANALYSIS_CONFIG = {
...DEFAULT_CONFIG,
// Specialized settings for velocity analysis
windowSize: 5,
smoothingFactor: 0.25,
minValleyProminence: 0.15
};
/**
* Configuration for bowling event detection
* @type {Object}
*/
const BOWLING_EVENT_CONFIG = {
releasePoint: {
...RELEASE_POINT_CONFIG,
name: 'releasePoint',
description: 'Ball release point',
priority: 1,
requiredConfidence: 0.7,
correlationThreshold: 0.65,
metricPriority: [
'velocity.wristVelocity',
'angles.elbowFlexions',
'angles.shoulderRotations'
]
},
frontFootLanding: {
...FOOT_LANDING_CONFIG,
name: 'frontFootLanding',
description: 'Front foot landing',
priority: 2,
requiredConfidence: 0.6,
correlationThreshold: 0.55,
metricPriority: [
'velocity.ankleVelocity',
'position.leftFootHeight',
'angles.kneeFlexions'
]
},
backFootLanding: {
...FOOT_LANDING_CONFIG,
name: 'backFootLanding',
description: 'Back foot landing',
priority: 3,
requiredConfidence: 0.55,
correlationThreshold: 0.52,
metricPriority: [
'velocity.ankleVelocity',
'position.rightFootHeight',
'angles.kneeFlexions'
]
}
};
/**
* Combined configuration for pipeline stages
* @type {Object}
*/
const PIPELINE_CONFIG = {
// Stage types
STAGE_TYPES: {
// Core stage types
FILE_LOADER: 'fileLoader',
FILE_SAVER: 'fileSaver',
// Domain-specific stage types
KEYPOINT_PROCESSOR: 'keypointProcessor',
EVENT_DETECTOR: 'eventDetector',
METRICS_CALCULATOR: 'metricsCalculator',
BIAS_CALCULATOR: 'biasCalculator',
ANALYSIS_GENERATOR: 'analysisGenerator'
},
// Pipeline templates
TEMPLATES: {
METRICS_ONLY: {
name: 'metrics-only',
stages: [
{ type: 'fileLoader' },
{ type: 'keypointProcessor' },
{ type: 'metricsCalculator' },
{ type: 'fileSaver' }
]
},
FULL_ANALYSIS: {
name: 'full-analysis',
stages: [
{ type: 'fileLoader' },
{ type: 'keypointProcessor' },
{ type: 'metricsCalculator' },
{ type: 'eventDetector' },
{ type: 'biasCalculator' },
{ type: 'analysisGenerator' },
{ type: 'fileSaver' }
]
}
},
// Frame handling options
FRAME_HANDLING: {
preserveAllFrames: true
}
};
/**
* Get configuration for a specific detection type
* @param {string} type - Type of detection ('default', 'footLanding', 'releasePoint', 'correlation', 'bias', 'velocity')
* @param {Object} [overrides] - Optional configuration overrides
* @returns {Object} Configuration object
*/
function getConfig(type = 'default', overrides = {}) {
let config;
switch (type.toLowerCase()) {
case 'footlanding':
config = { ...FOOT_LANDING_CONFIG };
break;
case 'releasepoint':
config = { ...RELEASE_POINT_CONFIG };
break;
case 'correlation':
config = { ...CORRELATION_CONFIG };
break;
case 'bias':
config = { ...BIAS_ANALYSIS_CONFIG };
break;
case 'velocity':
config = { ...VELOCITY_ANALYSIS_CONFIG };
break;
default:
config = { ...DEFAULT_CONFIG };
}
// Apply overrides
return { ...config, ...overrides };
}
/**
* Get a pipeline template by name
* @param {string} templateName - Template name
* @returns {Object|null} Pipeline template or null if not found
*/
function getPipelineTemplate(templateName) {
if (!templateName) return null;
const template = PIPELINE_CONFIG.TEMPLATES[templateName.toUpperCase()];
return template ? { ...template } : null;
}
/**
* Get a stage type configuration
* @param {string} stageType - Stage type
* @returns {string|null} Stage type or null if not found
*/
function getStageType(stageType) {
if (!stageType) return null;
return PIPELINE_CONFIG.STAGE_TYPES[stageType.toUpperCase()] || null;
}
/**
* Get configuration for a specific bowling event
* @param {string} eventName - Event name
* @returns {Object|null} Event configuration or null if not found
*/
function getBowlingEventConfig(eventName) {
return BOWLING_EVENT_CONFIG[eventName] || null;
}
module.exports = {
getConfig,
getPipelineTemplate,
getStageType,
getBowlingEventConfig,
DEFAULT_CONFIG,
BOWLING_EVENT_CONFIG,
PIPELINE_CONFIG
};