diff --git a/src/kili/adapters/kili_api_gateway/project/__init__.py b/src/kili/adapters/kili_api_gateway/project/__init__.py index e99fe159d..d6988c9a3 100644 --- a/src/kili/adapters/kili_api_gateway/project/__init__.py +++ b/src/kili/adapters/kili_api_gateway/project/__init__.py @@ -91,6 +91,13 @@ def list_projects( projects_gen = (load_project_json_fields(project, fields) for project in projects_gen) return projects_gen + def count_projects(self, project_filters: ProjectFilters) -> int: + """Return the number of projects.""" + where = project_where_mapper(filters=project_filters) + variables = {"where": where} + result = self.graphql_client.execute(GQL_COUNT_PROJECTS, variables) + return result["data"] + def update_properties_in_project( self, project_id: ProjectId, diff --git a/src/kili/client.py b/src/kili/client.py index 2b90f9e5c..83fa5162a 100644 --- a/src/kili/client.py +++ b/src/kili/client.py @@ -27,7 +27,6 @@ from kili.entrypoints.queries.notification import QueriesNotification from kili.entrypoints.queries.organization import QueriesOrganization from kili.entrypoints.queries.plugins import QueriesPlugins -from kili.entrypoints.queries.project import QueriesProject from kili.entrypoints.queries.project_user import QueriesProjectUser from kili.entrypoints.queries.project_version import QueriesProjectVersion from kili.entrypoints.queries.user import QueriesUser @@ -71,7 +70,6 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes QueriesNotification, QueriesOrganization, QueriesPlugins, - QueriesProject, QueriesProjectUser, QueriesProjectVersion, QueriesUser, diff --git a/src/kili/entrypoints/queries/project/__init__.py b/src/kili/entrypoints/queries/project/__init__.py index 58c160a6b..e69de29bb 100644 --- a/src/kili/entrypoints/queries/project/__init__.py +++ b/src/kili/entrypoints/queries/project/__init__.py @@ -1,58 +0,0 @@ -"""Project queries.""" - -from typing import Optional - -from typeguard import typechecked - -from kili.core.graphql.operations.project.queries import ProjectQuery, ProjectWhere -from kili.entrypoints.base import BaseOperationEntrypointMixin -from kili.utils.logcontext import for_all_methods, log_call - - -@for_all_methods(log_call, exclude=["__init__"]) -class QueriesProject(BaseOperationEntrypointMixin): - """Set of Project queries.""" - - # pylint: disable=too-many-arguments - - @typechecked - def count_projects( - self, - project_id: Optional[str] = None, - search_query: Optional[str] = None, - should_relaunch_kpi_computation: Optional[bool] = None, - updated_at_gte: Optional[str] = None, - updated_at_lte: Optional[str] = None, - archived: Optional[bool] = None, - ) -> int: - # pylint: disable=line-too-long - """Count the number of projects with a search_query. - - Args: - project_id: Select a specific project through its project_id. - search_query: Returned projects with a title or a description matching this [PostgreSQL ILIKE](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE) pattern. - should_relaunch_kpi_computation: Technical field, added to indicate changes in honeypot - or consensus settings - updated_at_gte: Returned projects should have a label - whose update date is greater - or equal to this date. - updated_at_lte: Returned projects should have a label - whose update date is lower or equal to this date. - archived: If `True`, only archived projects are returned, if `False`, only active projects are returned. - None disable this filter. - - !!! info "Dates format" - Date strings should have format: "YYYY-MM-DD" - - Returns: - The number of projects with the parameters provided - """ - where = ProjectWhere( - project_id=project_id, - search_query=search_query, - should_relaunch_kpi_computation=should_relaunch_kpi_computation, - updated_at_gte=updated_at_gte, - updated_at_lte=updated_at_lte, - archived=archived, - ) - return ProjectQuery(self.graphql_client, self.http_client).count(where) diff --git a/src/kili/presentation/client/project.py b/src/kili/presentation/client/project.py index df1e50726..c3e3bef0b 100644 --- a/src/kili/presentation/client/project.py +++ b/src/kili/presentation/client/project.py @@ -370,3 +370,47 @@ def update_properties_in_project( title=title, metadata_types=metadata_types, ) + + @typechecked + # pylint: disable=too-many-arguments + def count_projects( + self, + project_id: Optional[str] = None, + search_query: Optional[str] = None, + should_relaunch_kpi_computation: Optional[bool] = None, + updated_at_gte: Optional[str] = None, + updated_at_lte: Optional[str] = None, + archived: Optional[bool] = None, + ) -> int: + # pylint: disable=line-too-long + """Count the number of projects with a search_query. + + Args: + project_id: Select a specific project through its project_id. + search_query: Returned projects with a title or a description matching this [PostgreSQL ILIKE](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE) pattern. + should_relaunch_kpi_computation: Technical field, added to indicate changes in honeypot + or consensus settings + updated_at_gte: Returned projects should have a label + whose update date is greater + or equal to this date. + updated_at_lte: Returned projects should have a label + whose update date is lower or equal to this date. + archived: If `True`, only archived projects are returned, if `False`, only active projects are returned. + None disable this filter. + + !!! info "Dates format" + Date strings should have format: "YYYY-MM-DD" + + Returns: + The number of projects with the parameters provided + """ + return ProjectUseCases(self.kili_api_gateway).count_projects( + ProjectFilters( + id=ProjectId(project_id) if project_id else None, + search_query=search_query, + should_relaunch_kpi_computation=should_relaunch_kpi_computation, + updated_at_gte=updated_at_gte, + updated_at_lte=updated_at_lte, + archived=archived, + ) + ) diff --git a/src/kili/use_cases/project/project.py b/src/kili/use_cases/project/project.py index 69d2d728a..ff37eeb15 100644 --- a/src/kili/use_cases/project/project.py +++ b/src/kili/use_cases/project/project.py @@ -67,6 +67,10 @@ def list_projects( options=QueryOptions(skip=skip, first=first, disable_tqdm=disable_tqdm), ) + def count_projects(self, project_filters: ProjectFilters) -> int: + """Return the number of projects that match the filter.""" + return self._kili_api_gateway.count_projects(project_filters) + # pylint: disable=too-many-locals def update_properties_in_project( self,