const fs = require('fs'); const path = require('path'); const assert = require('assert'); const { parseLogData, parseJobFile, convertToJobFile } = require('../satloc-util'); describe('parseLogData', () => { const TEST_LOG_FILE = 'satlog-8ea46d9c-9815-462f-9e80-d1396135ae9c'; const TEST_LOG_FILE2 = 'Liqud_IF2_G4.log'; const TEST_LOG_FILE3 = 'Liquid_IF2_Falcon.log'; it('should parse log file from binary buffer', () => { const EXPECTED_NUMBER_OF_RECORDS = 25558; const EXPECTED_FIRST_RECORD = { number: 0, length: 64, type: 1, checksum: 58, timestamp: '2004-07-00 22:26:60.60', latitude: 41.46584426488616, longitude: -96.64534387548957, altitude: 592.5615844726562, speed: 68.57242584228516, track: 123.83997344970703, xTrackDeviation: 0, differentialAge: 7, flags: 0 }; const EXPECTED_LAST_RECORD = { number: 25557, length: 64, type: 1, checksum: 175, timestamp: '2004-07-03 30:28:50.60', latitude: 40.56573913117167, longitude: -96.27117138055407, altitude: 3943.1943359375, speed: 48.31016159057617, track: 346.8262939453125, xTrackDeviation: 0, differentialAge: 7, flags: 0 }; const testLogFilePath = path.join(__dirname, `${TEST_LOG_FILE}`); const result = parseLogData(Buffer.from(fs.readFileSync(testLogFilePath, 'utf8'), 'base64')); assert.strictEqual(result.numberOfRecords, EXPECTED_NUMBER_OF_RECORDS); assert.deepStrictEqual(result.records[0], EXPECTED_FIRST_RECORD); assert.deepStrictEqual(result.records[result.numberOfRecords - 1], EXPECTED_LAST_RECORD); }); it('should parse log file2 from binary buffer', () => { const EXPECTED_NUMBER_OF_RECORDS = 20986; const EXPECTED_FIRST_RECORD = { number: 0, length: 78, type: 1, checksum: 219, timestamp: '2008-05-27 28:19:54.43', latitude: 31.745099434971642, longitude: -84.4216519403793, altitude: 73.64077758789062, speed: 9.91972827911377, track: 313.3026123046875, xTrackDeviation: 0, differentialAge: 7, flags: 0 }; const EXPECTED_LAST_RECORD = { number: 20985, length: 78, type: 1, checksum: 76, timestamp: '2008-05-11 11:20:02.43', latitude: 31.74735294675701, longitude: -84.4226968052226, altitude: 53.10984420776367, speed: 0, track: 0, xTrackDeviation: 0, differentialAge: 5, flags: 0 }; const testLogFilePath = path.join(__dirname, `${TEST_LOG_FILE2}`); const result = parseLogData(fs.readFileSync(testLogFilePath)); assert.strictEqual(result.numberOfRecords, EXPECTED_NUMBER_OF_RECORDS); assert.deepStrictEqual(result.records[0], EXPECTED_FIRST_RECORD); assert.deepStrictEqual(result.records[result.numberOfRecords - 1], EXPECTED_LAST_RECORD); }); it('should parse log file3 from binary buffer', () => { const EXPECTED_NUMBER_OF_RECORDS = 48524; const EXPECTED_FIRST_RECORD = { number: 0, length: 78, type: 1, checksum: 14, timestamp: '2008-07-07 29:42:52.35', latitude: 33.439654886722565, longitude: -97.28487503528595, altitude: 339.3522644042969, speed: 68.23239135742188, track: 269.1196594238281, xTrackDeviation: 0, differentialAge: 0, flags: 0 }; const EXPECTED_LAST_RECORD = { number: 48523, length: 78, type: 1, checksum: 189, timestamp: '2008-07-05 29:42:52.35', latitude: 33.43965870141983, longitude: -97.28435897827148, altitude: 329.0902099609375, speed: 69.45293426513672, track: 270.6729431152344, xTrackDeviation: -0.6736387610435486, differentialAge: 0, flags: 0 }; const testLogFilePath = path.join(__dirname, `${TEST_LOG_FILE3}`); const result = parseLogData(fs.readFileSync(testLogFilePath)); assert.strictEqual(result.numberOfRecords, EXPECTED_NUMBER_OF_RECORDS); assert.deepStrictEqual(result.records[0], EXPECTED_FIRST_RECORD); assert.deepStrictEqual(result.records[result.numberOfRecords - 1], EXPECTED_LAST_RECORD); }); }); describe('parseJobFile', () => { it('should correctly parse inclusion and exclusion zones from Job - Simple.job', () => { const expectedOutput = { inclusion_zones: [ { pol_id: '1', coordinates: [ [-98.474731, 33.867388], [-98.468352, 33.867531], [-98.468314, 33.858642], [-98.467129, 33.858579], [-98.467129, 33.855150], [-98.476573, 33.855594] ] }, { pol_id: '2', coordinates: [ [-98.484731, 33.877388], [-98.478352, 33.877531], [-98.478314, 33.868642], [-98.477129, 33.868579], [-98.477129, 33.865150], [-98.486573, 33.865594] ] } ], exclusion_zones: [ { pol_id: '3', coordinates: [ [-98.472731, 33.864388], [-98.470352, 33.866388], [-98.470452, 33.859642], [-98.472771, 33.858579] ] } ] }; const jobFileContent = fs.readFileSync(path.join(__dirname, 'Job - Simple.job'), 'utf8'); const result = parseJobFile(jobFileContent); assert.deepStrictEqual(result, expectedOutput); }); it('should correctly parse inclusion and exclusion zones from 500.job', () => { const jobFileContent = fs.readFileSync(path.join(__dirname, '500.job'), 'utf8'); const result = parseJobFile(jobFileContent); assert.equal(result.inclusion_zones.length, 8); assert.equal(result.exclusion_zones.length, 7); const expectedFirstInclusionZone = { pol_id: '1', coordinates: [ [ -79.34299, -2.38706 ], [ -79.343, -2.3872 ], [ -79.34314, -2.3872 ], [ -79.34313, -2.38705 ] ] } assert.deepStrictEqual(result.inclusion_zones[0], expectedFirstInclusionZone); assert.equal(result.inclusion_zones[7].pol_id, '12'); assert.equal(result.inclusion_zones[7].coordinates.length, 216); assert.deepStrictEqual(result.inclusion_zones[7].coordinates[0], [ -79.344920, -2.379120 ],); assert.deepStrictEqual(result.inclusion_zones[7].coordinates[215], [ -79.344970, -2.379060 ],); const expectedFirstExclusionZone = { pol_id: '6', coordinates: [ [ -79.34342, -2.38694 ], [ -79.34343, -2.387 ], [ -79.34337, -2.387 ], [ -79.34337, -2.38694 ] ] }; assert.deepStrictEqual(result.exclusion_zones[0], expectedFirstExclusionZone); const expectedLastExclusionZone = { pol_id: '15', coordinates: [ [ -79.344631, -2.391793 ], [ -79.344577, -2.392007 ], [ -79.344417, -2.392114 ], [ -79.34428, -2.392296 ], [ -79.343755, -2.392654 ], [ -79.343228, -2.389966 ], [ -79.344166, -2.389791 ] ] }; assert.deepStrictEqual(result.exclusion_zones[6], expectedLastExclusionZone); }); });