Skip to content
Snippets Groups Projects

Restructure and introduce additional object to transfer figures and IDs from...

Merged Mayr, Hannes requested to merge 56-publish-should-create-a-subfolder-named-with-the-id into dev
13 files
+ 390
195
Compare changes
  • Side-by-side
  • Inline
Files
13
+ 11
6
@@ -3,7 +3,7 @@
Create an identifier to print it on a plot.
Functions:
create_id(str) -> string
create_id(str) -> str
"""
import time
import uuid
@@ -13,18 +13,23 @@ def create_id(id_method):
"""
Create an Identifier (str).
Creates an (sometimes unique) identifier based on the selected method
if no method is selected method 1 will be the default method
Creates an (sometimes unique) identifier based on the selected method.
Parameters
----------
id_method : str
id_method for creating the ID. Create an ID by Unix time is referenced
as 'time', create a random ID with id_method='random'.
Returns
-------
figure_id
figure_id : str
"""
match id_method:
case 'time':
figure_id = time.time() # UNIX Time
figure_id = hex(int(figure_id)) # convert time to hexadecimal
time.sleep(0.5) # break for avoiding duplicate IDs
figure_id = hex(int(figure_id)) # convert time to hexadecimal str
time.sleep(1) # break for avoiding duplicate IDs
case 'random':
figure_id = str(uuid.uuid4()) # creates a random UUID
figure_id = figure_id[0:8] # only use first 8 numbers
Loading