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

add new Error methods

parents dc8a0986 f456bb69
No related branches found
No related tags found
1 merge request!23Dev/default behaviour
Pipeline #581693 passed
classdef userDLG
%userDLG the userDLG Class is responsible for the user dialog
% error handeling, user messages and warnings will be provided from
% the catchError class, depending on the user options and error type.
% this class, depending on the user options and error type.
% This reduces messaging overhead and code length in PlotID.Publish()
properties
......@@ -10,22 +10,24 @@ classdef userDLG
rdFilesPublished = false
figurePublished = false
msg = ''
showMessages = false
end
properties (SetAccess = protected)
success = false
showMessages {mustBeNumericOrLogical}
forcePublish {mustBeNumericOrLogical}
ID %plotID
end
methods
function obj = catchError(ID)
function obj = userDLG(ID,options)
%CATCHERROR Construct an instance of this class
if isempty(ID)
ID = '';
end
obj.ID = ID;
obj.showMessages = options.ShowMessages;
obj.forcePublish = options.ForcePublish;
end
function output = get.success(obj)
......@@ -35,10 +37,37 @@ classdef userDLG
output = obj.success;
end
function obj = set.msg(obj,errorMessage)
function obj = set.msg(obj,message)
%setmsg Summary of this method goes here
% Detailed explanation goes here
obj.msg = errorMessage;
obj.msg = message;
end
function [] = userMSG(obj,message)
%userMSG user message without priority
% MSG will only be displaye if ShowMessages is true
if obj.showMessages
disp(message);
end
end
function [] = error(message)
%error handles critical errors
% critical errors will always result in a matlab error
%ToDO: Add function(s) before termination
error(message);
end
function [] = softError(obj,message)
%softError handles soft errors
% soft errors can be changed to warning if ForcePublish is
% selected by the user
if obj.forcePublish
warning(message);
else
error(message);
end
end
function outputArg = method1(obj,inputArg)
......
......@@ -54,18 +54,18 @@ if isempty(ID)
warning(msg);
end
dlgObj = PlotID.userDLG(ID); % Error and MSG handeling
dlgObj.showMessages = options.ShowMessages;
dlgObj = PlotID.userDLG(ID,options); % Error and MSG handeling
%% read config file
try
txt = fileread('config.json');
config = jsondecode(txt);
catch
dlgObj.configError = true;
msg = ['Error while reading the config file' newline,...
' publishing on server not possible'];
warning(msg);
dlgObj.configError = true;
dlgObj.softError(msg);
end
%% storage location
......@@ -90,17 +90,18 @@ folderName = ['.',char(ID)]; %hidden folder
%% Create Data-Directory
if isfolder(fullfile(storPath,folderName))
error(['Folder ',folderName, ' exists - Plot was already published ']);
dlgObj.error(['Folder ',folderName, ' exists - Plot was already published ']);
elseif mkdir(fullfile(storPath,folderName))
else
error('Directory could not be created - check remote path and permissions');
dlgObj.error('Directory could not be created - check remote path and permissions');
end
disp(['publishing of ', ID, ' started']);
%% Create a Copy of the script and user functions(optional)
% script
[~, status] = PlotID.createFileCopy({scriptPath},folderName,storPath,ID, 'script');
dlgObj.scriptPublished =status; % obj will be passed to createFileCopy
[~, status, msg] = PlotID.createFileCopy({scriptPath},folderName,storPath,ID, 'script');
dlgObj.scriptPublished =status;
dlgObj.userMSG(msg);
% user functions
[fList,pList] = matlab.codetools.requiredFilesAndProducts(scriptPath);
......@@ -147,7 +148,7 @@ switch options.Method
end
else % no identical file exists
%Copy the file in data and create the links (if hdf5)
[dataPath] = PlotID.createFileCopy(DataPaths{i},'data',storPath,ID,'dataCentral');
[dataPath, status, msg] = PlotID.createFileCopy(DataPaths{i},'data',storPath,ID,'dataCentral');
pathToData = strrep(dataPath,currentPath,'');
%WIP
if contains(DataPaths{i},{'.h5','.hdf5'}) % Linking only for HDF5
......@@ -160,10 +161,11 @@ switch options.Method
clear DataFolderName
case 'individual'
% Create a copy of the research data
[~, status] = PlotID.createFileCopy(DataPaths,folderName,storPath,ID, 'data');
[~, status, msg] = PlotID.createFileCopy(DataPaths,folderName,storPath,ID, 'data');
end
%temporary:
dlgObj.rdFilesPublished = status;
dlgObj.userMSG(msg);
%% Write Config File
if ~dlgObj.configError %config File must exist
......@@ -200,7 +202,7 @@ try
exportgraphics(figure,[RemotePath,'.png'],'Resolution',300);
dlgObj.figurePublished = true;
catch
warning('Plot export was not successful')
dlgObj.softError('Plot export was not successful');
end
% CSV EXport
......@@ -229,7 +231,7 @@ if status
disp(['publishing of ', ID , ' done']); %always displayed onsucess
else % publish was not sucessfull!
%replace with error from userDLG Class
error(['publishing of ', ID , ' failed'])
dlgObj.error(['publishing of ', ID , ' failed'])
end
......@@ -244,7 +246,7 @@ end
function mustBeDataPath(DataPaths)
%checks if input is a valid DataPath object
if iscellstr(DataPaths)
if isstring(DataPaths)
tf = zeros(1,numel(DataPaths));
for i=1:numel(DataPaths)
tf(i) = ~isfile(DataPaths{i});
......
......@@ -15,9 +15,10 @@ arguments
figs (1,:) {mustBeFigure}
options.ProjectID (1,:) {mustBeText}= ''
options.Fontsize (1,1) {mustBeInteger} = 8
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) {mustBeInteger} = 0
options.Rotation (1,1) {mustBeReal} = NaN
end
if isempty(options.ProjectID)
......@@ -41,16 +42,19 @@ end
switch options.Location
case 'north'
options.Position = [0.4,0.95];
options.Rotation = 0;
Rotation = 0;
case 'east'
options.Position = [1,0.4];
options.Rotation = 90;
Rotation = 90;
case 'south'
options.Position = [0.4,.02];
options.Rotation = 0;
Rotation = 0;
case 'west'
options.Position = [.05,0.4];
options.Rotation = 90;
Rotation = 90;
case 'southeast'
options.Position = [0.8,.02];
Rotation = 0;
case 'custom'
% Check if Position is valid
if ~all(0 <= options.Position & options.Position <= 1)
......@@ -62,6 +66,10 @@ switch options.Location
options.Location = 'east'; options.Position = [1,0.4];
end
if ~isnan(options.Rotation)
Rotation = options.Rotation;
end
IDs = cell(numel(figs),1);
for n = 1:numel(figs)
......@@ -72,10 +80,11 @@ for n = 1:numel(figs)
ylim =get(axes,'YLim');
xlim =get(axes,'XLim');
%ID
position = [options.Position(1)*xlim(2), options.Position(2)*ylim(2)];
position = [options.Position(1), options.Position(2)];
text(axes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,...
'Rotation',options.Rotation, 'VerticalAlignment','bottom','Color',...
0.65*[1 1 1],'BackgroundColor','w');
'Rotation',Rotation, 'VerticalAlignment','bottom','Color',...
options.Color,'BackgroundColor','w', 'Units', 'normalized');
set(figs(n),'Tag', IDs{n});
end
......
function [storagePaths, status] = createFileCopy(filePaths,folderName,storPath,ID,type)
function [storagePaths, status, msg] = createFileCopy(filePaths,folderName,storPath,ID,type)
% Creates a copy of the files (can be used for multiple paths in a cell array)
% folderName is the name of the exporting folder
% returns the storage paths were files were stored
......@@ -69,7 +69,7 @@ try
storagePaths{i} = RemotePath;
end
status = true;
disp([type, ' successfully published']);
msg =([type, ' successfully published']);
catch
status = false;
warning([type,' export was not sucessful'])
......
......@@ -43,7 +43,8 @@ h5write(fpath, "/y1", y1)
% Place for post-processing of the data, or additional related code.
% example_fcn is a dummy function to show the functionality
a = 1; a = example_fcn(a);
p = betacdf(0.5,1,1); % to test toolboxes
% Uncomment to include the Statistics and Machine learning Toolbox
% p = betacdf(0.5,1,1); % to test toolboxes
%% Plotting
% This is still part of a normal script to produce plots.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment