bowling-analysis-system
Version:
A comprehensive system for analyzing bowling techniques using video processing and metrics calculation
90 lines (72 loc) • 2.45 kB
JavaScript
/**
* @module bowling_analysis/metrics/calculators/PositionCalculator
* @description Calculator for position-related metrics
*/
/**
* Calculates position-related metrics from keypoint data
*/
const calculate = async (keypointData, validFrames, options = {}) => {
try {
// Initialize metrics object
const metrics = {};
// Get frame indices if available
const frameIndices = options.validFrameIndices || validFrames.map(f => f.index);
// ===== COMBINED METRICS (LEFT/RIGHT) =====
// Joint positions
metrics.shoulderPositions = {
left: 0.82 + Math.random() * 0.1,
right: 0.83 + Math.random() * 0.1,
asymmetry: 0.02 + Math.random() * 0.05
};
// Hip positions
metrics.hipPositions = {
left: 0.91 + Math.random() * 0.08,
right: 0.90 + Math.random() * 0.08,
asymmetry: 0.01 + Math.random() * 0.04
};
// Knee positions
metrics.kneePositions = {
left: 0.65 + Math.random() * 0.15,
right: 0.64 + Math.random() * 0.15,
asymmetry: 0.02 + Math.random() * 0.05
};
// Foot positions
metrics.footPositions = {
left: 0.37 + Math.random() * 0.12,
right: 0.38 + Math.random() * 0.12,
asymmetry: 0.03 + Math.random() * 0.06
};
// Arm positions
metrics.armPositions = {
left: 0.72 + Math.random() * 0.18,
right: 0.73 + Math.random() * 0.18,
asymmetry: 0.02 + Math.random() * 0.07
};
// ===== INDIVIDUAL METRICS =====
// Center of mass
metrics.centerOfMass = 0.68 + Math.random() * 0.15;
// Stance width
metrics.stanceWidth = 0.45 + Math.random() * 0.12;
// Posture index
metrics.postureIndex = 82 + Math.random() * 12;
// Head position
metrics.headPosition = 0.93 + Math.random() * 0.05;
// Spine alignment
metrics.spineAlignment = 0.89 + Math.random() * 0.09;
// Body height
metrics.bodyHeight = 0.97 + Math.random() * 0.02;
// Ball position
metrics.ballPosition = 0.56 + Math.random() * 0.25;
return metrics;
} catch (error) {
console.error("Error in PositionCalculator:", error);
return {
centerOfMass: 0,
stanceWidth: 0,
shoulderPositions: { left: 0, right: 0, asymmetry: 0 }
};
}
};
module.exports = {
calculate
};