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