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

[algorithms][models] Use new Environment object use_count method

parent 3a21221e
No related branches found
No related tags found
1 merge request!324Return compatibility information for algorithms and libraries
......@@ -229,36 +229,17 @@ class Library(Code):
Returns:
list: mapping environment to usage counts, determining how many times
a given algorithm has been successfully used on that environment
list: annotated environment with usage counts, determining how many times
a given library used in algorithms has been successfully used on that environment
"""
from django.db.models import Count, Q
from ..experiments.models import Block
from ..experiments.models import Experiment
from ..backend.models import Environment
# Tries to figure through a maximum if using algorithms have been
# 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 = (
Environment.objects.filter(
blocks__in=Block.objects.filter(
algorithm__in=self.used_by_algorithms.all()
).filter(
Q(experiment__status=Experiment.DONE)
| ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE))
)
)
.annotate(itemcount=Count("id"))
.order_by("-creation_date")
.distinct()
return Environment.objects.use_count(
Block.objects.filter(algorithm__in=self.used_by_algorithms.all())
)
return [(k, k.itemcount) for k in envs]
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