Skip to content

Commit

Permalink
"Documentation and refactoring class name "
Browse files Browse the repository at this point in the history
  • Loading branch information
sifaoufatai committed Apr 5, 2024
1 parent 99a2188 commit f142ff7
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 117 deletions.
54 changes: 54 additions & 0 deletions bep32v01/BidsDatatype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import yaml


def _load_data_types(yaml_path="ressources/schema/objects/datatypes.yaml"):
"""
Load data types from a YAML file.
Args:
yaml_path (str): The path to the YAML file containing data type data.
Returns:
dict: A dictionary containing data type data.
"""
with open(yaml_path, 'r') as file:
data_types_data = yaml.safe_load(file)
return data_types_data


class DataTypes:
def __init__(self):
"""
Initialize a DataTypes object and load data types from a YAML file.
"""
self.data_types = _load_data_types()

def get_data_type_value(self, data_type_name):
"""
Get the value of a specific data type.
Args:
data_type_name (str): The name of the data type to retrieve.
Returns:
str: The value of the data type, or None if the data type does not exist.
"""
return self.data_types.get(data_type_name, {}).get("value")


def main():
"""
Main function to demonstrate the usage of the DataTypes class.
"""
data_types = DataTypes()
data_type_name = "anat"
data_type = data_types.get_data_type_value(data_type_name)
if data_type:
print(f"Données de type '{data_type_name}':")
print(data_type)
else:
print(f"Le type de données '{data_type_name}' n'existe pas.")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

class DirectoryStructure:
def __init__(self):
"""
Initialize a DirectoryStructure object with default parameters.
"""
self.relative_path = "ressources/schema/rules/directories.yaml"
self.entity_directory = []
self.all_directory = None
Expand All @@ -17,10 +20,19 @@ def __init__(self):
self.get_detail()

def load_all_directories(self, relative_path):
# retrieve absolute path
"""
Load all directories from a YAML file.
Args:
relative_path (str): The relative path to the YAML file.
Returns:
list: A list of all directories.
"""
# Retrieve absolute path
absolute_path = Path(relative_path).resolve()

# check if the file exist
# Check if the file exists
if absolute_path.exists():
with open(absolute_path, 'r') as file:
directory_rules = yaml.safe_load(file)
Expand All @@ -34,40 +46,86 @@ def load_all_directories(self, relative_path):
return self.all_directory

def load_all_directoires_all_details(self, relative_path):
"""
Load all directory details from a YAML file.
Args:
relative_path (str): The relative path to the YAML file.
"""
self.entity_directory, self.value_directory, self.required_directory, self.optional_directory, self.recommended_directory, self.top_level_directory = helper.get_directories_with_details(
relative_path)

def get_detail(self):
"""
Get details of all directories.
"""
self.load_all_directories(self.relative_path)
self.load_all_directoires_all_details(self.relative_path)
return self

# Getter pour all_directory
# Getters for attributes

def get_all_directory(self):
"""
Get all directories.
Returns:
list: A list of all directories.
"""
return self.all_directory

# Getter pour entity_directory
def get_entity_directory(self):
"""
Get entity directories.
Returns:
list: A list of entity directories.
"""
return self.entity_directory

# Getter pour value_directory
def get_value_directory(self):
"""
Get value directories.
Returns:
list: A list of value directories.
"""
return self.value_directory

# Getter pour required_directory
def get_required_directory(self):
"""
Get required directories.
Returns:
list: A list of required directories.
"""
return self.required_directory

# Getter pour optional_directory
def get_optional_directory(self):
"""
Get optional directories.
Returns:
list: A list of optional directories.
"""
return self.optional_directory

# Getter pour recommended_directory
def get_recommended_directory(self):
"""
Get recommended directories.
Returns:
list: A list of recommended directories.
"""
return self.recommended_directory

# Getter pour top_level_directory
def get_top_level_directory(self):
"""
Get top-level directories.
Returns:
list: A list of top-level directories.
"""
return self.top_level_directory


Expand Down
42 changes: 42 additions & 0 deletions bep32v01/BidsEmptyRepositoryGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
from Createfile import CreatFile
from Createdirectory import Createdirectory


class Generator:
def __init__(self, output, sub_id=1, session_id=1, modality=None):
"""
Initialize a Generator object.
Args:
output (str): The output folder path.
sub_id (int): Subject ID.
session_id (int): Session ID.
modality (str, optional): The modality name.
"""
self.output = output
self.modality = modality.strip() if modality else None
if self.modality:
self.directory_builder = Createdirectory(output, sub_id, session_id, self.modality)
self.file_builder = CreatFile(output)
self.generate()
else:
print("No modality provided. Please specify a modality.")

def generate(self):
"""Generate files and directories."""
self.directory_builder.build()
self.file_builder.build()


if __name__ == "__main__":
output = input("Enter the output folder path: ").strip()
if output:
sub_id = input("Enter the subject ID (default is 1): ").strip()
session_id = input("Enter the session ID (default is 1): ").strip()
modality = input("Enter the modality (optional): ").strip()
sub_id = int(sub_id) if sub_id.isdigit() else 1
session_id = int(session_id) if session_id.isdigit() else 1
generator = Generator(output, sub_id, session_id, modality)
else:
print("Output folder path is required.")
26 changes: 25 additions & 1 deletion bep32v01/Entity.py → bep32v01/BidsEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,47 @@

class Entity:
def __init__(self):
"""
Initialize an Entity object and load entities from a YAML file.
"""
self.entities = self._load_entities()

def _load_entities(self, yaml_path="ressources/schema/objects/entities.yaml"):
"""
Load entities from a YAML file.
Args:
yaml_path (str): The path to the YAML file containing entity data.
Returns:
dict: A dictionary containing entity data.
"""
with open(yaml_path, 'r') as file:
entities_data = yaml.safe_load(file)
return entities_data

def get_entity_name(self, entity_name):
"""
Get the name of a specific entity.
Args:
entity_name (str): The name of the entity to retrieve.
Returns:
str: The name of the entity, or None if the entity does not exist.
"""
if entity_name in self.entities:
return self.entities[entity_name].get("name")
else:
return None


def main():
"""
Main function to demonstrate the usage of the Entity class.
"""
entities = Entity()
entity_name = "acquisition" # Exemple de nom d'entité
entity_name = "acquisition" # Example entity name
entity_name_output = entities.get_entity_name(entity_name)
if entity_name_output:
print(f"Nom de l'entité '{entity_name}': {entity_name_output}")
Expand Down
Loading

0 comments on commit f142ff7

Please sign in to comment.