-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bepv01 #98
base: main
Are you sure you want to change the base?
Bepv01 #98
Changes from all commits
bfa7a0f
91e7556
680a6ba
27ca1ac
224e540
99a2188
f142ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
from pathlib import Path | ||
import yaml | ||
import helper | ||
|
||
|
||
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 | ||
self.value_directory = None | ||
self.required_directory = None | ||
self.optional_directory = None | ||
self.recommended_directory = None | ||
self.top_level_directory = None | ||
self.sub_directory = None | ||
self.get_detail() | ||
|
||
def load_all_directories(self, relative_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 exists | ||
if absolute_path.exists(): | ||
with open(absolute_path, 'r') as file: | ||
directory_rules = yaml.safe_load(file) | ||
|
||
if directory_rules: | ||
self.all_directory = list(set(helper.find_keys_in_dict(directory_rules, 'level'))) | ||
else: | ||
print("Le fichier de règles des répertoires est vide.") | ||
else: | ||
print("Le fichier YAML spécifié n'existe pas :", absolute_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 | ||
|
||
# Getters for attributes | ||
|
||
def get_all_directory(self): | ||
""" | ||
Get all directories. | ||
|
||
Returns: | ||
list: A list of all directories. | ||
""" | ||
return self.all_directory | ||
|
||
def get_entity_directory(self): | ||
""" | ||
Get entity directories. | ||
|
||
Returns: | ||
list: A list of entity directories. | ||
""" | ||
return self.entity_directory | ||
|
||
def get_value_directory(self): | ||
""" | ||
Get value directories. | ||
|
||
Returns: | ||
list: A list of value directories. | ||
""" | ||
return self.value_directory | ||
|
||
def get_required_directory(self): | ||
""" | ||
Get required directories. | ||
|
||
Returns: | ||
list: A list of required directories. | ||
""" | ||
return self.required_directory | ||
|
||
def get_optional_directory(self): | ||
""" | ||
Get optional directories. | ||
|
||
Returns: | ||
list: A list of optional directories. | ||
""" | ||
return self.optional_directory | ||
|
||
def get_recommended_directory(self): | ||
""" | ||
Get recommended directories. | ||
|
||
Returns: | ||
list: A list of recommended directories. | ||
""" | ||
return self.recommended_directory | ||
|
||
def get_top_level_directory(self): | ||
""" | ||
Get top-level directories. | ||
|
||
Returns: | ||
list: A list of top-level directories. | ||
""" | ||
return self.top_level_directory | ||
|
||
|
||
if __name__ == "__main__": | ||
relative_path = "ressources/schema/rules/directories.yaml" | ||
|
||
common_structure = DirectoryStructure() | ||
common_structure.get_detail() | ||
|
||
print("All:", common_structure.get_all_directory()) | ||
print("Entity:", common_structure.get_entity_directory()) | ||
print("par Valeur :", common_structure.get_value_directory()) | ||
print("REQUIRED :", common_structure.get_required_directory()) | ||
print("optional :", common_structure.get_optional_directory()) | ||
print("top level:", common_structure.get_top_level_directory()) | ||
print("recomende:", common_structure.get_recommended_directory()) |
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.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import yaml | ||
|
||
|
||
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" # 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}") | ||
else: | ||
print(f"L'entité '{entity_name}' n'existe pas.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pense a mettre tout les prints en Anglais, c'est important !