Skip to content

Commit

Permalink
Make functions cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-parker committed Aug 26, 2024
1 parent 86d4807 commit c150cc0
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions ena-submission/scripts/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,28 @@ class Config:
def construct_project_set_object(
group_info: dict[str, str],
config: Config,
metadata_dict: dict[str, str],
row: dict[str, str],
entry: dict[str, str],
test=False,
):
"""
Construct project set object, using:
- entry in project_table
- group_info of corresponding group_id
- config information, such as ingest metadata for that organism
If test=True add a timestamp to the alias suffix to allow for multiple
submissions of the same project for testing.
(ENA blocks multiple submissions with the same alias)
"""
metadata_dict = config.organisms[entry["organism"]]["ingest"]
if test:
alias = XmlAttribute(
f"{row["group_id"]}:{row["organism"]}:{config.unique_project_suffix}:{datetime.now(tz=pytz.utc)}"
f"{entry["group_id"]}:{entry["organism"]}:{config.unique_project_suffix}:{datetime.now(tz=pytz.utc)}"
) # TODO(https://github.com/loculus-project/loculus/issues/2425): remove in production
else:
alias = XmlAttribute(f"{row["group_id"]}:{row["organism"]}:{config.unique_project_suffix}")
alias = XmlAttribute(
f"{entry["group_id"]}:{entry["organism"]}:{config.unique_project_suffix}"
)

project_type = ProjectType(
center_name=XmlAttribute(group_info["institution"]),
Expand All @@ -89,7 +101,7 @@ def construct_project_set_object(
)
),
project_links=ProjectLinks(
project_link=ProjectLink(xref_link=XrefType(db=config.db_name, id=row["group_id"]))
project_link=ProjectLink(xref_link=XrefType(db=config.db_name, id=entry["group_id"]))
),
)
return ProjectSet(project=[project_type])
Expand Down Expand Up @@ -239,17 +251,17 @@ def project_table_create(db_config, config, retry_number=3):
for row in ready_to_submit_project:
group_key = {"group_id": row["group_id"], "organism": row["organism"]}

metadata_dict = config.organisms[row["organism"]]["ingest"]
try:
group_info = get_group_info(config, row["group_id"])[0]["group"]
except Exception as e:
logger.error(f"Was unable to get group info for group: {row["group_id"]}, {e}")
continue

project_set = construct_project_set_object(
group_info, config, metadata_dict, row, test=True
)
update_values = {"status": Status.SUBMITTING}
project_set = construct_project_set_object(group_info, config, row, test=True)
update_values = {
"status": Status.SUBMITTING,
"started_at": datetime.now(tz=pytz.utc),
}
number_rows_updated = update_db_where_conditions(
db_config,
table_name="project_table",
Expand Down Expand Up @@ -294,6 +306,7 @@ def project_table_create(db_config, config, retry_number=3):
update_values = {
"status": Status.HAS_ERRORS,
"errors": json.dumps(project_creation_results.errors),
"started_at": datetime.now(tz=pytz.utc),
}
number_rows_updated = 0
tries = 0
Expand Down

0 comments on commit c150cc0

Please sign in to comment.