Skip to content
Snippets Groups Projects
Commit ec96eafc authored by Nicolas Barthes's avatar Nicolas Barthes
Browse files

Class to manage spectra md5 hash

parent 27cb217a
No related branches found
No related tags found
No related merge requests found
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
...@@ -3,6 +3,7 @@ from Class_Mod import Plsr, LinearPCA, Umap, find_col_index, PinardPlsr, Nmf, AP ...@@ -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 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.DATA_HANDLING import *
from Class_Mod.Miscellaneous import prediction, download_results, plot_spectra, local_css 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 from Report import report
css_file = Path("style/") css_file = Path("style/")
pages_folder = Path("pages/") pages_folder = Path("pages/")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment