From f905b2f001dfe7b9ac7c1200a3d86c69c5318e3d Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Tue, 7 Apr 2020 15:27:06 +0200
Subject: [PATCH] [algorithms][models] Return directly the queryset output for
 "used in" environments

No reason to return a tuple as the query is annotated.

This will allow easier use in the serialization part.
---
 beat/web/algorithms/models.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/beat/web/algorithms/models.py b/beat/web/algorithms/models.py
index c45c2adff..de6182099 100755
--- a/beat/web/algorithms/models.py
+++ b/beat/web/algorithms/models.py
@@ -204,7 +204,7 @@ class Algorithm(Code):
         Returns:
 
           list: mapping environment to usage counts, determining how many times
-            a given algorithm has been successfuly used on that environment
+            a given algorithm has been successfully used on that environment
 
         """
 
@@ -213,27 +213,25 @@ class Algorithm(Code):
         from ..backend.models import Environment
 
         # Tries to figure through a maximum if an algorithm has been
-        # successfuly used inside an environment.
+        # successfully used inside an environment.
 
         # Case 1) The block is part of an experiment that was successful
         # Case 2) The block is part of an experiment that is not successful
         # (failed or other), but it is CACHED (if not cached, then we can't
         # attest anything about the algorithm/environment relationship!)
 
-        envs = (
+        return (
             Environment.objects.filter(
                 blocks__in=self.blocks.filter(
                     Q(experiment__status=Experiment.DONE)
                     | ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE))
                 )
             )
-            .annotate(itemcount=Count("id"))
+            .annotate(use_count=Count("id"))
             .order_by("-creation_date")
             .distinct()
         )
 
-        return [(k, k.itemcount) for k in envs]
-
     # _____ Overrides __________
 
     def save(self, *args, **kwargs):
-- 
GitLab