Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Examples/Example Calibration Files/LiquidCalibration.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"metadata": {
"modification_datetime": "2000-01-01T00:00:00"
"modification_datetime": "2000-01-01T00:00:00",
"COM": "example data"
},
"ValveDatas": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function updatePathAndSettings(BpodSystem, varargin)
%% -- Calibration Files
calFolder = BpodLib.path.getPath('calibration', BpodSystem, 'LocalDir', LocalDir);

if ~isfile(fullfile(Path.SettingsDir, 'LiquidCalibration.json')) && ~BpodLib.path.compatibility.isLegacySettings(Path.LocalDir)
freshSetup = ~isfile(fullfile(Path.SettingsDir, 'LiquidCalibration.json')) && ~BpodLib.path.compatibility.isLegacySettings(Path.LocalDir);
if freshSetup
fileNames = {'LiquidCalibration.json', 'SoundCalibration.mat', 'Readme.txt'};
for idx = 1:numel(fileNames)
fileName = fileNames{idx};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
valve3.addMeasurement(35, 3.5);
valve3.addMeasurement(66, 8.5);

% todo: these dates are different to the .JSON in Examples/
% Update LastDateModified to reflect the dummy data
valve1.LastDateModified = '2016-11-17T16:08:26'; % original from Bpod_Gen2
% valve3.LastDateModified = char(datetime('2024-07-17 09:22:28')); % the date of this function's creation
valve3.LastDateModified = "";

% Original MATLAB struct file had LastDateModified equivalent to 2016-11-17T16:08:26
dateString = "2000-01-01T00:00:00";
valve1.LastDateModified = dateString;
valve3.LastDateModified = dateString;
end
6 changes: 6 additions & 0 deletions Functions/+BpodLib/+calibration/+liquid/+utils/checkCOM.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
return
end

if strcmp(LiquidCal.metadata.COM, "example data")
% If the file's COM is example data, the liquid cal is just placeholder
% so we count that as "unknown"
return
end

if strcmp(LiquidCal.metadata.COM, BpodSystemCOM)
matchingCOM = 'yes';
else
Expand Down
24 changes: 24 additions & 0 deletions Functions/+BpodLib/+calibration/+liquid/+utils/createDefaultFile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function createDefaultFile()
% Create the default LiquidCalibration.json file in Examples/

LiquidCal= BpodLib.calibration.liquid.compatibility.createDummyData();
rootPath = BpodLib.path.getPath('root');
filePath = fullfile(rootPath, 'Examples/Example Calibration Files/LiquidCalibration.json');

% Insert data
dateString = "2000-01-01T00:00:00";
saveData = LiquidCal.createSaveData();
saveData.metadata.modification_datetime = dateString;
saveData.metadata.COM = "example data";

if verLessThan('matlab', '9.10') % R2021a is 9.10
writeData = jsonencode(saveData);
else
writeData = jsonencode(saveData, 'PrettyPrint', true);
end
fid = fopen(filePath, 'w');
fwrite(fid, writeData, 'char');
fclose(fid);


end
11 changes: 11 additions & 0 deletions Tests/BpodLib/calibration/liquid/test_dataWarning.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ function test_loadFailure(testCase)
% These should "fail" silently if the startup failed to load data
BpodLib.calibration.liquid.io.checkDefaultData([]);
BpodLib.calibration.liquid.io.report([])
end

function test_load_fresh(testCase)
BpodSystem = BpodTest.MockBpodObject('EMU');
filepath = fullfile(BpodLib.path.getPath('root'), 'Examples/Example Calibration Files/LiquidCalibration.json');
LiquidCal = BpodLib.calibration.liquid.ValveDataManagerClass('filepath', filepath);

BpodSystem.CalibrationTables.LiquidCal = LiquidCal;
LiquidCal.metadata.COM
BpodLib.calibration.liquid.utils.checkCOM(BpodSystem)
testCase.verifyTrue(strcmp('unknown', BpodLib.calibration.liquid.utils.checkCOM(BpodSystem)));
end
28 changes: 0 additions & 28 deletions Tests/BpodLib/calibration/liquid/test_liquidcalibration.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function setupOnce(testCase)
OriginalLiquidCal(3).Coeffs = [0.0479777954004750,5.72402854877083,13.6002180808882];

testCase.TestData.OriginalLiquidCal = OriginalLiquidCal;
% testCase.TestData.expectedJSONPath = fullfile('testData/ExpectedLiquidCalibration.json');
[testFolder, ~, ~] = fileparts(mfilename('fullpath'));
testDataFolder = fullfile(testFolder, 'testData');
testCase.TestData.expectedJSONPath = fullfile(testDataFolder, 'ExpectedLiquidCalibration.json');
Expand All @@ -34,33 +33,6 @@ function teardownOnce(testCase)
rmdir(testCase.TestData.rootPath, 's');
end


function test_JSONWrite(testCase)
% Test that the JSON format being saved by ValveManagerClass is correct

% Create test data and write JSON
dummyValveManager = BpodLib.calibration.liquid.compatibility.createDummyData();
dummyjsonPath = fullfile(testCase.TestData.rootPath, 'test.json');
dummyValveManager.saveData(dummyjsonPath);

% Read both files
jsonData = fileread(dummyjsonPath);
expectedData = fileread(testCase.TestData.expectedJSONPath);

% Normalize both JSON strings
jsonData = normalizeJSON(jsonData);
expectedData = normalizeJSON(expectedData);

% Compare the normalized versions
testCase.verifyEqual(jsonData, expectedData, 'JSON content does not match expected');

% If still failing, provide diagnostic output
if ~isequal(jsonData, expectedData)
fprintf('\n=== JSON COMPARISON FAILURE DETAILS ===\n');
showDiff(jsonData, expectedData);
end
end

function test_JSONRead(testCase)
% Test ValveDataManager's reading, ensuring values are in the right
% places
Expand Down