96 lines
3.3 KiB
JavaScript
96 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Test Job Matching Logic Implementation
|
|
* Demonstrates how SatLoc Job IDs and Aircraft IDs are extracted and can be used for job matching
|
|
*/
|
|
|
|
const { SatLocLogParser } = require('./helpers/satloc_log_parser');
|
|
const SatLocApplicationProcessor = require('./helpers/satloc_application_processor');
|
|
|
|
async function testJobMatching() {
|
|
console.log('=== SatLoc Job Matching Test ===\n');
|
|
|
|
const testFiles = [
|
|
'./test-logs/Liquid_IF2_G4.log',
|
|
'./test-logs/Liquid_IF2_Falcon.log'
|
|
];
|
|
|
|
for (const filePath of testFiles) {
|
|
console.log(`🔍 Testing: ${filePath}`);
|
|
|
|
try {
|
|
// Step 1: Parse log file to extract job information
|
|
const parser = new SatLocLogParser({ outputAllRecords: true });
|
|
const result = await parser.parseFile(filePath);
|
|
|
|
if (!result.success) {
|
|
console.log(`❌ Parse failed: ${result.error}\n`);
|
|
continue;
|
|
}
|
|
|
|
// Step 2: Extract job matching information
|
|
const satlocJobIds = new Set();
|
|
let aircraftInfo = null;
|
|
|
|
result.records.forEach(record => {
|
|
// Extract Job ID from Swathing Setup (120)
|
|
if (record.recordType === 120 && record.jobId) {
|
|
satlocJobIds.add(record.jobId);
|
|
}
|
|
// Extract Aircraft ID from System Setup (100)
|
|
if (record.recordType === 100 && !aircraftInfo) {
|
|
aircraftInfo = {
|
|
aircraftId: record.aircraftId,
|
|
pilotName: record.pilotName,
|
|
gmtOffset: record.gmtOffset
|
|
};
|
|
}
|
|
});
|
|
|
|
// Step 3: Show job matching results
|
|
console.log(` Aircraft ID: ${aircraftInfo?.aircraftId || 'Not found'}`);
|
|
console.log(` Pilot Name: ${aircraftInfo?.pilotName || 'Not found'}`);
|
|
console.log(` SatLoc Job IDs: ${Array.from(satlocJobIds).join(', ') || 'None found'}`);
|
|
|
|
// Step 4: Show application details distribution by job
|
|
if (result.applicationDetails.length > 0) {
|
|
const jobDistribution = {};
|
|
result.applicationDetails.forEach(detail => {
|
|
const jobId = detail.satlocJobId || 'unknown';
|
|
jobDistribution[jobId] = (jobDistribution[jobId] || 0) + 1;
|
|
});
|
|
|
|
console.log(' Application Details by Job:');
|
|
Object.entries(jobDistribution).forEach(([jobId, count]) => {
|
|
console.log(` "${jobId}": ${count.toLocaleString()} records`);
|
|
});
|
|
}
|
|
|
|
// Step 5: Demonstrate job matching workflow
|
|
console.log('\n 🔄 Job Matching Workflow:');
|
|
if (aircraftInfo && satlocJobIds.size > 0) {
|
|
for (const satlocJobId of satlocJobIds) {
|
|
console.log(` 1. Aircraft "${aircraftInfo.aircraftId}" + Job "${satlocJobId}"`);
|
|
console.log(` 2. Look up AgMission Job assignments for aircraft "${aircraftInfo.aircraftId}"`);
|
|
console.log(` 3. Match SatLoc Job ID "${satlocJobId}" to AgMission Job`);
|
|
console.log(` 4. Create/update Application with matched Job ID`);
|
|
console.log(` 5. Split application details by SatLoc Job ID`);
|
|
}
|
|
} else {
|
|
console.log(' ⚠️ Incomplete job information - cannot perform matching');
|
|
}
|
|
|
|
console.log('');
|
|
|
|
} catch (error) {
|
|
console.log(`❌ Error: ${error.message}\n`);
|
|
}
|
|
}
|
|
|
|
console.log('✅ Job matching test completed');
|
|
}
|
|
|
|
// Run the test
|
|
testJobMatching().catch(console.error);
|