eldam.utils package¶
Submodules¶
eldam.utils.exceptions module¶
Custom exceptions
eldam.utils.elda module¶
Functions used for elda management
-
add_major_version_from_text
(version_text)[source]¶ Returns the next major version from a text formatted version number
Example
>>> add_major_version_from_text('V1.3') 'V2.0'
- Parameters
version_text (str) – Text formatted version number like ‘V2.3’
- Returns
Text formatted version number
- Return type
str
-
add_minor_version_from_text
(version_text)[source]¶ Returns the next minor version from a text formatted version number
Example
>>> add_minor_version_from_text('V1.3') 'V1.4'
- Parameters
version_text (str) – Text formatted version number like ‘V2.3’
- Returns
Text formatted version number
- Return type
str
eldam.utils.gui module¶
Functions used in ELDAM GUI
-
get_last_changelog
()[source]¶ Gets ELDAM’s last changelog.
- Returns
Last ELDAM changelog
- Return type
str
-
get_last_eldam_version_number
(offset=0)[source]¶ Gets last ELDAM version number from the gitlab repository tags
- Parameters
offset (int) – Offset of 1 will give the penultimate version number
- Returns
Last ELDAM version number
- Return type
str
-
name_from_pattern
(pattern, process='process', product='product')[source]¶ Creates a file name from a pattern
Pattern replaceable items are PROCESS and DATE
- Parameters
pattern (str) – Pattern to use
process (str) – Process name for replacing PROCESS in the pattern
product (str) – Product name for replacing PRODUCT in the pattern
- Returns
filename
- Return type
str
Examples
>>> name_from_pattern('PROCESS_date', process='process_name') 'process_name_date' >>> name_from_pattern('PROCESS_foo', process='process/name/with/slash') 'process_name_with_slash_foo' >>> name_from_pattern('PRODUCT_bar', product='Prod') 'Prod_bar'
-
remove_path_from_error_message
(message)[source]¶ The error message displayed when ELDAM crashes contains path to the Python files on the computer on which ELDAM as been compilated. This function simply hides the first part of the path.
- Parameters
message (str) – Error message
- Returns
Error message with first part of paths hidden
- Return type
str
Examples
>>> remove_path_from_error_message('''Traceback (most recent call last): File "C:/Users/user/AppData/Local/Programs/Python/Python37/lib/tkinter/__init__.py", line 1702, in __call__ return self.func(*args) File "C:/Path/to/ELDAM/eldam/gui_tk.py", line 453, in convert_elda_to_csv self.read_elda() File "C:/Path/to/ELDAM/eldam/gui_tk.py", line 665, in read_elda self.processes.append(elda.read_last_version().to_process()) File "C:/Path/to/ELDAM/eldam/core/elda.py", line 870, in to_process level=input_parameter_data['level'] or 'Process') File "C:/Path/to/ELDAM/eldam/core/lci_data.py", line 474, in __init__ self.value_or_formula = self.valueAttributeError: 'InputParameter' object has no attribute 'value' ''') 'Traceback (most recent call last): File "... \x02/lib/tkinter/__init__.py", line 1702, in __call__ return self.func(*args) File "... \x02/eldam/gui_tk.py", line 453, in convert_elda_to_csv self.read_elda() File "... \x02/eldam/gui_tk.py", line 665, in read_elda self.processes.append(elda.read_last_version().to_process()) File "... \x02/eldam/core/elda.py", line 870, in to_process level=input_parameter_data[\'level\'] or \'Process\') File "... \x02/eldam/core/lci_data.py", line 474, in __init__ self.value_or_formula = self.valueAttributeError: \'InputParameter\' object has no attribute \'value\' '
eldam.utils.lci_data module¶
eldam.utils.misc module¶
Miscellaneous functions used by ELDAM
-
compare_file
(file_1, file_2)[source]¶ Returns the differences between two files.
- Parameters
file_1 (str) – Path to file 1
file_2 (str) – Path to file 2
- Returns
Differences between the files
- Return type
str
-
find_data_file
(filename)[source]¶ Function used to find data files when compiling with cs_freeze
- Parameters
filename (str) – The name of the file from the program (.py or .exe)
- Returns
Path to the file
- Return type
str
-
is_number
(s)[source]¶ Checks if a string is a number or not.
- Parameters
s (str) – String to check
- Returns
Answer
- Return type
bool
Examples
>>> is_number('0') True >>> is_number('Input') False >>> is_number('0,5') False >>> is_number('0.3') True >>> is_number('5') True
-
n_float
(arg)[source]¶ A function returning a float or None if arg is None
Example
>>> n_float(None)
>>> n_float(6) 6.0
- Parameters
arg – Object
- Returns
float(arg) or None
- Return type
float or NoneType
-
n_int
(arg)[source]¶ A function returning a int or None if arg is None
Example
>>> n_int(None)
>>> n_int(6) 6
- Parameters
arg – Object
- Returns
int(arg) or None
- Return type
int or NoneType
-
n_str
(arg)[source]¶ A function that returns None if the input is None, else str(arg)
Example
>>> n_str(None)
>>> n_str(5) '5'
- Parameters
arg – Object
- Returns
str(arg) or None
- Return type
str or NoneType
-
remove_duplicates
(iterable)[source]¶ Returns a list without its duplicates preserving the order of the elements
Notes
Works on list of unhashable and unsortable objects
- Parameters
iterable (list) – List to remove duplicates from
- Returns
List without its duplicates
- Return type
list
Examples
>>> remove_duplicates([1, 2, 3, 4, 4]) [1, 2, 3, 4]
eldam.utils.simapro module¶
Functions used for SimaPro .xlsx files management
-
extract_data_from_comment
(comment)[source]¶ Extracts data from a comment.
For example, quality data like process modification code and comment
- Parameters
comment (str) – Text containing the data
- Returns
Dictionnary containing every parsed data
- Return type
dict
Examples
>>> extract_data_from_comment('Comment on test co-product\n\n!!! DO NOT EDIT BELOW THIS LINE !!!' ... '\n[[{"review_state": 2, "reviewer_comment":"a reviewer comment",' ... '"comment_for_reviewer": "a comment for reviewer"}]]') {'comment': 'Comment on test co-product', 'review_state': 2, 'reviewer_comment': 'a reviewer comment', 'comment_for_reviewer': 'a comment for reviewer'} >>> extract_data_from_comment('1BZ:\n1: Information on process modification\nB: Info on relevance' ... '\nZ: Info on confidence\n\nRest of the comment\n\n!!! DO NOT EDIT BELOW THIS LINE !!!\n' ... '[[{"library": "Own process", "review_state": 2, "reviewer_comment": "a reviewer comment",' ... '"comment_for_reviewer": "a comment for reviewer"}]]') {'modification_code': '1', 'relevance_code': 'B', 'confidence_code': 'Z', 'modification_comment': 'Information on process modification', 'relevance_comment': 'Info on relevance', 'confidence_comment': 'Info on confidence', 'comment': 'Rest of the comment', 'library': 'Own process', 'review_state': 2, 'reviewer_comment': 'a reviewer comment', 'comment_for_reviewer': 'a comment for reviewer'} >>> extract_data_from_comment('0AZ:\nA: info on relevance (the line about modification has been ' ... 'skipped because code 0)\nZ: info on confidence\n\nrest of the comment\non 2 lines' ... '\n\n!!! DO NOT EDIT BELOW THIS LINE !!!\n[[{"data_source": "Source of the data", ' ... '"library": "Own process", "review_state": 2,"reviewer_comment": "a reviewer comment", ' ... '"comment_for_reviewer": "a comment for reviewer"}]]') {'modification_code': '0', 'relevance_code': 'A', 'confidence_code': 'Z', 'relevance_comment': 'info on relevance (the line about modification has been skipped because code 0)', 'confidence_comment': 'info on confidence', 'comment': 'rest of the comment\non 2 lines', 'data_source': 'Source of the data', 'library': 'Own process', 'review_state': 2, 'reviewer_comment': 'a reviewer comment', 'comment_for_reviewer': 'a comment for reviewer'} >>> extract_data_from_comment('Comment without acv cirad data\n\n!!! DO NOT EDIT BELOW THIS LINE !!!\n' ... '[[{"review_state": 2, "reviewer_comment": "a reviewer comment", ' ... '"comment_for_reviewer": "a comment for reviewer"}]]') {'comment': 'Comment without acv cirad data', 'review_state': 2, 'reviewer_comment': 'a reviewer comment', 'comment_for_reviewer': 'a comment for reviewer'} >>> extract_data_from_comment('AY:\nA: info on relevance\nY: info on confidence') {'relevance_code': 'A', 'confidence_code': 'Y', 'relevance_comment': 'info on relevance', 'confidence_comment': 'info on confidence'} >>> extract_data_from_comment('Just a simple comment') {'comment': 'Just a simple comment'} >>> extract_data_from_comment('BY') {'relevance_code': 'B', 'confidence_code': 'Y'} >>> extract_data_from_comment('(3AZ)\n\nComments on quality data are missing') {'modification_code': '3', 'relevance_code': 'A', 'confidence_code': 'Z', 'comment': 'Comments on quality data are missing'}
eldam.utils.xls module¶
Module contents¶
Utility functions used in ELDAM