Extract normalized project summary service
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 20:45:42 +03:00
parent b97c449211
commit ff8f9a6dd4
3 changed files with 87 additions and 69 deletions
+5 -69
View File
@@ -108,7 +108,6 @@ from api_server.metadata_tree_builder import (
_metadata_tree_children_for_node, _metadata_tree_children_for_node,
_metadata_tree_path_for_node, _metadata_tree_path_for_node,
_metadata_tree_path_steps, _metadata_tree_path_steps,
_normalized_all_groups,
_normalized_metadata_tree_children_for_node, _normalized_metadata_tree_children_for_node,
_project_metadata_tree_response as _builder_project_metadata_tree_response, _project_metadata_tree_response as _builder_project_metadata_tree_response,
_project_metadata_tree_response_from_normalized as _builder_project_metadata_tree_response_from_normalized, _project_metadata_tree_response_from_normalized as _builder_project_metadata_tree_response_from_normalized,
@@ -121,6 +120,11 @@ from api_server.metadata_tree_models import (
MetadataTreeSearchResponse, MetadataTreeSearchResponse,
ProjectMetadataTreeResponse, ProjectMetadataTreeResponse,
) )
from api_server.normalized_project_models import NormalizedProjectSummary
from api_server.normalized_project_service import (
normalized_all_groups as _normalized_all_groups,
normalized_project_summary as _normalized_project_summary,
)
from impact_engine import object_impact, routine_impact from impact_engine import object_impact, routine_impact
from incremental_indexer import rebuild_changed_file from incremental_indexer import rebuild_changed_file
from integration_topology import IntegrationKind, build_integration_topology from integration_topology import IntegrationKind, build_integration_topology
@@ -925,31 +929,6 @@ class ImportSyncPreview(BaseModel):
items: list[ImportSyncDiffItem] = Field(default_factory=list) items: list[ImportSyncDiffItem] = Field(default_factory=list)
class NormalizedGroupSummary(BaseModel):
name: str
object_kind: str
object_count: int
class NormalizedProjectSummary(BaseModel):
project_id: str | None = None
source_path: str | None = None
group_count: int = 0
object_count: int = 0
attribute_count: int = 0
tabular_section_count: int = 0
form_count: int = 0
command_count: int = 0
role_count: int = 0
rights_count: int = 0
module_count: int = 0
layout_count: int = 0
movement_count: int = 0
extension_count: int = 0
extensions: list[str] = Field(default_factory=list)
groups: list[NormalizedGroupSummary] = Field(default_factory=list)
class NormalizedObjectDetail(BaseModel): class NormalizedObjectDetail(BaseModel):
project_id: str | None = None project_id: str | None = None
group_name: str group_name: str
@@ -7429,49 +7408,6 @@ def _load_normalized_project(project_id: str) -> NormalizedProject | None:
return normalized return normalized
def _normalized_project_summary(normalized: NormalizedProject) -> NormalizedProjectSummary:
all_groups = _normalized_all_groups(normalized)
objects = [item for group in all_groups for item in group.objects]
return NormalizedProjectSummary(
project_id=normalized.project_id,
source_path=normalized.source_path,
group_count=len(all_groups),
object_count=len(objects),
attribute_count=sum(
len(item.attributes)
+ sum(_normalized_part_descendant_count(section, "ATTRIBUTE") for section in item.tabular_sections)
+ sum(_normalized_part_descendant_count(form, "ATTRIBUTE") for form in item.forms)
for item in objects
),
tabular_section_count=sum(len(item.tabular_sections) for item in objects),
form_count=sum(len(item.forms) for item in objects),
command_count=sum(len(item.commands) for item in objects),
role_count=sum(1 for item in objects if item.object_kind == "ROLE"),
rights_count=sum(len(item.rights) for item in objects),
module_count=sum(len(item.modules) for item in objects),
layout_count=sum(len(item.layouts) for item in objects),
movement_count=sum(len(item.movements) for item in objects),
extension_count=len(normalized.configuration.extensions),
extensions=[item.name for item in normalized.configuration.extensions],
groups=[
NormalizedGroupSummary(
name=group.name,
object_kind=", ".join(group.object_kinds),
object_count=len(group.objects),
)
for group in all_groups
],
)
def _normalized_part_descendant_count(part, kind: str | None = None) -> int:
children = getattr(part, "children", [])
return sum(
(1 if kind is None or child.kind == kind else 0) + _normalized_part_descendant_count(child, kind)
for child in children
)
def _quality_check( def _quality_check(
code: str, code: str,
title: str, title: str,
@@ -0,0 +1,28 @@
from __future__ import annotations
from pydantic import BaseModel, Field
class NormalizedGroupSummary(BaseModel):
name: str
object_kind: str
object_count: int
class NormalizedProjectSummary(BaseModel):
project_id: str | None = None
source_path: str | None = None
group_count: int = 0
object_count: int = 0
attribute_count: int = 0
tabular_section_count: int = 0
form_count: int = 0
command_count: int = 0
role_count: int = 0
rights_count: int = 0
module_count: int = 0
layout_count: int = 0
movement_count: int = 0
extension_count: int = 0
extensions: list[str] = Field(default_factory=list)
groups: list[NormalizedGroupSummary] = Field(default_factory=list)
@@ -0,0 +1,54 @@
from __future__ import annotations
from api_server.normalized_project_models import NormalizedGroupSummary, NormalizedProjectSummary
from one_c_normalizer import NormalizedProject
def normalized_all_groups(normalized: NormalizedProject):
groups = list(normalized.configuration.groups)
for extension in normalized.configuration.extensions:
groups.extend(extension.groups)
return groups
def normalized_project_summary(normalized: NormalizedProject) -> NormalizedProjectSummary:
all_groups = normalized_all_groups(normalized)
objects = [item for group in all_groups for item in group.objects]
return NormalizedProjectSummary(
project_id=normalized.project_id,
source_path=normalized.source_path,
group_count=len(all_groups),
object_count=len(objects),
attribute_count=sum(
len(item.attributes)
+ sum(normalized_part_descendant_count(section, "ATTRIBUTE") for section in item.tabular_sections)
+ sum(normalized_part_descendant_count(form, "ATTRIBUTE") for form in item.forms)
for item in objects
),
tabular_section_count=sum(len(item.tabular_sections) for item in objects),
form_count=sum(len(item.forms) for item in objects),
command_count=sum(len(item.commands) for item in objects),
role_count=sum(1 for item in objects if item.object_kind == "ROLE"),
rights_count=sum(len(item.rights) for item in objects),
module_count=sum(len(item.modules) for item in objects),
layout_count=sum(len(item.layouts) for item in objects),
movement_count=sum(len(item.movements) for item in objects),
extension_count=len(normalized.configuration.extensions),
extensions=[item.name for item in normalized.configuration.extensions],
groups=[
NormalizedGroupSummary(
name=group.name,
object_kind=", ".join(group.object_kinds),
object_count=len(group.objects),
)
for group in all_groups
],
)
def normalized_part_descendant_count(part, kind: str | None = None) -> int:
children = getattr(part, "children", [])
return sum(
(1 if kind is None or child.kind == kind else 0) + normalized_part_descendant_count(child, kind)
for child in children
)