From 5b4ff79774de6c98fbe276c7049e35a991b48a80 Mon Sep 17 00:00:00 2001
From: Jan Lemmer <jan.lemmer@fst.tu-darmstadt.de>
Date: Tue, 24 Aug 2021 11:50:46 +0200
Subject: [PATCH] Closes #23, fixes Bugs

---
 CI_files/default_test.m |  2 +-
 config.json             |  2 +-
 example.m               | 13 +++++++------
 fcn_core/CreateID.m     |  2 +-
 fcn_core/Publish.m      | 10 ++++++----
 fcn_core/TagPlot.m      | 19 +++++++++++++------
 fcn_help/fileCompare.m  |  6 +++---
 7 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/CI_files/default_test.m b/CI_files/default_test.m
index d346c13..c25bd97 100644
--- a/CI_files/default_test.m
+++ b/CI_files/default_test.m
@@ -41,7 +41,7 @@ plot(x1,y1,'-r');
 
 %% Tag the plot
 try
-    [figs, ID] = TagPlot(fig, ProjectID);
+    [figs, ID] = TagPlot(fig,'ProjectID', ProjectID);
 
     %% call a dummy function
     a=1;
diff --git a/config.json b/config.json
index b7a8bf8..23a100c 100644
--- a/config.json
+++ b/config.json
@@ -1,4 +1,4 @@
 {
-    "ProjectID": "JL01",
+    "ProjectID": "JL01", 
     "ServerPath": "\\\\FST-220\\Jans-50GB-SMB\\Lemmer"
 }
\ No newline at end of file
diff --git a/example.m b/example.m
index 16f69b5..ebdaf12 100644
--- a/example.m
+++ b/example.m
@@ -12,13 +12,14 @@ end
 
 
 %% Set ProjectID
-% ProjectID 
+% ProjectID can also be set in the config file 
 
 % TODO:  decide how projectID and optionally ORCID will be implemented
 % ORCID placed on startup (alternative?) - projectID as persistent
 % otherwise dialogue?
-ProjectID = 'JL01';
 
+% Leave empty for using the ID from the config file
+ProjectID = '';
 
 
 %% Data
@@ -65,7 +66,7 @@ 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] = TagPlot(fig, ProjectID);
+[fig, ID] = TagPlot(fig, 'ProjectID', ProjectID);
 
 %% Publishing
 % Second part of plotID 
@@ -79,7 +80,7 @@ path.rdata =  {dataset1,dataset2} ; % don't forget the extension
 
 Publish(path, ID, fig(1), 'Location', 'local','Method','centraliced')
 
-%% Example 2 : multiple plots plot, all based on two data-set2
+%% Example 2: multiple plots plot, all based on data-set2 (hdf5)
 % for individual data-sets, use an appropriate array
 
 fig(2) = figure;
@@ -89,7 +90,7 @@ plot(x1,y1,'--k');
 set(gca, 'TickDir', 'out', 'YLim', [0,4]);
 
 % tag both plots 
-[fig, IDs] = TagPlot(fig, ProjectID);
+[fig, IDs] = TagPlot(fig,'ProjectID', ProjectID);
 
 % data locations
 path.script = mfilename('fullpath'); % filename of the m.script
@@ -110,6 +111,6 @@ plot(x,y,'-k');
 hold on
 plot(x1,y1,'-r');
 
-[fig2, ID] = TagPlot(fig2, ProjectID);
+[fig2, ID] = TagPlot(fig2,'ProjectID', ProjectID);
 
 Publish(path, ID, fig2, 'Location', 'local','Method','centraliced')
\ No newline at end of file
diff --git a/fcn_core/CreateID.m b/fcn_core/CreateID.m
index 216e91a..2579717 100644
--- a/fcn_core/CreateID.m
+++ b/fcn_core/CreateID.m
@@ -10,7 +10,7 @@ switch method
     case 1 % UNIX Time in seconds as HEX
         ID = posixtime(datetime('now')); %get current Unix time
         ID = dec2hex(int32(ID)); % get it as Hex
-        pause(0.5); %Pausing for unique IDs
+        pause(1); %Pausing for unique IDs
     case 2 % random UUID from Java 128 bit
         %Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
         % The UUID is generated using a cryptographically strong pseudo
diff --git a/fcn_core/Publish.m b/fcn_core/Publish.m
index 3c21b56..7598802 100644
--- a/fcn_core/Publish.m
+++ b/fcn_core/Publish.m
@@ -2,7 +2,7 @@ function Publish(DataPaths, ID, figure, options)
 %Publishes saves plot, data and measuring script 
 %   Location sets the storage location. 'local' sets the storage location
 %   to the current folder (an export folder will be created), 'server' is a
-%   remote path.
+%   remote path, that is defined in the config file.
 %   Two Methods are implemented 'individual' stores the data for
 %   each plot while 'centralized' uses a data folder and uses reference links
 %   to the original data (hdf5 only).
@@ -28,15 +28,17 @@ end
 switch options.Location 
     case 'local'
          storPath = fullfile(pwd,'export');
-    case 'server'
-        storPath = '\\FST-220\Jans-50GB-SMB\Lemmer';
+    case 'server' %from config File
+         txt = fileread('config.json');
+         config = jsondecode(txt);
+         storPath = config.ServerPath;
     case 'CI-Test'
         storPath = fullfile(pwd,'CI_files','export');
 end
 folderName = char(ID);
 
 %% Create Data-Directory
-addpath(storPath);
+addpath(storPath); % ToDo necessary? - 
 if isfolder(fullfile(storPath,folderName))
    error(['Folder ',folderName, ' exists - Plot was already published ']);
 elseif mkdir(fullfile(storPath,folderName))
diff --git a/fcn_core/TagPlot.m b/fcn_core/TagPlot.m
index b3f0ae4..0032a89 100644
--- a/fcn_core/TagPlot.m
+++ b/fcn_core/TagPlot.m
@@ -1,10 +1,11 @@
-function [figs, IDs] = TagPlot(figs, prefix, options)
+function [figs, IDs] = TagPlot(figs, options)
 %TagPlot adds IDs to figures
 %   The ID is placed visual on the figure window and as Tag (property of figure)
 %   TagPlot can tag multiple figures at once.
 %   If a single Plot is taged IDs is a char, otherwise it is a cell array of
 %   chars 
-%   prefix is the project number (string or char)
+%   options.ProjectID is the project number (string or char), if empty the ID from the
+%   config file is used
 %   
 %   The ID is placed on the 'east' per default, if you want it somwhere
 %   else, use the 'Location' option. 'north','east','south','west' are
@@ -12,15 +13,21 @@ function [figs, IDs] = TagPlot(figs, prefix, options)
 %   'Position' (relative to your x- and y-axis limits)
 arguments
     figs (1,:) {mustBeFigure}
-    prefix (1,:) {mustBeText}= ''
+    options.ProjectID (1,:) {mustBeText}= ''
     options.Fontsize (1,1) {mustBeInteger} = 8 
     options.Location (1,:) {mustBeText} = 'east'
     options.Position (1,2) {mustBeVector} = [1,0.4] % default for east
     options.Rotation (1,1) {mustBeInteger} = 0  
 end
 
-if isempty(prefix)
-    warning('no project prefix defined')
+if isempty(options.ProjectID)
+   txt = fileread('config.json');
+   config = jsondecode(txt);
+   if ~isempty(config.ProjectID)
+       options.ProjectID = config.ProjectID;
+   else
+       warning('no project options.ProjectID defined')
+   end
 end
 
 switch options.Location
@@ -51,7 +58,7 @@ IDs = cell(numel(figs),1);
 
 for n = 1:numel(figs)
     IDs{n} = CreateID; % Create ID
-    IDs{n} = [prefix,'-',IDs{n}]; % add Prefix
+    IDs{n} = [options.ProjectID,'-',IDs{n}]; % add options.ProjectID
     axes = get(figs(n),'CurrentAxes'); % Axes object for text annotation
     % Limits for relative Positioning
     ylim =get(axes,'YLim');
diff --git a/fcn_help/fileCompare.m b/fcn_help/fileCompare.m
index c9007e7..8026faa 100644
--- a/fcn_help/fileCompare.m
+++ b/fcn_help/fileCompare.m
@@ -15,7 +15,7 @@ end
 id = zeros(height(fileList),1);
 
 for i=1:height(fileList)
-    [~,~,ext2] = fileparts(fileList.name{i});
+    [~,~,ext2] = fileparts(fileList{i,'name'});
 
     if ~isequal(ext1,ext2)
         %warning('File extension are not identical');
@@ -23,9 +23,9 @@ for i=1:height(fileList)
         continue
     end
 
-    filepath = fullfile(fileList.folder{i},fileList.name{i});
+    filepath = fullfile(fileList{i,'folder'},fileList{i,'name'});
     if ispc
-        [status,~] = system(['fc ' filename ' ' filepath]);
+        [status,~] = system(['fc ' filename ' ' char(filepath)]);
         % 0 -> identical, 1 -> not identical
          status = ~status; % false (not identical), true(identical)
                    
-- 
GitLab