Skip to content

Commit ca631d9

Browse files
committed
Refactor counter usage for score set search filters.
1 parent 7f613b5 commit ca631d9

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/mavedb/lib/score_sets.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ def search_score_sets(db: Session, owner_or_contributor: Optional[User], search:
293293
return {"score_sets": score_sets, "num_score_sets": num_score_sets}
294294

295295

296+
def score_set_search_filter_options_from_counter(counter: Counter):
297+
return [{"value": value, "count": count} for value, count in counter.items()]
298+
299+
296300
def fetch_score_set_search_filter_options(db: Session, owner_or_contributor: Optional[User], search: ScoreSetsSearch):
297301
save_to_logging_context({"score_set_search_criteria": search.model_dump()})
298302

@@ -330,11 +334,6 @@ def fetch_score_set_search_filter_options(db: Session, owner_or_contributor: Opt
330334
if accession:
331335
target_accession_counter[accession] += 1
332336

333-
target_gene_categories = [{"value": value, "count": count} for value, count in target_category_counter.items()]
334-
target_gene_names = [{"value": value, "count": count} for value, count in target_name_counter.items()]
335-
target_organism_names = [{"value": value, "count": count} for value, count in target_organism_name_counter.items()]
336-
target_accessions = [{"value": value, "count": count} for value, count in target_accession_counter.items()]
337-
338337
publication_author_name_counter: Counter[str] = Counter()
339338
publication_db_name_counter: Counter[str] = Counter()
340339
publication_journal_counter: Counter[str] = Counter()
@@ -356,22 +355,16 @@ def fetch_score_set_search_filter_options(db: Session, owner_or_contributor: Opt
356355
if journal:
357356
publication_journal_counter[journal] += 1
358357

359-
publication_author_names = [
360-
{"value": value, "count": count} for value, count in publication_author_name_counter.items()
361-
]
362-
publication_db_names = [{"value": value, "count": count} for value, count in publication_db_name_counter.items()]
363-
publication_journals = [{"value": value, "count": count} for value, count in publication_journal_counter.items()]
364-
365358
logger.debug(msg="Score set search filter options were fetched.", extra=logging_context())
366359

367360
return {
368-
"target_gene_categories": target_gene_categories,
369-
"target_gene_names": target_gene_names,
370-
"target_organism_names": target_organism_names,
371-
"target_accessions": target_accessions,
372-
"publication_author_names": publication_author_names,
373-
"publication_db_names": publication_db_names,
374-
"publication_journals": publication_journals,
361+
"target_gene_categories": score_set_search_filter_options_from_counter(target_category_counter),
362+
"target_gene_names": score_set_search_filter_options_from_counter(target_name_counter),
363+
"target_organism_names": score_set_search_filter_options_from_counter(target_organism_name_counter),
364+
"target_accessions": score_set_search_filter_options_from_counter(target_accession_counter),
365+
"publication_author_names": score_set_search_filter_options_from_counter(publication_author_name_counter),
366+
"publication_db_names": score_set_search_filter_options_from_counter(publication_db_name_counter),
367+
"publication_journals": score_set_search_filter_options_from_counter(publication_journal_counter),
375368
}
376369

377370

0 commit comments

Comments
 (0)