UNPKG

bowling-analysis-system

Version:

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

51 lines (41 loc) 1.41 kB
/** * @fileoverview File loader stage for loading keypoint data */ const fs = require('fs'); class FileLoader { /** * Load keypoint data from file * @param {Object} params - Stage parameters * @param {string} params.filePath - Path to keypoint file * @param {Object} params.options - Stage options * @param {boolean} [params.options.debug] - Enable debug logging * @returns {Promise<Array>} Array of keypoint frames */ async execute({ filePath, options = {} }) { const { debug = false } = options; if (!filePath) { throw new Error('Keypoint file path is required'); } if (!fs.existsSync(filePath)) { throw new Error(`Keypoint file not found at path: ${filePath}`); } const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); const frames = data.frames || data; if (!Array.isArray(frames)) { throw new Error('Invalid keypoint data: frames not found or not an array'); } // Initialize all frames with null values first const totalFrames = 132; // Required frame count const nullFrames = Array(totalFrames).fill(null); // Map the loaded frames into the null frame array frames.forEach((frame, index) => { if (index < totalFrames) { nullFrames[index] = frame; } }); return nullFrames; } } module.exports = { FileLoader };