Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: count_projects #1500

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/kili/adapters/kili_api_gateway/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/kili/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +70,6 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes
QueriesNotification,
QueriesOrganization,
QueriesPlugins,
QueriesProject,
QueriesProjectUser,
QueriesProjectVersion,
QueriesUser,
Expand Down
58 changes: 0 additions & 58 deletions src/kili/entrypoints/queries/project/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions src/kili/presentation/client/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
4 changes: 4 additions & 0 deletions src/kili/use_cases/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down