Skip to content
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

EVA-3437: remove duplicate while counting deprecated rs from db #424

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_deprecated_counts_for_assembly(mongo_source, assembly_accession):
filter_criteria = {"inactiveObjects.asm": assembly_accession, "eventType": "DEPRECATED"}
if prev_release_end_for_assembly:
filter_criteria["createdDate"] = {"$gt": prev_release_end_for_assembly}
return query_mongo(mongo_source, filter_criteria, "new_deprecated_rs")
return query_mongo_distinct(mongo_source, filter_criteria, "new_deprecated_rs", "accession")


def query_mongo(mongo_source, filter_criteria, metric):
Expand All @@ -304,6 +304,16 @@ def query_mongo(mongo_source, filter_criteria, metric):
return total_count


def query_mongo_distinct(mongo_source, filter_criteria, metric, distinct_field):
distinct_documents = set()
for collection_name in collections[metric]:
logger.info(f'Querying mongo: db.{collection_name}.distinct({distinct_field}, {filter_criteria})')
collection = mongo_source.mongo_handle[mongo_source.db_name][collection_name]
documents = collection.distinct(distinct_field, filter_criteria)
distinct_documents.update(documents)
return len(distinct_documents)


def insert_counts_in_db(private_config_xml_file, metrics_for_assembly, ranges_per_assembly, release_version):
with get_metadata_connection_handle("production_processing", private_config_xml_file) as metadata_connection_handle:
fill_data_for_current_release(metadata_connection_handle, metrics_for_assembly, ranges_per_assembly,
Expand Down
Loading