From 6f43989a5d091df5f36edf380b281d68d1b64324 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Wed, 22 Apr 2020 22:30:24 +0200
Subject: [PATCH] discard "Kd ratio" compound activities from "best activity"

this complements work in a075f990cb27817ce3f90e547768d646b090f557
related to #204
---
 ippisite/ippidb/models.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index b510423f..15dde95a 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -1038,9 +1038,7 @@ class TestActivityDescription(models.Model):
     nb_active_compounds = models.IntegerField(
         verbose_name="Total number of active compounds"
     )
-    cell_line = models.ForeignKey(
-        CellLine, on_delete=models.SET_NULL, null=True
-    )
+    cell_line = models.ForeignKey(CellLine, on_delete=models.SET_NULL, null=True)
 
     def get_complexes(self):
         """
@@ -1326,7 +1324,12 @@ def update_compound_cached_properties(compounds_queryset=None):
         ),
         best_activity=Subquery(
             compounds_queryset.filter(id=OuterRef("id"))
-            .annotate(_best_activity=Max("compoundactivityresult__activity"))
+            .annotate(
+                _best_activity=Max(
+                    "compoundactivityresult__activity",
+                    filter=~Q(compoundactivityresult__activity_type="KdRat"),
+                )
+            )
             .values("_best_activity")[:1]
         ),
         le=Subquery(
-- 
GitLab