diff --git a/src/Class_Mod/Hash.py b/src/Class_Mod/Hash.py new file mode 100644 index 0000000000000000000000000000000000000000..8a96cbd6009e356e4b3011f35778de27d3e58a9c --- /dev/null +++ b/src/Class_Mod/Hash.py @@ -0,0 +1,26 @@ +from Packages import * + +def create_hash(spectra): + #using the md5 hash function. + hash_func = hashlib.md5() + spectra = str(spectra) + encoded_spectra = spectra.encode() + hash_func.update(encoded_spectra) + hash = hash_func.hexdigest() + return hash + +def check_hash(hash): + # path to hash file and grep/cat functions for Win + subprocess_path = Path("src/data/hash/") + # run a grep from the hash onto the hash file + nb_hash = subprocess.run([subprocess_path / 'grep.exe', '-c', hash, subprocess_path / "hash.txt"], shell=True) + # if hash present + if 'returncode=0' in str(nb_hash): + return 'existing hash' + # if hash not present, add it to the file with cat function + else: + add_hash = subprocess.run(['echo', str(hash) + '>>', subprocess_path / "hash.txt"], shell=True) + if 'returncode=0' in str(add_hash): + return 'hash added' + else: + return 'error while adding the new hash' \ No newline at end of file diff --git a/src/Modules.py b/src/Modules.py index 8699e5616f258a6b0fad449942a497c1edf9aa87..ba9e78454bea329013c893e864d5b1042b72ef1a 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -3,6 +3,7 @@ from Class_Mod import Plsr, LinearPCA, Umap, find_col_index, PinardPlsr, Nmf, AP from Class_Mod import LWPLSR, list_files, metrics, TpeIpls, reg_plot, resid_plot, Sk_Kmeans, DxRead, Hdbscan, read_dx, PlsProcess from Class_Mod.DATA_HANDLING import * from Class_Mod.Miscellaneous import prediction, download_results, plot_spectra, local_css +from Class_Mod.Hash import create_hash, check_hash from Report import report css_file = Path("style/") pages_folder = Path("pages/") diff --git a/src/data/hash/hash.txt b/src/data/hash/hash.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391