Add support for project stats with children flag

This commit is contained in:
allegroai 2022-02-13 19:26:47 +02:00
parent 36e013b40c
commit e334246b46
4 changed files with 15 additions and 1 deletions

View File

@ -53,6 +53,7 @@ class ProjectHyperparamValuesRequest(MultiProjectRequest):
class ProjectsGetRequest(models.Base): class ProjectsGetRequest(models.Base):
include_stats = fields.BoolField(default=False) include_stats = fields.BoolField(default=False)
stats_with_children = fields.BoolField(default=True)
stats_for_state = ActualEnumField(EntityVisibility, default=EntityVisibility.active) stats_for_state = ActualEnumField(EntityVisibility, default=EntityVisibility.active)
non_public = fields.BoolField(default=False) non_public = fields.BoolField(default=False)
active_users = fields.ListField(str) active_users = fields.ListField(str)

View File

@ -456,11 +456,16 @@ class ProjectBLL:
company: str, company: str,
project_ids: Sequence[str], project_ids: Sequence[str],
specific_state: Optional[EntityVisibility] = None, specific_state: Optional[EntityVisibility] = None,
include_children: bool = True,
) -> Tuple[Dict[str, dict], Dict[str, dict]]: ) -> Tuple[Dict[str, dict], Dict[str, dict]]:
if not project_ids: if not project_ids:
return {}, {} return {}, {}
child_projects = _get_sub_projects(project_ids, _only=("id", "name")) child_projects = (
_get_sub_projects(project_ids, _only=("id", "name"))
if include_children
else {}
)
project_ids_with_children = set(project_ids) | { project_ids_with_children = set(project_ids) | {
c.id for c in itertools.chain.from_iterable(child_projects.values()) c.id for c in itertools.chain.from_iterable(child_projects.values())
} }

View File

@ -539,6 +539,13 @@ get_all_ex {
description: "Scroll ID that can be used with the next calls to get_all to retrieve more data" description: "Scroll ID that can be used with the next calls to get_all to retrieve more data"
} }
} }
"999.0": ${get_all_ex."2.15"} {
response.properties.stats_with_children {
description: "If include_stats flag is set then this flag contols whether the child projects tasks are taken into statistics or not"
type: boolean
default: true
}
}
} }
update { update {
"2.1" { "2.1" {

View File

@ -140,6 +140,7 @@ def get_all_ex(call: APICall, company_id: str, request: ProjectsGetRequest):
company=company_id, company=company_id,
project_ids=list(project_ids), project_ids=list(project_ids),
specific_state=request.stats_for_state, specific_state=request.stats_for_state,
include_children=request.stats_with_children,
) )
for project in projects: for project in projects: