Compare commits
No commits in common. "ea33affc84d71352c91567b077e7e780cd4eaae5" and "77d13656c3593b1e36c93d0f8065a73cca52aa6b" have entirely different histories.
ea33affc84
...
77d13656c3
@ -2,76 +2,30 @@ function reorganize_data()
|
|||||||
basePath = '../';
|
basePath = '../';
|
||||||
rawDataPath = fullfile(basePath, 'raw_data');
|
rawDataPath = fullfile(basePath, 'raw_data');
|
||||||
|
|
||||||
% Initialize maps to track run files and transient run numbers
|
% Get all .mat files in the rawDataPath
|
||||||
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)
|
||||||
data = load(fullfile(files(i).folder, files(i).name));
|
filePath = 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);
|
||||||
runNumber = extractRunNumber(files(i).name);
|
newDir = fullfile('../sorted_data', tireid);
|
||||||
|
if ~exist(newDir, 'dir')
|
||||||
key = sprintf('%s_%s', tireid, testType);
|
mkdir(newDir);
|
||||||
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;
|
|
||||||
|
|
||||||
% Identify the transient run for cornering
|
newFilePath = fullfile(newDir, sprintf('%s.mat', testType));
|
||||||
if strcmpi(testType, 'cornering')
|
|
||||||
if transientRunMap.isKey(tireid)
|
|
||||||
transientRunMap(tireid) = min(transientRunMap(tireid), runNumber);
|
|
||||||
else
|
|
||||||
transientRunMap(tireid) = runNumber;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Create directories for each tireid if they don't exist
|
if exist(newFilePath, 'file')
|
||||||
mapKeys = runFilesMap.keys();
|
mergeData(newFilePath, filePath);
|
||||||
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
|
||||||
% Regular file processing
|
copyfile(filePath, newFilePath);
|
||||||
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
|
||||||
@ -117,13 +71,3 @@ 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