Skip to content

Commit

Permalink
Feature/discard gsms (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcones committed Oct 31, 2023
1 parent bd59406 commit 093e59c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions kilombo/model/study_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging

from kilombo.model.failed_study import FailedStudy
from kilombo.model.failed_study_reason import FailedStudyReason


class StudyHierarchy:
Expand All @@ -15,6 +18,9 @@ def __init__(self, pending=None):
def add_pending_study(self, study_id):
self.pending[study_id] = {}

def remove_study(self, study_id):
del self.pending[study_id]

def move_study_to_failed(self, failed_study: FailedStudy):
self.failed[failed_study.study_id] = self.pending[failed_study.study_id]
self.failed[failed_study.study_id] = failed_study.reason
Expand All @@ -36,12 +42,24 @@ def add_srrs(self, study_id, srrs: []):
self.successful[study_id]["srrs"] = srrs

def reconcile(self):
successful_study_ids_to_remove = [study_id[0] for study_id in self.successful.items() if study_id[0] in self.pending.keys()]
failed_study_ids_to_remove = [study_id[0] for study_id in self.failed.items() if study_id[0] in self.pending.keys()]
successful_study_ids_to_remove_from_pending = [study_id[0] for study_id in self.successful.items() if study_id[0] in self.pending.keys()]
failed_study_ids_to_remove_from_pending = [study_id[0] for study_id in self.failed.items() if study_id[0] in self.pending.keys()]

study_ids = successful_study_ids_to_remove + failed_study_ids_to_remove
study_ids = successful_study_ids_to_remove_from_pending + failed_study_ids_to_remove_from_pending

for study_id in study_ids:
self.pending.pop(study_id)

if len(self.pending) == 0:
del self.pending

self._clean_gsms()

def _clean_gsms(self):
gsms_to_remove = [study_id for study_id in self.failed.keys() if self.failed[study_id] == FailedStudyReason.GSM_FOUND]
if gsms_to_remove:
logging.debug(f"GSMs to remove: {gsms_to_remove}")
for study_id in gsms_to_remove:
self.failed.pop(study_id)
self.count_failed -= 1
self.count_total -= 1

0 comments on commit 093e59c

Please sign in to comment.