Compare commits
2 Commits
77d13656c3
...
ea33affc84
Author | SHA1 | Date | |
---|---|---|---|
ea33affc84 | |||
b964bcade5 |
@ -2,30 +2,76 @@ function reorganize_data()
|
|||||||
basePath = '../';
|
basePath = '../';
|
||||||
rawDataPath = fullfile(basePath, 'raw_data');
|
rawDataPath = fullfile(basePath, 'raw_data');
|
||||||
|
|
||||||
% Get all .mat files in the rawDataPath
|
% Initialize maps to track run files and transient run numbers
|
||||||
|
runFilesMap = containers.Map('KeyType', 'char', 'ValueType', 'any');
|
||||||
|
transientRunMap = containers.Map('KeyType', 'char', 'ValueType', 'double');
|
||||||
|
|
||||||
files = dir(fullfile(rawDataPath, '**/*.mat'));
|
files = dir(fullfile(rawDataPath, '**/*.mat'));
|
||||||
|
|
||||||
|
% Process files to categorize runs and identify transient runs
|
||||||
for i = 1:length(files)
|
for i = 1:length(files)
|
||||||
filePath = fullfile(files(i).folder, files(i).name);
|
data = load(fullfile(files(i).folder, files(i).name));
|
||||||
data = load(filePath);
|
|
||||||
|
|
||||||
if isfield(data, 'tireid') && isfield(data, 'testid')
|
if isfield(data, 'tireid') && isfield(data, 'testid')
|
||||||
tireid = data.tireid;
|
tireid = data.tireid;
|
||||||
testType = formatTestType(data.testid);
|
testType = formatTestType(data.testid);
|
||||||
newDir = fullfile('../sorted_data', tireid);
|
runNumber = extractRunNumber(files(i).name);
|
||||||
if ~exist(newDir, 'dir')
|
|
||||||
mkdir(newDir);
|
key = sprintf('%s_%s', tireid, testType);
|
||||||
|
if ~runFilesMap.isKey(key)
|
||||||
|
runFilesMap(key) = {};
|
||||||
end
|
end
|
||||||
|
runFiles = runFilesMap(key);
|
||||||
|
runFiles{end+1} = struct('path', fullfile(files(i).folder, files(i).name), 'runNumber', runNumber);
|
||||||
|
runFilesMap(key) = runFiles;
|
||||||
|
|
||||||
newFilePath = fullfile(newDir, sprintf('%s.mat', testType));
|
% Identify the transient run for cornering
|
||||||
|
if strcmpi(testType, 'cornering')
|
||||||
|
if transientRunMap.isKey(tireid)
|
||||||
|
transientRunMap(tireid) = min(transientRunMap(tireid), runNumber);
|
||||||
|
else
|
||||||
|
transientRunMap(tireid) = runNumber;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if exist(newFilePath, 'file')
|
% Create directories for each tireid if they don't exist
|
||||||
mergeData(newFilePath, filePath);
|
mapKeys = runFilesMap.keys();
|
||||||
|
tireids = unique(cellfun(@(x) strtok(x, '_'), mapKeys, 'UniformOutput', false));
|
||||||
|
for i = 1:length(tireids)
|
||||||
|
newDir = fullfile('../sorted_data', tireids{i});
|
||||||
|
if ~exist(newDir, 'dir')
|
||||||
|
mkdir(newDir);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
% Merge files in ascending order of run number and handle transient runs
|
||||||
|
for i = 1:length(mapKeys)
|
||||||
|
key = mapKeys{i};
|
||||||
|
runFiles = runFilesMap(key);
|
||||||
|
[tireid, testType] = strtok(key, '_');
|
||||||
|
testType = testType(2:end); % Remove leading underscore
|
||||||
|
|
||||||
|
% Extract run numbers and sort runs by run number
|
||||||
|
runNumbers = arrayfun(@(x) x.runNumber, [runFiles{:}]);
|
||||||
|
[~, idx] = sort(runNumbers);
|
||||||
|
sortedRuns = runFiles(idx);
|
||||||
|
|
||||||
|
newDir = fullfile('../sorted_data', tireid);
|
||||||
|
for j = 1:length(sortedRuns)
|
||||||
|
if strcmpi(testType, 'cornering') && sortedRuns{j}.runNumber == transientRunMap(tireid)
|
||||||
|
% Handle transient cornering run separately
|
||||||
|
newFilePath = fullfile(newDir, 'cornering_transient.mat');
|
||||||
|
copyfile(sortedRuns{j}.path, newFilePath);
|
||||||
else
|
else
|
||||||
copyfile(filePath, newFilePath);
|
% Regular file processing
|
||||||
|
newFilePath = fullfile(newDir, sprintf('%s.mat', testType));
|
||||||
|
if j == 1 || ~exist(newFilePath, 'file')
|
||||||
|
copyfile(sortedRuns{j}.path, newFilePath);
|
||||||
|
else
|
||||||
|
mergeData(newFilePath, sortedRuns{j}.path);
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
warning('Required fields not found in %s', filePath);
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -71,3 +117,13 @@ function mergeData(mergedFilePath, newFilePath)
|
|||||||
% Save the merged data
|
% Save the merged data
|
||||||
save(mergedFilePath, '-struct', 'existingData');
|
save(mergedFilePath, '-struct', 'existingData');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function runNumber = extractRunNumber(fileName)
|
||||||
|
num = sscanf(fileName, 'B2356run%d');
|
||||||
|
if isempty(num)
|
||||||
|
runNumber = NaN; % Indicate missing or invalid run number
|
||||||
|
else
|
||||||
|
runNumber = num;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user