Skip to content
Snippets Groups Projects
Commit 61fe55b8 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

ConductCalibProvider. Comments and style.

parent 3d64fd68
No related branches found
No related tags found
No related merge requests found
...@@ -115,21 +115,21 @@ class CalibRun: ...@@ -115,21 +115,21 @@ class CalibRun:
periodic_file = self.__find_single_file_in_file_list__( periodic_file = self.__find_single_file_in_file_list__(
files_list=files, files_list=files,
file_pattern=r"[0-9]{8}_[0-9]{6}_conduct-calib_(EDAQ|CONDUCTI)_periodic.log", file_pattern=r"[0-9]{8}_[0-9]{6}_conduct-calib_(EDAQ|CONDUCTI)_periodic.log",
file_identifyer="Periodic") file_identifier="Periodic")
self.periodic_df = self.get_periodic_file_content(directory + periodic_file) self.periodic_df = self.get_periodic_file_content(directory + periodic_file)
# Instant configuration changes # Instant configuration changes
instant_config_file = self.__find_single_file_in_file_list__( instant_config_file = self.__find_single_file_in_file_list__(
files_list=files, files_list=files,
file_pattern=r"[0-9]{8}_[0-9]{6}_conduct-calib_(EDAQ|CONDUCTI)_instant.log", file_pattern=r"[0-9]{8}_[0-9]{6}_conduct-calib_(EDAQ|CONDUCTI)_instant.log",
file_identifyer="Instant config") file_identifier="Instant config")
self.instant_config_df = self.get_instant_config_file_content(directory + instant_config_file) self.instant_config_df = self.get_instant_config_file_content(directory + instant_config_file)
# User-defined) configuration changes # User-defined) configuration changes
user_config_file = self.__find_single_file_in_file_list__( user_config_file = self.__find_single_file_in_file_list__(
files_list=files, files_list=files,
file_pattern=r"conduct_calib.csv", file_pattern=r"conduct_calib.csv",
file_identifyer="User config") file_identifier="User config")
self.user_config_df = self.get_user_config_file_content(directory + user_config_file) self.user_config_df = self.get_user_config_file_content(directory + user_config_file)
# Compare expected and real configuration changes. # Compare expected and real configuration changes.
...@@ -141,30 +141,71 @@ class CalibRun: ...@@ -141,30 +141,71 @@ class CalibRun:
standard_cond_file = self.__find_single_file_in_file_list__( standard_cond_file = self.__find_single_file_in_file_list__(
files_list=files, files_list=files,
file_pattern=r"standard_conductivity.txt", file_pattern=r"standard_conductivity.txt",
file_identifyer="Standard conductivity") file_identifier="Standard conductivity")
with open(directory + standard_cond_file, "r") as file: with open(directory + standard_cond_file, "r") as file:
self.standard_cond = float(file.readline()) self.standard_cond = float(file.readline())
def __check_real_config__(self, real_config_df: pd.DataFrame, user_config_df: pd.DataFrame) -> bool: @staticmethod
def __check_real_config__(real_config_df: pd.DataFrame, user_config_df: pd.DataFrame) -> bool:
"""Check that the real and user-defined configuration are the same.
Parameters
----------
real_config_df: pd.Dataframe
Dataframe containing the really-applied configuration changes, i.e. the orders which have been send to the
instrument.
user_config_df: pd.Dataframe
Dataframe containing the user-defined configuration, as defined in the conduct_calib.csv file
Returns
-------
bool
True if the real config matches the user-defined one, False if there are discrepancies.
"""
"""Compare the user-defined configuration file with the instant recording of the configuration changes. """Compare the user-defined configuration file with the instant recording of the configuration changes.
Note: Currently only check steps number""" Note: Currently only check steps number"""
return real_config_df["step"].max() == user_config_df["step"].max() return real_config_df["step"].max() == user_config_df["step"].max()
def __find_single_file_in_file_list__(self, files_list: list, file_pattern: str, file_identifyer: str) -> str: @staticmethod
def __find_single_file_in_file_list__(files_list: list, file_pattern: str, file_identifier: str) -> str:
"""Get the file name matching the ``file_pattern``, from the files list.
Parameters
----------
files_list: list
List of file names.
file_pattern: str
Regex used to find the desired single file.
file_identifier: str
Human-readable string used to identify the file type which is searched. This string is used to inform the
user when there is an error.
Returns
-------
str:
File name matching the ``file_pattern``
Raises
-------
ValueError
If no file or more than one file is found.
"""
found_files = [f for f in files_list if re.search(file_pattern, f)] found_files = [f for f in files_list if re.search(file_pattern, f)]
if len(found_files) > 1: if len(found_files) > 1:
raise ValueError("More than one file of type [" + file_identifyer + "] found.") raise ValueError("More than one file of type [" + file_identifier + "] found.")
elif len(found_files) == 0: elif len(found_files) == 0:
raise ValueError("No file found for type [" + file_identifyer + "]") raise ValueError("No file found for type [" + file_identifier + "]")
return found_files[0] return found_files[0]
def get_periodic_file_content(self, filename: str) -> pd.DataFrame: @staticmethod
def get_periodic_file_content(filename: str) -> pd.DataFrame:
periodic_df = pd.read_csv(filename, sep="\t", parse_dates=["datetime"]) periodic_df = pd.read_csv(filename, sep="\t", parse_dates=["datetime"])
return periodic_df return periodic_df
def get_instant_config_file_content(self, filename: str) -> pd.DataFrame: @staticmethod
def get_instant_config_file_content(filename: str) -> pd.DataFrame:
config_df = pd.read_csv(filename, sep=",", parse_dates=["datetime"]) config_df = pd.read_csv(filename, sep=",", parse_dates=["datetime"])
# Identify steps. # Identify steps.
...@@ -177,6 +218,7 @@ class CalibRun: ...@@ -177,6 +218,7 @@ class CalibRun:
return config_df return config_df
def get_user_config_file_content(self, filename: str) -> pd.DataFrame: @staticmethod
def get_user_config_file_content(filename: str) -> pd.DataFrame:
config_df = pd.read_csv(filename, sep=",") config_df = pd.read_csv(filename, sep=",")
return config_df return config_df
\ No newline at end of file
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