110 lines
3.2 KiB
JavaScript
110 lines
3.2 KiB
JavaScript
/**
|
|
* Test: Motion Data Generation
|
|
*
|
|
* Validates that generated mouse trajectories look human.
|
|
*/
|
|
|
|
import { MotionGenerator } from '../src/generator/motion.js';
|
|
import { Logger } from '../src/utils/logger.js';
|
|
|
|
const logger = new Logger('TestMotion');
|
|
|
|
function test() {
|
|
logger.info('Starting motion generation test...');
|
|
|
|
const generator = new MotionGenerator({
|
|
screenWidth: 1920,
|
|
screenHeight: 1080,
|
|
checkboxPos: { x: 200, y: 300 },
|
|
});
|
|
|
|
const motion = generator.generate();
|
|
|
|
// Validate structure
|
|
logger.info('Validating motion data structure...');
|
|
|
|
if (!motion.st || typeof motion.st !== 'number') {
|
|
logger.error('Missing or invalid start timestamp (st)');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!Array.isArray(motion.mm) || motion.mm.length === 0) {
|
|
logger.error('Missing or empty mouse moves (mm)');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!Array.isArray(motion.md) || motion.md.length === 0) {
|
|
logger.error('Missing or empty mouse down (md)');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!Array.isArray(motion.mu) || motion.mu.length === 0) {
|
|
logger.error('Missing or empty mouse up (mu)');
|
|
process.exit(1);
|
|
}
|
|
|
|
logger.success('Structure validation passed');
|
|
|
|
// Analyze trajectory
|
|
logger.info('Analyzing trajectory characteristics...');
|
|
|
|
const mm = motion.mm;
|
|
let totalDistance = 0;
|
|
let straightLineDistance = 0;
|
|
let prevPoint = null;
|
|
|
|
for (const point of mm) {
|
|
if (prevPoint) {
|
|
const dx = point[0] - prevPoint[0];
|
|
const dy = point[1] - prevPoint[1];
|
|
totalDistance += Math.sqrt(dx * dx + dy * dy);
|
|
}
|
|
prevPoint = point;
|
|
}
|
|
|
|
// Calculate straight-line distance
|
|
const start = mm[0];
|
|
const end = mm[mm.length - 1];
|
|
const sdx = end[0] - start[0];
|
|
const sdy = end[1] - start[1];
|
|
straightLineDistance = Math.sqrt(sdx * sdx + sdy * sdy);
|
|
|
|
const curviness = totalDistance / straightLineDistance;
|
|
|
|
logger.info(`Total points: ${mm.length}`);
|
|
logger.info(`Path distance: ${totalDistance.toFixed(1)}px`);
|
|
logger.info(`Straight distance: ${straightLineDistance.toFixed(1)}px`);
|
|
logger.info(`Curviness ratio: ${curviness.toFixed(2)}x`);
|
|
|
|
if (curviness < 1.05) {
|
|
logger.warn('Trajectory is too straight! Looks robotic.');
|
|
logger.warn('Consider increasing bezier control point variance.');
|
|
} else if (curviness > 3.0) {
|
|
logger.warn('Trajectory is too curved! Looks erratic.');
|
|
} else {
|
|
logger.success('Trajectory curviness looks human');
|
|
}
|
|
|
|
// Check timing
|
|
const duration = mm[mm.length - 1][2] - mm[0][2];
|
|
logger.info(`Duration: ${duration}ms`);
|
|
|
|
if (duration < 200) {
|
|
logger.warn('Movement too fast! Humans are slower.');
|
|
} else if (duration > 5000) {
|
|
logger.warn('Movement too slow! Humans are faster.');
|
|
} else {
|
|
logger.success('Movement timing looks human');
|
|
}
|
|
|
|
// Output sample
|
|
logger.info('\nSample motion data (first 5 points):');
|
|
for (let i = 0; i < Math.min(5, mm.length); i++) {
|
|
console.log(` [${mm[i][0]}, ${mm[i][1]}, ${mm[i][2]}]`);
|
|
}
|
|
|
|
logger.success('\nMotion test completed');
|
|
}
|
|
|
|
test();
|