From 0c426bac8d34d85b6154fd580d1248e44310f767 Mon Sep 17 00:00:00 2001 From: whohensee <106775295+whohensee@users.noreply.github.com> Date: Tue, 15 Oct 2024 08:37:31 -0700 Subject: [PATCH] Changes from review --- models/deepscore.py | 25 ------------------------- pipeline/data_store.py | 13 +++---------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/models/deepscore.py b/models/deepscore.py index 2f5dea95..7f4e4d34 100644 --- a/models/deepscore.py +++ b/models/deepscore.py @@ -120,31 +120,6 @@ def from_measurements(measurements, provenance=None, **kwargs): return score - def evaluate_scores(self): - """Evaluate the ML/DL score for the associated measurement, using the - appropriate algorithm. - """ - # consider doing cases or another solution, for now just if-else block - - algo = Provenance.get( self.provenance_id ).parameters['algorithm'] - - if algo == 'random': - self.score = np.random.default_rng().random() - self.algorithm = algo - - elif algo == 'allperfect': - self.score = 1.0 - self.algorithm = algo - - elif algo in DeepscoreAlgorithmConverter.dict_inverse: - raise NotImplementedError(f"algorithm {algo} isn't yet implemented") - - else: - raise ValueError(f"{algo} is not a valid ML algorithm.") - - return None - - def get_upstreams(self, session=None): """Get the measurements that was used to make this deepscore. """ with SmartSession(session) as session: diff --git a/pipeline/data_store.py b/pipeline/data_store.py index dfac1bab..42a2c41a 100644 --- a/pipeline/data_store.py +++ b/pipeline/data_store.py @@ -1668,19 +1668,12 @@ def get_scores(self, provenance=None, reload=False, session=None): # sort the scores so the list order matches measurements if scores is not None and len(scores) > 0: + if len(scores) != len(self.measurements): raise RuntimeError(f"get_scores found {len(scores)} scores for {len(self.measurements)} measurements") + m_ids = [str(m.id) for m in self.measurements] - sorted_scores = [None]*len(self.scores) - for score in scores: - idx = m_ids.index(str(score.measurements_id)) - sorted_scores[idx] = score - - if not all(scores): # check if any None still remain - raise RuntimeError(f"get_scores did not replace all None values when sorting list") - - scores = sorted_scores - self.scores = scores # update the order in ds to be sorted too. + scores.sort( key=lambda x: m_ids.index( str(x.measurements_id) ) ) return scores