Initial Commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
|
||||
const INTERFERENCE_TYPES = new Set(['COE', 'P2P', 'P3P']);
|
||||
const DIRECTION_TYPES = new Set(['UL', 'DL', 'BI']);
|
||||
|
||||
/**
|
||||
* Parse a TC_WIFI_*.ini filename and its parent directory name into tags.
|
||||
* Returns an object with all tag fields plus id and file_id.
|
||||
*/
|
||||
function parseFilename(filename, parentDir) {
|
||||
// Strip prefix and extension → full derived ID used as primary key
|
||||
const base = filename.replace(/^TC_WIFI_/, '').replace(/\.ini$/, '');
|
||||
const id = base;
|
||||
const segments = base.split('_');
|
||||
|
||||
// Interference: first segment, fixed enum
|
||||
const interference = INTERFERENCE_TYPES.has(segments[0]) ? segments[0] : null;
|
||||
|
||||
// File ID: segment matching R<digit><ALNUM>+
|
||||
const file_id = segments.find(s => /^R\d+[A-Z0-9]+$/i.test(s)) || null;
|
||||
|
||||
// Device: segment matching CGW<digits>q
|
||||
const device = segments.find(s => /^CGW\d+$/.test(s)) || null;
|
||||
|
||||
// Test Point: segment starting with TPT
|
||||
const test_point = segments.find(s => /^TPT\w+$/.test(s)) || null;
|
||||
|
||||
// RSSI: segment matching RSSI<digits>
|
||||
const rssi = segments.find(s => /^RSSI\d+$/.test(s)) || null;
|
||||
|
||||
// Station: segment matching STA<digits>
|
||||
const station = segments.find(s => /^STA\d+$/.test(s)) || null;
|
||||
|
||||
// Band: segment matching <digit>GHZ
|
||||
const band = segments.find(s => /^\dGHZ$/.test(s)) || null;
|
||||
|
||||
// Channel: segment matching CH<digits>
|
||||
const channel = segments.find(s => /^CH\d+$/.test(s)) || null;
|
||||
|
||||
// Bandwidth: segment matching BW<digits>
|
||||
const bandwidth = segments.find(s => /^BW\d+$/.test(s)) || null;
|
||||
|
||||
// Direction: last segment, fixed enum
|
||||
const lastSeg = segments[segments.length - 1];
|
||||
const direction = DIRECTION_TYPES.has(lastSeg) ? lastSeg : null;
|
||||
|
||||
// Rotation from parent directory name: ROT<digits>
|
||||
const rotation = parentDir
|
||||
? (parentDir.split('_').find(s => /^ROT\d+$/.test(s)) || null)
|
||||
: null;
|
||||
|
||||
return { id, file_id, interference, device, test_point, rssi, station, band, channel, bandwidth, direction, rotation };
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a timestamp from a result log filename.
|
||||
* Matches YYYY-MM-DD-HH-MM or YYYY-MM-DD-HH-MM-SS at the end of the name.
|
||||
* Returns an ISO-ish string (e.g. "2026-05-16T07:30:14") or null.
|
||||
*/
|
||||
function parseTimestamp(filename) {
|
||||
const match = filename.match(/(\d{4}-\d{2}-\d{2}-\d{2}-\d{2}(?:-\d{2})?)(?:\.\w+)?$/);
|
||||
if (!match) return null;
|
||||
const parts = match[1].split('-');
|
||||
const [year, month, day, hour, minute, second = '00'] = parts;
|
||||
return `${year}-${month}-${day}T${hour}:${minute}:${second}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an elapsed time string "H:MM:SS.ffffff" to total seconds.
|
||||
*/
|
||||
function parseElapsedTime(timeStr) {
|
||||
const match = timeStr.match(/^(\d+):(\d{2}):(\d{2})\.(\d+)$/);
|
||||
if (!match) return null;
|
||||
const [, h, m, s, frac] = match;
|
||||
return parseInt(h) * 3600 + parseInt(m) * 60 + parseInt(s) + parseFloat(`0.${frac}`);
|
||||
}
|
||||
|
||||
module.exports = { parseFilename, parseTimestamp, parseElapsedTime };
|
||||
Reference in New Issue
Block a user