Skip to content
Snippets Groups Projects
Commit 83b74423 authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

Add config Class, Implement Wizard

#53, #63
parent d64f24b9
Branches
Tags
2 merge requests!30Fix CI,!29Add config Class, Implement Wizard
Pipeline #584626 passed
classdef config
%CONFIG class handles methoths and attributes related to the config
%file
% Detailed explanation goes here
properties (SetAccess = protected)
configData
configFileName
end
methods
function obj = config(configFileName)
%CONFIG Construct an instance of this class
% Detailed explanation goes here
obj.configFileName = configFileName;
try
txt = fileread(obj.configFileName);
obj.configData = jsondecode(txt);
checkConfig(obj);
catch
msg = ['no valid config File with the filename ',...
obj.configFileName, ' found.' newline,...
'Please enter the required information manually'];
disp(msg);
obj.configData = obj.wizard('initilise');
m = input('Do you want to save the config, Y/N [Y]:','s');
if ismember(m,{'Y','y'})
obj.writeConfig(fullfile(pwd));
end
end%try
end
function outputArg = checkConfig(obj)
%checkConfig validates the config file
% TODo;
outputArg = true;
end
function outputArg = writeConfig(obj,path)
%writeConfig writes the config file to path
% TODo;
fid = fopen(fullfile(path,obj.configFileName),'w');
txt = jsonencode(obj.configData,'PrettyPrint',true);
fprintf(fid,txt);
fclose(fid);
end
function outputArg = method1(obj,inputArg)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
outputArg = obj.Property1 + inputArg;
end
end
methods (Static)
configStruct = wizard(mode)
optionStruct = plotID_options(input)
end
end
function [options] = plotID_options(input)
%PLOTID_OPTIONS Summary of this function goes here
% Detailed explanation goes here
switch input
case 'default'
options = struct();
options.Location = 'local'; % storage path
options.Method = 'individual';
options.ParentFolder = 'export';
options.ConfigFileName = 'config.json';%individual config names possible
options.CopyUserFCN = true;
options.CSV = false;
options.ShowMessages = true;
options.ForcePublish = false; %publish anyway
end
end
function config = wizard(mode)
%wizard creates config files depending on the selected mode
% initilise ask only for the input that is neccessary to run plotID
config = struct();
switch mode
case 'initilise'
config.Author = inputRequired('your Name');
config.ProjectID = inputRequired('your Project Number');
msg = ['Do you want to add a remote path?' newline,...
'Otherwise your files will be stored locally.' newline,...
'>ou can add this later by rerunning the initilisation.'];
disp(msg);
m = input('Do you want add a remothe path, Y/N [Y]:','s');
if ismember(m,{'Y','y'})
config.ServerPath = uigetdir();
end
otherwise
error('wizard mode undefined in CLASS config');
end %switch
end
function usrTxt = inputRequired(msg)
%Input Dialog that repeats if left empty
inputRequired = true;
while inputRequired
prompt = ['Please enter ', msg , ':'];
inpt = input(prompt,'s');
if isempty(inpt)
disp('Input must not be empty!');
else
usrTxt = inpt;
inputRequired = false;
end
end
end
\ No newline at end of file
......@@ -67,16 +67,19 @@ if isempty(ID)
warning(msg);
end
%% read config file
configObj = PlotID.config(options.ConfigFileName);
% try
% txt = fileread('config.json');
% config = jsondecode(txt);
% catch
% dlgObj.configError = true;
% end
% Error and MSG handeling
dlgObj = PlotID.userDLG(ID,options);
%% read config file
try
txt = fileread('config.json');
config = jsondecode(txt);
catch
dlgObj.configError = true;
end
%% storage location
switch options.Location
......@@ -183,20 +186,23 @@ dlgObj.rdFilesPublished = status;
dlgObj.userMSG(msg);
%% Write Config File
if ~dlgObj.configError
% copy config file
configPath = PlotID.createFileCopy('config.json',folderName,...
storPath,ID, 'data');
else
%create config file
configPath = fullfile(storPath,folderName,'config.json');
config = options;
end
%write config
fid = fopen(char(configPath),'w');
txt = jsonencode(config,'PrettyPrint',true);
fprintf(fid,txt);
fclose(fid);
exportPath = fullfile(storPath,folderName);
configObj.writeConfig(exportPath);
% if ~dlgObj.configError
% % copy config file
% configPath = PlotID.createFileCopy('config.json',folderName,...
% storPath,ID, 'data');
% else
% %create config file
% configPath = fullfile(storPath,folderName,'config.json');
% config = options;
% end
% %write config
% fid = fopen(char(configPath),'w');
% txt = jsonencode(config,'PrettyPrint',true);
% fprintf(fid,txt);
% fclose(fid);
% add further Metadata
meta =struct();
......
......@@ -18,25 +18,13 @@ arguments
options.Color (1,3) {mustBeNonnegative} = 0.65*[1 1 1] % grey
options.Location (1,:) {mustBeText} = 'east'
options.Position (1,2) {mustBeVector} = [1,0.4] % default for east
options.Rotation (1,1) {mustBeReal} = NaN
options.Rotation (1,1) {mustBeReal} = NaN
options.ConfigFileName (1,:) {mustBeText} = 'config.json'
end
if isempty(options.ProjectID)
try
txt = fileread('config.json');
config = jsondecode(txt);
catch
config =struct;
config.ProjectID = '';
warning("No ProjectID was definded and no config.json could be found");
end
if ~isempty(config.ProjectID)
options.ProjectID = config.ProjectID;
else
warning('no project options.ProjectID defined')
end
configObj = PlotID.config(options.ConfigFileName);
configData = configObj.configData;
end
switch options.Location
......
function [status] = initilise()
%INITILISE Initilisation for first time úsage
end
{
"Author": "Example Author",
"ProjectID": "AB01",
"ServerPath": "\\\\Server\\path\\folder"
}
......@@ -62,8 +62,8 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
% PlotID Implementation starts here.
% TagPlot adds a visible ID to the figure(s) and to the figures property
% 'Tag'
[fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID);
% [fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID);
[fig, ID] = PlotID.TagPlot(fig);
%% Publishing
% Second part of plotID
% The functions needs the file location of the script, the location of the
......@@ -76,7 +76,7 @@ scriptPath = [mfilename('fullpath'),'.m'];
%(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5'
locations = {dataset1,dataset2} ; % don't forget the extension
locations = {string(dataset1),dataset2}
locations = {string(dataset1),dataset2};
%call publishing
PlotID.Publish(locations,scriptPath, fig(1), 'Location', 'local' ,'Method','individual')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment