feat: Add standalone script for enhanced Bygma CSV import with validation test: Create simple database test to show current state and product counts test: Develop enhanced validation demo to simulate problematic CSV data handling test: Implement price validation tests with higher limits for edge cases test: Conduct real enhanced validation test with actual Bygma CSV file test: Test validation improvements with known problematic data test: Validate logic of cleaning and validating CSV rows without database test: Test improved VareNr cleaning functionality to remove spaces
80 lines
2.7 KiB
JavaScript
80 lines
2.7 KiB
JavaScript
/**
|
|
* Detailed analysis of specific problematic lines
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const csv = require('csv-parser');
|
|
|
|
async function analyzeSpecificLines() {
|
|
console.log('🔍 Detailed Analysis of Problematic Lines...\n');
|
|
|
|
const filePath = './frontend/firmadata/subvendor/bygma/PrisBog_20250918090450_38178059_ Tømrer- og Snedker Mikael Holck ApS_ 156.csv';
|
|
const problematicLines = [433, 434, 435, 436, 437, 438, 582, 583, 584, 585, 1837];
|
|
|
|
return new Promise((resolve) => {
|
|
let lineNumber = 0;
|
|
const foundLines = {};
|
|
|
|
fs.createReadStream(filePath)
|
|
.pipe(csv({
|
|
separator: ';',
|
|
headers: ['Varegrp', 'VareNr', 'Tekst', 'Enhed', 'BruttoPris', 'Opdat', 'Nettopris', 'DB-nr', 'EAN-nr', 'Std'],
|
|
skipLinesWithError: false,
|
|
strict: false
|
|
}))
|
|
.on('data', (row) => {
|
|
lineNumber++;
|
|
|
|
if (problematicLines.includes(lineNumber)) {
|
|
foundLines[lineNumber] = row;
|
|
}
|
|
})
|
|
.on('end', () => {
|
|
console.log('📋 Problematic Lines Analysis:\n');
|
|
|
|
problematicLines.forEach(line => {
|
|
if (foundLines[line]) {
|
|
const row = foundLines[line];
|
|
console.log(`Line ${line}:`);
|
|
console.log(`Raw data: ${JSON.stringify(row)}`);
|
|
|
|
// Check for parsing issues
|
|
const values = Object.values(row);
|
|
const emptyFields = values.filter(v => !v || v.trim() === '').length;
|
|
const nonEmptyFields = values.filter(v => v && v.trim() !== '').length;
|
|
|
|
console.log(`Fields: ${values.length} total, ${nonEmptyFields} non-empty, ${emptyFields} empty`);
|
|
|
|
// Check for semicolons in wrong places
|
|
const hasParsingErrors = values.some(value => {
|
|
if (!value || typeof value !== 'string') return false;
|
|
return value.includes(';;') || value.startsWith(';') || value.endsWith(';');
|
|
});
|
|
|
|
if (hasParsingErrors) {
|
|
console.log('❌ Contains parsing errors (semicolons in wrong places)');
|
|
}
|
|
|
|
// Check prices
|
|
const bruttoPris = row.BruttoPris;
|
|
const nettoPris = row.Nettopris;
|
|
|
|
if (!bruttoPris && !nettoPris) {
|
|
console.log('❌ Both prices missing');
|
|
} else if (bruttoPris === '0' && nettoPris === '0') {
|
|
console.log('❌ Both prices are zero');
|
|
}
|
|
|
|
console.log('');
|
|
} else {
|
|
console.log(`Line ${line}: Not found in data`);
|
|
}
|
|
});
|
|
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
analyzeSpecificLines();
|