Commit 345f15fc authored by Hueser, Christian (FWCC) - 138593's avatar Hueser, Christian (FWCC) - 138593
Browse files

Add setter that creates output folder path and sub-folder itself

* Add a public setter method that sets an analysis output folder path
and creates the respective sub-folder itself once per analysis run.
* The output folder path property may then be reused after that
in all locations where output is generated.
* This setter method is called once in the constructor of class
Settings.
parent 7abf0dae
Pipeline #68999 passed with stages
in 4 minutes and 18 seconds
......@@ -45,10 +45,8 @@ def run():
print(time_coding_percentage_frame.std())
print('##########')
# create path
output_path: Path = settings.output_folder / settings.run_timestamp
if not output_path.exists():
output_path.mkdir(parents=True)
# get output path
output_path: Path = settings.analysis_output_path
# coding time all
plot = (p9.ggplot(data=time_coding_percentage_frame,
......
......@@ -198,7 +198,7 @@ def remove_entries(word_count: dict,
return word_count
def analyze(relevant_questions: list, name: str, filter: dict, path: str):
def analyze(relevant_questions: list, name: str, filter: dict, path: Path):
print(f'##### {name} #####')
answer_data_frame = question_ids_to_dataframe(relevant_questions)
......@@ -283,10 +283,8 @@ def run():
'max_coding_experience': 9.999,
'sort_out_empty': True}
# create path
output_path: Path = settings.output_folder / settings.run_timestamp
if not output_path.exists():
output_path.mkdir(parents=True)
# get output path
output_path: Path = settings.analysis_output_path
analyze(relevant_questions=relevant_questions,
name='all',
......
......@@ -46,10 +46,8 @@ def run():
with open("metadata/HIFIS_Software_Survey_2020_Questions.yml") as meta_yml:
meta = yaml.load(meta_yml, Loader=yaml.FullLoader)
# create output path
output_path: Path = settings.output_folder / settings.run_timestamp
if not output_path.exists():
output_path.mkdir(parents=True)
# get output path
output_path: Path = settings.analysis_output_path
# handle numerical questions
results_table = []
......
......@@ -63,11 +63,8 @@ def _output_pyplot_image(output_file_stem: str = "") -> None:
file_ending: str = settings.output_format.name.lower()
file_name: str = f"{output_file_stem}.{file_ending}"
output_subfolder: Path = settings.output_folder / settings.run_timestamp
output_path: Path = output_subfolder / file_name
if not output_subfolder.exists():
output_subfolder.mkdir(parents=True)
output_path: Path = settings.analysis_output_path / file_name
if output_path.exists():
logging.warning(f"Overriding existing output file {output_path}")
......
......@@ -57,6 +57,13 @@ class Settings(object):
# (e.g. for saving output images)
self.run_timestamp: str = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
# Path to sub-folder which holds all output files of a single
# analysis run
self.__analysis_output_path: Path = None
# Set path to sub-folder and create sub-folder in one go
self.analysis_output_path = self.output_folder / self.run_timestamp
# Using a set for true_values and false_values to avoid duplicates and
# because order does not matter
self.true_values: Set[str] = {
......@@ -84,3 +91,42 @@ class Settings(object):
additional_lower: Set[str] = set(map(str.lower, self.false_values))
additional_upper: Set[str] = set(map(str.upper, self.false_values))
self.false_values.update(additional_lower.union(additional_upper))
@property
def analysis_output_path(self) -> Path:
"""
Getter method of property.
Returns:
analysis_output_path (Path): Path to sub-folder which holds all
output files of a single analysis run.
"""
return self.__analysis_output_path
@analysis_output_path.setter
def analysis_output_path(self, analysis_output_path: Path) -> None:
"""
Setter method of property that sets value only once and creates folder.
This setter method not only sets the path of the analysis output folder
once per analysis run but also takes care of the creation of the
sub-folder as well.
Args:
analysis_output_path (Path): Path to sub-folder which holds all
output files of a single analysis run.
"""
if self.__analysis_output_path is None:
self.__analysis_output_path = analysis_output_path
self.__create_analysis_output_folder()
def __create_analysis_output_folder(self) -> None:
"""
Create a unique sub-folder to hold all output files of an analysis run.
The sub-folder for the output of the analysis run is only created
if path property is set and only created once per analysis run.
"""
if self.analysis_output_path is not None:
if not self.analysis_output_path.exists():
self.analysis_output_path.mkdir(parents=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment