From f3698e8d17e4d43879439818299e85e3ca943543 Mon Sep 17 00:00:00 2001
From: "Lemmer, Jan" <jan.lemmer@fst.tu-darmstadt.de>
Date: Tue, 12 Oct 2021 13:41:58 +0200
Subject: [PATCH] Add Toolbox Information to config implements #33

---
 +PlotID/Publish.m   | 45 ++++++++++++++++++++++++++++-----------------
 README.md           | 36 ++++++++++++++++++------------------
 example-config.json |  3 ++-
 example.m           |  2 +-
 4 files changed, 49 insertions(+), 37 deletions(-)

diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m
index 4f82c2c..fcd7772 100644
--- a/+PlotID/Publish.m
+++ b/+PlotID/Publish.m
@@ -69,27 +69,12 @@ else
 end
 disp(['publishing of ', ID, ' started']);
 
-%% Create a Copy of the script, config and user functions(optional)
+%% Create a Copy of the script and user functions(optional)
 % script
 PlotID.createFileCopy({[DataPaths.script,'.m']},folderName,storPath,ID, 'script');
 
-% config
-[fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script);
-if ~configError %config File must exist
-   % copy config file 
-   configPath = PlotID.createFileCopy('config.json',folderName,...
-       storPath,ID, 'data');
-   % add Metadata 
-   config.MatlabVersion = version;
-   % TODO Add Toolboxes
-   %write config 
-   fid = fopen(char(configPath),'w');
-   txt = jsonencode(config,'PrettyPrint',true);
-   fprintf(fid,txt); 
-   fclose(fid);
-end
-
 % user functions
+[fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script);
 if options.CopyUserFCN 
    fList = fList(~ismember(fList,[DataPaths.script,'.m'])); % rmv script from list
    fList = fList(~contains(fList,'config.json')); % rmv config.json from list
@@ -146,6 +131,32 @@ switch options.Method
         % Create a copy of the research data    
         PlotID.createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
 end
+%% Write Config File
+
+if ~configError %config File must exist
+   % copy config file 
+   configPath = PlotID.createFileCopy('config.json',folderName,...
+       storPath,ID, 'data');
+else
+   configPath = fullpath(storPath,folderName, 'config.json');
+   config = struct(); 
+   if ispc
+    config.author = getenv('USERNAME');
+   end
+end
+% add further Metadata
+config.ProjectID = ID;
+config.CreationDate = datestr(now);
+config.MatlabVersion = version;
+config.ToolboxVersions = pList;
+
+%write config 
+fid = fopen(char(configPath),'w');
+txt = jsonencode(config,'PrettyPrint',true);
+fprintf(fid,txt); 
+fclose(fid);
+
+
 %% Export the Plot
 try 
        PlotName = [ID,'_plot']; % plotname
diff --git a/README.md b/README.md
index 973c29a..a9e8270 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,17 @@
 **PlotID**
- 
+
 `PlotID` is a toolkit that labels your plots and figures and copies all associated data (research data, plotting script, user-functions and a copy of the figure) to the desired location.
+
 This version of  `PlotID` is build for `MATLAB`.
 
-`PlotID` provides two core functions TagPlot and Publish which are described in detail below.
+`PlotID` provides two core functions **TagPlot** and **Publish** which are described in detail below.
 
 Feel free to give feedback and feature requests or to take part in the development process.
 
  [TOC]
 
 # Quick User Guide
-PlotID works in two Steps:
+`PlotID` works in two Steps:
 
 1. tagging the plot
 `[figs, IDs] = plotId.TagPlot(figs, options)`
@@ -25,27 +26,28 @@ PlotID works in two Steps:
 
 # PlotID.TagPlot()
 `[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 
+**TagPlot** adds IDs to figures
+The ID is placed visual on the figure window and as Tag (property of the figure)
+**TagPlot** can tag multiple figures at once. If a single Plot is tagged, IDs is a char, otherwise it is a cell array of chars .
 
 <details><summary>detailed description</summary>
 
 _options_ \
-you find the options for TagPlot below. The data is in curled braces and the default value follows the equal sign.
+you find the options for TagPlot below. The data type is in curled braces and the default value follows the equal sign.
 
--    ProjectID  {mustBeText}= ''
--    Fontsize {mustBeInteger} = 8 
--    Location  {mustBeText} = 'east'
--    Position  {mustBeVector} = [1,0.4] 
--    Rotation  {mustBeInteger} = 0  
+- ProjectID  {mustBeText}= '' 
+- Fontsize {mustBeInteger} = 8 
+- Location  {mustBeText} = 'east'
+- Position  {mustBeVector} = [1,0.4] 
+-  Rotation  {mustBeInteger} = 0  
 
-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' of the figure per default, if you want it somwhere else, use the 'Location' option. 'north','east','south','west' are  predefined, otherwise use the 'custom' option and provide the desired 'Position' (relative to your x- and y-axis limits)
+`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' of the figure per default, if you want it somwhere else, use the `'Location'` option. 'north', 'east', 'south', 'west' are predefined, otherwise use the `'custom'` option and provide the desired 'Position'  as a vector relative to your x- and y-axis limits `[relX, relY]` .
 </details>
+
 ## CreateID()
 `function [ID] = CreateID(method)` \
-CreateID Creates an identifier (char). It creates an (sometimes unique) identifier based on the selected method,if no method is selected method 1 will be the default method.
+CreateID Creates an identifier (char). It creates an (sometimes unique) identifier based on the selected method, if no method is selected method 1 will be the default method.
 
 1. **UNIX Time in seconds as HEX** \
 This is used by default due to its simplicity and it is human readable. 
@@ -54,7 +56,7 @@ Static factory to retrieve a type 4 (pseudo randomly generated) UUID. The UUID i
 
 ## friendlyID() 
 `[IDf,PrjID, Str] = friendlyID(ID)` \
-FriendlyID Changes the Hex Number to a human friendly datetime and dateStr. IDf returns the ID as DateTime Object, PrjID returns the ProjectID, Str returns the timestamp as String. \
+FriendlyID Changes the Hex Number to a human friendly *datetime* and *dateStr*. `IDf` returns the ID as DateTime Object, `PrjID` returns the ProjectID, `Str` returns the timestamp as String. \
 **This only works with ID method 1.**
 
 
@@ -94,8 +96,6 @@ fileCompare checks if file1 is (binary) identical to a file in filelist, it retu
 `[fListClean] = removePltIdFiles(fList)` \
 removePltIdFiles removes functions that are part of PlotID out of flist.
 
-
-
 # How to use the .config file
 The config file is a JSON-File. At the moment two options can be set in the config file, the project ID and the remote Path.
 
diff --git a/example-config.json b/example-config.json
index c0bd971..9df3f40 100644
--- a/example-config.json
+++ b/example-config.json
@@ -1,4 +1,5 @@
-{
+{   
+    "Author": "Example Author"
     "ProjectID": "AB01", 
     "ServerPath": "\\\\Server\\path\\folder"
 }
\ No newline at end of file
diff --git a/example.m b/example.m
index 492711c..04aa8c1 100644
--- a/example.m
+++ b/example.m
@@ -43,7 +43,7 @@ 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
+p = betacdf(0.5,1,1); % to test toolboxes
 
 %% Plotting
 % This is still part of a normal script to produce plots.
-- 
GitLab