feat: refactor parsing and scanning logic for test files

- Updated `parseFilename` to `parseTargetFilename` and modified its return structure to include `test_id` instead of `file_id`.
- Introduced `parseResultFilename` to extract `test_id` and `device` from result file names.
- Enhanced `fullScan` to separately handle target and results directories, improving clarity and functionality.
- Updated database interactions to use `test_id` instead of `file_id` across various modules.
- Added a new `/rescan` endpoint to trigger a full scan of target and results directories.
- Improved logging and error handling throughout the scanning process.
- Introduced `parseTputRssi` to extract throughput and RSSI data from log files.
This commit is contained in:
2026-05-21 14:53:08 -04:00
parent ed0f93036d
commit a67815c61a
22 changed files with 9791 additions and 228 deletions
+29 -11
View File
@@ -5,22 +5,22 @@ 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.
* Returns an object with all tag fields plus id and test_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('_');
function parseTargetFilename(filename, parentDir) {
const baseName = filename.replace(/\.ini$/i, '');
const segments = baseName.split('_').slice(2); // Skip "TC" and "WIFI" prefix
const id = `${parentDir}/${baseName}`;
// 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;
const test_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;
// Device: segment after interference
const device = segments.length > 1 ? segments[1] : null;
// Test Point: segment starting with TPT
const test_point = segments.find(s => /^TPT\w+$/.test(s)) || null;
@@ -49,7 +49,16 @@ function parseFilename(filename, 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 };
return { id, test_id, interference, device, test_point, rssi, station, band, channel, bandwidth, direction, rotation };
}
function parseResultFilename(filename){
// Extract test_id and device from result file name
// COE_CGW453_R2COERXAX014_TPT3E_RSSI70_STA56_2GHZ_CH1_BW20_TCP_MIMOFD_SONFD_MESHFD_LPI_UL
const segments = filename.split(/[_\-]/);
const test_id = segments.find(s => /^R\d+[A-Z0-9]+$/.test(s)) || null;
const device = segments.length > 1 ? segments[1] : null; // Assuming device is the second segment
return { test_id, device };
}
/**
@@ -75,4 +84,13 @@ function parseElapsedTime(timeStr) {
return parseInt(h) * 3600 + parseInt(m) * 60 + parseInt(s) + parseFloat(`0.${frac}`);
}
module.exports = { parseFilename, parseTimestamp, parseElapsedTime };
function parseTputRssi(line) {
// Parse a line for station, tput, and RSSI info. Ex:
// [2026-05-18 15:09:46,167 INFO] STA56 over angles >> AVG IxChariot TPUT: 1464 Mbps, AVG DL RSSI: -42 dBm, AVG UL RSSI: -50 dBm, CHANNEL: 100
const match = line.match(/STA(\d+) over angles >> AVG IxChariot TPUT: (\d+) Mbps, AVG DL RSSI: (-?\d+) dBm, AVG UL RSSI: (-?\d+) dBm/);
if (!match) return null;
const [, station, tput, dlRssi, ulRssi] = match;
return { station: parseInt(station), tput: parseInt(tput), dlRssi: parseInt(dlRssi), ulRssi: parseInt(ulRssi) };
}
module.exports = { parseTargetFilename, parseResultFilename, parseTimestamp, parseElapsedTime, parseTputRssi };