Skip to content

Commit

Permalink
Litin
Browse files Browse the repository at this point in the history
  • Loading branch information
luissian committed Jul 27, 2023
1 parent bbd1c1e commit b20d086
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
4 changes: 3 additions & 1 deletion core/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@
"Check documentation to define the Laboratory",
]
ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_EMPTY_VALUE = ["Batch file contains empty values"]
ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT = ["Batch file does not have the correct format"]
ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT = [
"Batch file does not have the correct format"
]
ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_NO_DEFINED_TYPE_OF_SAMPLES = [
"No Type of Samples are defined yet",
"Check documentation to define them",
Expand Down
44 changes: 28 additions & 16 deletions core/utils/load_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@


def get_sample_projects_names(sample_df):
"""
"""
""" """
sample_df["Project/Service"] = sample_df["Project/Service"].fillna("")
return sample_df["Project/Service"].unique().tolist()

Expand Down Expand Up @@ -374,44 +373,55 @@ def create_molecule_parameter_from_file(molecule_obj, sample_data):


def get_sample_project_fields(project_names):
"""
"""
""" """
p_fields = []
for p_name in project_names:
if p_name == "" or p_name.lower() == "none":
continue
if core.models.SampleProjects.objects.filter(sample_project_name__iexact=p_name).exists():
s_proj_obj = core.models.SampleProjects.objects.filter(sample_project_name__iexact=p_name).last()
s_pro_field_objs = core.models.SampleProjectsFields.objects.filter(sample_projects_id=s_proj_obj)
if core.models.SampleProjects.objects.filter(
sample_project_name__iexact=p_name
).exists():
s_proj_obj = core.models.SampleProjects.objects.filter(
sample_project_name__iexact=p_name
).last()
s_pro_field_objs = core.models.SampleProjectsFields.objects.filter(
sample_projects_id=s_proj_obj
)
for s_pro_field_obj in s_pro_field_objs:
p_fields.append(s_pro_field_obj.get_field_name())
else:
return {"ERROR":core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_SAMPLE_PROJECT_NO_DEFINED}
return {
"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_SAMPLE_PROJECT_NO_DEFINED
}
return p_fields


def heading_validation(sample_batch_df):
"""
"""
""" """
batch_head = list(sample_batch_df.head(0))
for item in core.core_config.HEADING_FOR_RECORD_SAMPLES:
if item not in batch_head:
return {"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT}
return {
"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT
}
project_names = get_sample_projects_names(sample_batch_df)
project_len = len(project_names)
if "" in project_names or "None" in project_names:
project_len -= 1
if project_len > 1 :
return {"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_TOO_MANY_PROJECTS}
if project_len > 1:
return {
"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_TOO_MANY_PROJECTS
}
s_project_fields = get_sample_project_fields(project_names)
if "ERROR" in s_project_fields:
return s_project_fields
for field in s_project_fields:
if field not in batch_head:
return {"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT}
return {
"ERROR": core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_INVALID_FORMAT
}
return "OK"



def read_batch_sample_file(batch_file):
"""
Expand Down Expand Up @@ -452,7 +462,9 @@ def valid_sample_batch_file(sample_batch_df, package):
return validate_heading
# if sample_batch_df.isnull().values.any():
# return core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_EMPTY_VALUE
import pdb; pdb.set_trace()
import pdb

pdb.set_trace()
if not check_samples_belongs_to_same_type_and_molecule_protocol(sample_batch_df):
return (
core.core_config.ERROR_MESSAGE_FOR_SAMPLE_BATCH_FILE_NOT_SAME_SAMPLE_PROTOCOL
Expand Down

0 comments on commit b20d086

Please sign in to comment.