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

Feature/discard gsms #9

Merged
merged 4 commits into from
Oct 31, 2023
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
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