131 lines
4.3 KiB
JavaScript
131 lines
4.3 KiB
JavaScript
/**
|
|
* SatLoc Filename Utility - Handles job ID extraction from SatLoc log filenames
|
|
* Supports multiple naming conventions used by different SatLoc systems
|
|
*/
|
|
|
|
/**
|
|
* Extract job ID from log file name based on naming conventions
|
|
* @param {string} fileName - The log file name
|
|
* @returns {string|null} Extracted job ID or null if not found
|
|
*/
|
|
function extractJobIdFromFileName(fileName) {
|
|
if (!fileName) return null;
|
|
|
|
// Remove file extension
|
|
const baseName = fileName.replace(/\.(log|LOG)$/i, '');
|
|
|
|
// Pattern 1: JOB[jobId] format (e.g., "JOB146 HK4704")
|
|
const jobPattern1 = /^JOB(\w+)/i;
|
|
const match1 = baseName.match(jobPattern1);
|
|
if (match1) {
|
|
return match1[1].trim();
|
|
}
|
|
|
|
// Pattern 2: [10 digits yymmddhhmm]_/' '[jobId] for Falcon system (e.g., "2507140724SatlocG4_b4ef")
|
|
// Extract the part after the 10 digits, looking for meaningful job identifier
|
|
const jobPattern2 = /^\d{10}(.+)$/;
|
|
const match2 = baseName.match(jobPattern2);
|
|
if (match2) {
|
|
let remaining = match2[1].trim();
|
|
// Remove common prefixes like "Satloc", "G4", etc.
|
|
remaining = remaining.replace(/^(Satloc|G4|_)+/i, '');
|
|
// Take the remaining part as job ID if it's meaningful
|
|
if (remaining && remaining.length > 0) {
|
|
return remaining.trim();
|
|
}
|
|
}
|
|
|
|
// Pattern 3: [8 digits date]_JOB[jobId] for Bantom2 system (e.g., "20250915_JOB789")
|
|
const jobPattern3 = /^\d{8}_JOB(\w+)/i;
|
|
const match3 = baseName.match(jobPattern3);
|
|
if (match3) {
|
|
return match3[1].trim();
|
|
}
|
|
|
|
// Pattern 4: [10 digits with space] [jobId] for Falcon system (e.g., "2025091512 CROP001")
|
|
const jobPattern4 = /^\d{10}\s+(.+)$/;
|
|
const match4 = baseName.match(jobPattern4);
|
|
if (match4) {
|
|
return match4[1].trim();
|
|
}
|
|
|
|
// Pattern 5: Falcon [jobId] or [jobId]-Log_YYMMDD_N format (e.g., "150-12-06-2025", "150-12-06-2025-Log_251209_0")
|
|
// JobId format: typically contains date like "150-12-06-2025" or similar patterns with dashes
|
|
// If "-Log_" suffix exists, extract jobId before it; otherwise use the whole baseName
|
|
// Loosened pattern: capture anything before '-Log' and accept any suffix after it
|
|
// Example matches: '150-12-06-2025-Log_251209_0', '150-12-06-2025-LogExtra', '150-12-06-2025-Log'
|
|
const logSuffixPattern = /^(.+?)-Log.*$/i;
|
|
const match5 = baseName.match(logSuffixPattern);
|
|
if (match5) {
|
|
return match5[1].trim();
|
|
}
|
|
|
|
// Pattern 6: If baseName looks like a Falcon jobId (contains dashes with date-like pattern)
|
|
// e.g., "150-12-06-2025" - return as-is if it matches a reasonable job ID pattern
|
|
const falconJobIdPattern = /^[\w]+-\d{2}-\d{2}-\d{4}$/;
|
|
if (falconJobIdPattern.test(baseName)) {
|
|
return baseName;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Check if a filename contains a recognizable job ID pattern
|
|
* @param {string} fileName - The log file name
|
|
* @returns {boolean} True if filename contains a job ID pattern
|
|
*/
|
|
function hasJobIdPattern(fileName) {
|
|
return extractJobIdFromFileName(fileName) !== null;
|
|
}
|
|
|
|
/**
|
|
* Get supported filename patterns for documentation/validation
|
|
* @returns {Array} Array of pattern descriptions
|
|
*/
|
|
function getSupportedPatterns() {
|
|
return [
|
|
{
|
|
name: 'Direct JOB Pattern',
|
|
format: 'JOB[jobId]',
|
|
example: 'JOB146 HK4704.log',
|
|
description: 'Direct format with JOB prefix'
|
|
},
|
|
{
|
|
name: 'Falcon System Pattern',
|
|
format: '[10 digits yymmddhhmm][separator][jobId]',
|
|
example: '2507140724SatlocG4_b4ef.log',
|
|
description: 'Falcon system with timestamp and job identifier'
|
|
},
|
|
{
|
|
name: 'Falcon System with Space',
|
|
format: '[10 digits yymmddhhmm] [jobId]',
|
|
example: '2025091512 CROP001.log',
|
|
description: 'Falcon system with space separator'
|
|
},
|
|
{
|
|
name: 'Bantom2 System Pattern',
|
|
format: '[8 digits date]_JOB[jobId]',
|
|
example: '20250915_JOB789_field1.log',
|
|
description: 'Bantom2 system with date prefix and JOB'
|
|
},
|
|
{
|
|
name: 'Falcon Job with Log Suffix',
|
|
format: '[jobId]-Log_YYMMDD_N',
|
|
example: '150-12-06-2025-Log_251209_0.log',
|
|
description: 'Falcon system with job ID and log timestamp suffix'
|
|
},
|
|
{
|
|
name: 'Falcon Job ID Only',
|
|
format: '[prefix]-DD-MM-YYYY',
|
|
example: '150-12-06-2025.log',
|
|
description: 'Falcon system with job ID containing date pattern'
|
|
}
|
|
];
|
|
}
|
|
|
|
module.exports = {
|
|
extractJobIdFromFileName,
|
|
hasJobIdPattern,
|
|
getSupportedPatterns
|
|
}; |