Skip to content
Snippets Groups Projects
Commit f905b2f0 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[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.
parent b50b95b4
No related branches found
No related tags found
1 merge request!324Return compatibility information for algorithms and libraries
...@@ -204,7 +204,7 @@ class Algorithm(Code): ...@@ -204,7 +204,7 @@ class Algorithm(Code):
Returns: Returns:
list: mapping environment to usage counts, determining how many times 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): ...@@ -213,27 +213,25 @@ class Algorithm(Code):
from ..backend.models import Environment from ..backend.models import Environment
# Tries to figure through a maximum if an algorithm has been # 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 1) The block is part of an experiment that was successful
# Case 2) The block is part of an experiment that is not 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 # (failed or other), but it is CACHED (if not cached, then we can't
# attest anything about the algorithm/environment relationship!) # attest anything about the algorithm/environment relationship!)
envs = ( return (
Environment.objects.filter( Environment.objects.filter(
blocks__in=self.blocks.filter( blocks__in=self.blocks.filter(
Q(experiment__status=Experiment.DONE) Q(experiment__status=Experiment.DONE)
| ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE)) | ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE))
) )
) )
.annotate(itemcount=Count("id")) .annotate(use_count=Count("id"))
.order_by("-creation_date") .order_by("-creation_date")
.distinct() .distinct()
) )
return [(k, k.itemcount) for k in envs]
# _____ Overrides __________ # _____ Overrides __________
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment