mirror of
https://github.com/clearml/clearml-server
synced 2025-05-22 12:14:33 +00:00
Add support for organization.get_entities_count
This commit is contained in:
parent
dd8a1503b0
commit
f8b9d9802e
@ -1,5 +1,7 @@
|
||||
from jsonmodels import fields, models
|
||||
|
||||
from apiserver.apimodels import DictField
|
||||
|
||||
|
||||
class Filter(models.Base):
|
||||
tags = fields.ListField([str])
|
||||
@ -9,3 +11,10 @@ class Filter(models.Base):
|
||||
class TagsRequest(models.Base):
|
||||
include_system = fields.BoolField(default=False)
|
||||
filter = fields.EmbeddedField(Filter)
|
||||
|
||||
|
||||
class EntitiesCountRequest(models.Base):
|
||||
projects = DictField()
|
||||
tasks = DictField()
|
||||
models = DictField()
|
||||
pipelines = DictField()
|
||||
|
@ -102,4 +102,55 @@ get_user_companies {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
get_entities_count {
|
||||
"999.0": {
|
||||
description: "Get counts for the company entities according to the passed search criteria"
|
||||
request {
|
||||
type: object
|
||||
properties {
|
||||
projects {
|
||||
type: object
|
||||
additionalProperties: true
|
||||
description: Search criteria for projects
|
||||
}
|
||||
tasks {
|
||||
type: object
|
||||
additionalProperties: true
|
||||
description: Search criteria for experiments
|
||||
}
|
||||
models {
|
||||
type: object
|
||||
additionalProperties: true
|
||||
description: Search criteria for models
|
||||
}
|
||||
pipelines {
|
||||
type: object
|
||||
additionalProperties: true
|
||||
description: Search criteria for pipelines
|
||||
}
|
||||
}
|
||||
}
|
||||
response {
|
||||
type: object
|
||||
properties {
|
||||
projects {
|
||||
type: integer
|
||||
description: The number of projects matching the criteria
|
||||
}
|
||||
tasks {
|
||||
type: integer
|
||||
description: The number of experiments matching the criteria
|
||||
}
|
||||
models {
|
||||
type: integer
|
||||
description: The number of models matching the criteria
|
||||
}
|
||||
pipelines {
|
||||
type: integer
|
||||
description: The number of pipelines matching the criteria
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
from collections import defaultdict
|
||||
from operator import itemgetter
|
||||
from typing import Mapping, Type
|
||||
|
||||
from apiserver.apimodels.organization import TagsRequest
|
||||
from mongoengine import Q
|
||||
|
||||
from apiserver.apimodels.organization import TagsRequest, EntitiesCountRequest
|
||||
from apiserver.bll.organization import OrgBLL, Tags
|
||||
from apiserver.database.model import User
|
||||
from apiserver.database.model import User, AttributedDocument, EntityVisibility
|
||||
from apiserver.database.model.model import Model
|
||||
from apiserver.database.model.project import Project
|
||||
from apiserver.database.model.task.task import Task
|
||||
from apiserver.service_repo import endpoint, APICall
|
||||
from apiserver.services.utils import get_tags_filter_dictionary, sort_tags_response
|
||||
|
||||
@ -41,3 +47,28 @@ def get_user_companies(call: APICall, company_id: str, _):
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@endpoint("organization.get_entities_count", request_data_model=EntitiesCountRequest)
|
||||
def get_entities_count(call: APICall, company, _):
|
||||
entity_classes: Mapping[str, Type[AttributedDocument]] = {
|
||||
"projects": Project,
|
||||
"tasks": Task,
|
||||
"models": Model,
|
||||
"pipelines": Project,
|
||||
}
|
||||
ret = {}
|
||||
for field, entity_cls in entity_classes.items():
|
||||
data = call.data.get(field)
|
||||
if data is None:
|
||||
continue
|
||||
|
||||
query = Q()
|
||||
if entity_cls in (Project, Task) and not data.get("search_hidden"):
|
||||
query &= Q(system_tags__ne=EntityVisibility.hidden.value)
|
||||
|
||||
ret[field] = entity_cls.get_count(
|
||||
company=company, query_dict=data, query=query, allow_public=True,
|
||||
)
|
||||
|
||||
call.result.data = ret
|
||||
|
Loading…
Reference in New Issue
Block a user