Skip to content

Commit

Permalink
Now added a validate folder command.
Browse files Browse the repository at this point in the history
  • Loading branch information
KFilippopolitis committed Jul 3, 2023
1 parent dac748a commit 0a5d80f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mipdb/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from mipdb.database import MonetDB
from mipdb.reader import JsonFileReader
from mipdb.usecases import AddDataModel, Cleanup, ValidateDatasetNoDatabase
from mipdb.usecases import AddDataModel, Cleanup, ValidateDatasetNoDatabase, ValidateDataModel
from mipdb.usecases import AddPropertyToDataModel
from mipdb.usecases import AddPropertyToDataset
from mipdb.usecases import DeleteDataModel
Expand Down Expand Up @@ -147,6 +147,27 @@ def load_folder(file, copy_from_file, ip, port, username, password, db_name):
print(f"CSV '{csv_path}' was successfully added.")


@entry.command()
@cl.argument("file", required=True)
@handle_errors
def validate_folder(file):
for subdir, dirs, files in os.walk(file):
if dirs:
continue
print(f"Data model '{subdir}' is being validated...")
metadata_path = os.path.join(subdir, "CDEsMetadata.json")
reader = JsonFileReader(metadata_path)
data_model_metadata = reader.read()
code = data_model_metadata["code"]
ValidateDataModel().execute(data_model_metadata)
print(f"Data model '{code}' was successfully validated.")

for csv_path in glob.glob(subdir + "/*.csv"):
print(f"CSV '{csv_path}' is being validated...")
ValidateDatasetNoDatabase().execute(csv_path, data_model_metadata)
print(f"CSV '{csv_path}' was successfully validated.")


@entry.command()
@db_configs_options
@handle_errors
Expand Down
8 changes: 8 additions & 0 deletions mipdb/usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ def _create_metadata_table(self, schema, conn, cdes):
metadata_table.insert_values(values, conn)


class ValidateDataModel(UseCase):
def execute(self, data_model_metadata) -> None:
cdes = make_cdes(copy.deepcopy(data_model_metadata))
validate_dataset_present_on_cdes_with_proper_format(cdes)
if LONGITUDINAL in data_model_metadata and data_model_metadata[LONGITUDINAL]:
validate_longitudinal_data_model(cdes)


class DeleteDataModel(UseCase):
def __init__(self, db: DataBase) -> None:
self.db = db
Expand Down

0 comments on commit 0a5d80f

Please sign in to comment.