lerobot/robot-learning-tutorial
508
1// Test utilities for Large Dataset Support2// Run in browser console to validate sampling behavior3 4/**5 * Test suite for large dataset sampling6 */7export const LargeDatasetTests = {8 9 /**10 * Test basic sampling functionality11 */12 testBasicSampling() {13 console.log('๐งช Testing basic sampling functionality...');14 15 // Generate a dataset that should trigger sampling16 if (window.trackioInstance) {17 const result = window.trackioInstance.generateMassiveDataset(1000, 2);18 console.log('โ
Basic sampling test completed:', result);19 return result;20 } else {21 console.error('โ trackioInstance not found');22 return null;23 }24 },25 26 /**27 * Test massive dataset performance28 */29 testMassiveDataset() {30 console.log('๐งช Testing massive dataset (10K points)...');31 32 if (window.trackioInstance) {33 const startTime = performance.now();34 const result = window.trackioInstance.generateMassiveDataset(10000, 3);35 const endTime = performance.now();36 37 console.log(`โ
Massive dataset test completed in ${(endTime - startTime).toFixed(2)}ms`);38 console.log('๐ Result:', result);39 return { result, duration: endTime - startTime };40 } else {41 console.error('โ trackioInstance not found');42 return null;43 }44 },45 46 /**47 * Test sampling strategies48 */49 async testSamplingStrategies() {50 console.log('๐งช Testing different sampling strategies...');51 52 const { AdaptiveSampler } = await import('./adaptive-sampler.js');53 54 // Generate test data55 const testData = Array.from({ length: 1000 }, (_, i) => ({56 step: i + 1,57 value: Math.sin(i * 0.01) + Math.random() * 0.158 }));59 60 const strategies = ['uniform', 'smart', 'lod'];61 const results = {};62 63 strategies.forEach(strategy => {64 const sampler = new AdaptiveSampler({ 65 maxPoints: 400, 66 targetPoints: 100,67 adaptiveStrategy: strategy 68 });69 70 const startTime = performance.now();71 const result = sampler.sampleSeries(testData, strategy);72 const endTime = performance.now();73 74 results[strategy] = {75 originalLength: testData.length,76 sampledLength: result.data.length,77 compressionRatio: result.compressionRatio,78 duration: endTime - startTime,79 strategy: result.strategy80 };81 82 console.log(`๐ ${strategy}: ${result.data.length} points (${(result.compressionRatio * 100).toFixed(1)}% retained) in ${(endTime - startTime).toFixed(2)}ms`);83 });84 85 console.log('โ
Strategy comparison test completed');86 return results;87 },88 89 /**90 * Performance benchmark across different dataset sizes91 */92 async benchmarkPerformance() {93 console.log('๐งช Running performance benchmark...');94 95 const { AdaptiveSampler } = await import('./adaptive-sampler.js');96 const sampler = new AdaptiveSampler();97 98 const sizes = [500, 1000, 2000, 5000, 10000];99 const results = [];100 101 for (const size of sizes) {102 console.log(`๐ Testing ${size} points...`);103 104 // Generate test data105 const testData = Array.from({ length: size }, (_, i) => ({106 step: i + 1,107 value: Math.sin(i * 0.001) + Math.cos(i * 0.003) + Math.random() * 0.05108 }));109 110 // Measure sampling performance111 const startTime = performance.now();112 const result = sampler.sampleSeries(testData);113 const endTime = performance.now();114 115 const testResult = {116 originalSize: size,117 sampledSize: result.data.length,118 compressionRatio: result.compressionRatio,119 duration: endTime - startTime,120 pointsPerMs: result.data.length / (endTime - startTime)121 };122 123 results.push(testResult);124 console.log(`๐ ${size} โ ${result.data.length} points (${(result.compressionRatio * 100).toFixed(1)}%) in ${(endTime - startTime).toFixed(2)}ms`);125 }126 127 console.log('โ
Performance benchmark completed');128 console.table(results);129 return results;130 },131 132 /**133 * Test feature preservation134 */135 async testFeaturePreservation() {136 console.log('๐งช Testing feature preservation...');137 138 const { AdaptiveSampler } = await import('./adaptive-sampler.js');139 const sampler = new AdaptiveSampler({ preserveFeatures: true });140 141 // Generate data with clear features (peaks, valleys, inflection points)142 const testData = [];143 for (let i = 0; i < 1000; i++) {144 let value = 0;145 146 // Add some peaks and valleys147 value += Math.sin(i * 0.02) * 2; // Main oscillation148 value += Math.sin(i * 0.1) * 0.5; // Faster oscillation149 value += Math.cos(i * 0.005) * 1.5; // Slow trend150 151 // Add sharp peaks at specific points152 if (i === 200 || i === 600 || i === 800) {153 value += 3;154 }155 156 // Add noise157 value += (Math.random() - 0.5) * 0.1;158 159 testData.push({ step: i + 1, value });160 }161 162 const result = sampler.sampleSeries(testData);163 const features = result.features;164 165 console.log('๐ฏ Feature detection results:');166 console.log(` Peaks found: ${features?.peaks?.length || 0}`);167 console.log(` Valleys found: ${features?.valleys?.length || 0}`);168 console.log(` Inflection points: ${features?.inflectionPoints?.length || 0}`);169 console.log(` Compression: ${testData.length} โ ${result.data.length} (${(result.compressionRatio * 100).toFixed(1)}%)`);170 171 // Check if our artificial peaks are preserved172 const preservedPeaks = [200, 600, 800].filter(peakStep => 173 result.sampledIndices.some(idx => Math.abs(idx - peakStep) <= 2)174 );175 176 console.log(`๐ฏ Artificial peaks preserved: ${preservedPeaks.length}/3`);177 console.log('โ
Feature preservation test completed');178 179 return { result, features, preservedPeaks };180 },181 182 /**183 * Run all tests184 */185 async runAllTests() {186 console.log('๐ Running complete large dataset test suite...');187 188 const results = {189 basicSampling: this.testBasicSampling(),190 massiveDataset: this.testMassiveDataset(),191 samplingStrategies: await this.testSamplingStrategies(),192 performanceBenchmark: await this.benchmarkPerformance(),193 featurePreservation: await this.testFeaturePreservation()194 };195 196 console.log('๐ All tests completed!');197 console.log('๐ Full test results:', results);198 199 return results;200 }201};202 203/**204 * Quick test function for browser console205 */206export function testLargeDatasets() {207 return LargeDatasetTests.runAllTests();208}209 210/**211 * Expose to global scope for easy testing212 */213if (typeof window !== 'undefined') {214 window.LargeDatasetTests = LargeDatasetTests;215 window.testLargeDatasets = testLargeDatasets;216}217 218// Example usage in browser console:219// testLargeDatasets()220// LargeDatasetTests.testMassiveDataset()221// LargeDatasetTests.benchmarkPerformance()222 