git-contribution-analyzer 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_contribution_analyzer/__init__.py +3 -0
- git_contribution_analyzer/adapters/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/local_identity.py +51 -0
- git_contribution_analyzer/adapters/git/native_git.py +353 -0
- git_contribution_analyzer/adapters/git/pydriller_history.py +57 -0
- git_contribution_analyzer/adapters/git/repository_discovery.py +75 -0
- git_contribution_analyzer/adapters/gui/__init__.py +1 -0
- git_contribution_analyzer/adapters/gui/app.py +63 -0
- git_contribution_analyzer/adapters/gui/controller.py +1084 -0
- git_contribution_analyzer/adapters/gui/models/__init__.py +3 -0
- git_contribution_analyzer/adapters/gui/models/base_table.py +108 -0
- git_contribution_analyzer/adapters/gui/settings.py +53 -0
- git_contribution_analyzer/adapters/gui/task_runner.py +196 -0
- git_contribution_analyzer/adapters/llm/__init__.py +1 -0
- git_contribution_analyzer/adapters/llm/anthropic.py +52 -0
- git_contribution_analyzer/adapters/llm/base.py +142 -0
- git_contribution_analyzer/adapters/llm/cache.py +148 -0
- git_contribution_analyzer/adapters/llm/claude_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/codex_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/command_base.py +153 -0
- git_contribution_analyzer/adapters/llm/mock.py +82 -0
- git_contribution_analyzer/adapters/llm/ollama.py +53 -0
- git_contribution_analyzer/adapters/llm/openai_compatible.py +61 -0
- git_contribution_analyzer/adapters/llm/registry.py +117 -0
- git_contribution_analyzer/adapters/mcp/__init__.py +13 -0
- git_contribution_analyzer/adapters/mcp/installer.py +175 -0
- git_contribution_analyzer/adapters/mcp/prompts_resources.py +218 -0
- git_contribution_analyzer/adapters/mcp/protocol.py +361 -0
- git_contribution_analyzer/adapters/mcp/server.py +52 -0
- git_contribution_analyzer/adapters/mcp/tools.py +621 -0
- git_contribution_analyzer/adapters/outcomes/__init__.py +1 -0
- git_contribution_analyzer/adapters/outcomes/yaml_loader.py +55 -0
- git_contribution_analyzer/adapters/outcomes/yaml_store.py +104 -0
- git_contribution_analyzer/adapters/reporting/__init__.py +1 -0
- git_contribution_analyzer/adapters/reporting/brag_markdown.py +115 -0
- git_contribution_analyzer/adapters/reporting/html_report.py +1413 -0
- git_contribution_analyzer/adapters/reporting/markdown.py +217 -0
- git_contribution_analyzer/adapters/reporting/portfolio_markdown.py +167 -0
- git_contribution_analyzer/adapters/reporting/recap_markdown.py +212 -0
- git_contribution_analyzer/adapters/reporting/resume_markdown.py +37 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_csv.py +117 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_markdown.py +90 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_series_markdown.py +31 -0
- git_contribution_analyzer/adapters/storage/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/analysis.py +708 -0
- git_contribution_analyzer/adapters/storage/sqlite/database.py +98 -0
- git_contribution_analyzer/adapters/storage/sqlite/git_index.py +482 -0
- git_contribution_analyzer/adapters/storage/sqlite/identity_merge.py +373 -0
- git_contribution_analyzer/adapters/storage/sqlite/llm_audit.py +109 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/env.py +34 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/script.py.mako +22 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0001_initial.py +51 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0002_git_index.py +146 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0003_analysis.py +79 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0004_llm_audit.py +69 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0005_run_types.py +42 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0006_identity_merges.py +83 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0007_structural_baselines.py +173 -0
- git_contribution_analyzer/adapters/storage/sqlite/models.py +354 -0
- git_contribution_analyzer/adapters/storage/sqlite/structural_baseline.py +841 -0
- git_contribution_analyzer/adapters/workspace/__init__.py +1 -0
- git_contribution_analyzer/adapters/workspace/config.py +135 -0
- git_contribution_analyzer/adapters/workspace/git_exclude.py +32 -0
- git_contribution_analyzer/adapters/workspace/layout.py +40 -0
- git_contribution_analyzer/adapters/workspace/locks.py +27 -0
- git_contribution_analyzer/adapters/workspace/portfolio_workspace.py +380 -0
- git_contribution_analyzer/adapters/workspace/ranking_config.py +17 -0
- git_contribution_analyzer/application/__init__.py +1 -0
- git_contribution_analyzer/application/dto/__init__.py +19 -0
- git_contribution_analyzer/application/dto/gui.py +86 -0
- git_contribution_analyzer/application/dto/results.py +21 -0
- git_contribution_analyzer/application/facades/__init__.py +3 -0
- git_contribution_analyzer/application/facades/gui.py +568 -0
- git_contribution_analyzer/application/ports/__init__.py +22 -0
- git_contribution_analyzer/application/ports/cancellation.py +50 -0
- git_contribution_analyzer/application/ports/git_history.py +22 -0
- git_contribution_analyzer/application/ports/llm.py +44 -0
- git_contribution_analyzer/application/ports/portfolio_store.py +34 -0
- git_contribution_analyzer/application/ports/progress.py +43 -0
- git_contribution_analyzer/application/ports/structural_baseline.py +93 -0
- git_contribution_analyzer/application/services/__init__.py +1 -0
- git_contribution_analyzer/application/services/assessment_explanation.py +127 -0
- git_contribution_analyzer/application/services/default_person.py +61 -0
- git_contribution_analyzer/application/services/evidence_snapshot.py +64 -0
- git_contribution_analyzer/application/services/person_selection.py +88 -0
- git_contribution_analyzer/application/services/resume_generation.py +318 -0
- git_contribution_analyzer/application/services/semantic_enhancement.py +157 -0
- git_contribution_analyzer/application/services/time_boundaries.py +49 -0
- git_contribution_analyzer/application/use_cases/__init__.py +1 -0
- git_contribution_analyzer/application/use_cases/analyze_contributions.py +276 -0
- git_contribution_analyzer/application/use_cases/analyze_project.py +295 -0
- git_contribution_analyzer/application/use_cases/assess_portfolio.py +327 -0
- git_contribution_analyzer/application/use_cases/assess_work.py +602 -0
- git_contribution_analyzer/application/use_cases/assess_work_series.py +212 -0
- git_contribution_analyzer/application/use_cases/compare_assessment_runs.py +121 -0
- git_contribution_analyzer/application/use_cases/export_report.py +49 -0
- git_contribution_analyzer/application/use_cases/generate_brag.py +308 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_recap.py +244 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_resume.py +152 -0
- git_contribution_analyzer/application/use_cases/generate_recap.py +316 -0
- git_contribution_analyzer/application/use_cases/generate_report.py +32 -0
- git_contribution_analyzer/application/use_cases/generate_resume.py +209 -0
- git_contribution_analyzer/application/use_cases/get_portfolio_status.py +83 -0
- git_contribution_analyzer/application/use_cases/get_run.py +16 -0
- git_contribution_analyzer/application/use_cases/get_status.py +69 -0
- git_contribution_analyzer/application/use_cases/index_repository.py +267 -0
- git_contribution_analyzer/application/use_cases/init_portfolio.py +89 -0
- git_contribution_analyzer/application/use_cases/init_project.py +71 -0
- git_contribution_analyzer/application/use_cases/list_identities.py +16 -0
- git_contribution_analyzer/application/use_cases/list_providers.py +29 -0
- git_contribution_analyzer/application/use_cases/list_runs.py +17 -0
- git_contribution_analyzer/application/use_cases/manage_identity_merges.py +48 -0
- git_contribution_analyzer/application/use_cases/manage_outcomes.py +189 -0
- git_contribution_analyzer/application/use_cases/manage_structural_baselines.py +262 -0
- git_contribution_analyzer/application/use_cases/map_identity.py +28 -0
- git_contribution_analyzer/application/use_cases/recover_runs.py +22 -0
- git_contribution_analyzer/application/use_cases/run_doctor.py +81 -0
- git_contribution_analyzer/application/use_cases/sync_portfolio.py +232 -0
- git_contribution_analyzer/application/use_cases/test_provider.py +22 -0
- git_contribution_analyzer/application/use_cases/uninit_project.py +23 -0
- git_contribution_analyzer/application/use_cases/verify_portfolio.py +165 -0
- git_contribution_analyzer/cli/__init__.py +1 -0
- git_contribution_analyzer/cli/app.py +1430 -0
- git_contribution_analyzer/cli/exit_codes.py +13 -0
- git_contribution_analyzer/cli/output.py +26 -0
- git_contribution_analyzer/cli/portfolio_commands.py +629 -0
- git_contribution_analyzer/domain/__init__.py +1 -0
- git_contribution_analyzer/domain/errors.py +55 -0
- git_contribution_analyzer/domain/models/__init__.py +3 -0
- git_contribution_analyzer/domain/models/analysis.py +29 -0
- git_contribution_analyzer/domain/models/assessment.py +12 -0
- git_contribution_analyzer/domain/models/brag.py +148 -0
- git_contribution_analyzer/domain/models/contribution.py +55 -0
- git_contribution_analyzer/domain/models/git_history.py +69 -0
- git_contribution_analyzer/domain/models/person_selection.py +46 -0
- git_contribution_analyzer/domain/models/portfolio.py +498 -0
- git_contribution_analyzer/domain/models/ranking.py +48 -0
- git_contribution_analyzer/domain/models/recap.py +235 -0
- git_contribution_analyzer/domain/models/repository.py +10 -0
- git_contribution_analyzer/domain/models/resume.py +59 -0
- git_contribution_analyzer/domain/models/run.py +10 -0
- git_contribution_analyzer/domain/models/semantic.py +34 -0
- git_contribution_analyzer/domain/models/snapshot.py +208 -0
- git_contribution_analyzer/domain/models/structural_baseline.py +120 -0
- git_contribution_analyzer/domain/models/work_assessment.py +81 -0
- git_contribution_analyzer/domain/services/assessment_periods.py +182 -0
- git_contribution_analyzer/domain/services/brag_rules.py +250 -0
- git_contribution_analyzer/domain/services/capability_rules.py +91 -0
- git_contribution_analyzer/domain/services/contribution_clustering.py +98 -0
- git_contribution_analyzer/domain/services/contribution_rules.py +79 -0
- git_contribution_analyzer/domain/services/difficulty_rules.py +191 -0
- git_contribution_analyzer/domain/services/dimensional_summary.py +117 -0
- git_contribution_analyzer/domain/services/portfolio_aggregation.py +250 -0
- git_contribution_analyzer/domain/services/portfolio_resume_rules.py +265 -0
- git_contribution_analyzer/domain/services/portfolio_verifier.py +238 -0
- git_contribution_analyzer/domain/services/ranking_rules.py +226 -0
- git_contribution_analyzer/domain/services/recap_rules.py +268 -0
- git_contribution_analyzer/domain/services/resume_claim_rules.py +70 -0
- git_contribution_analyzer/domain/services/structural_baseline.py +317 -0
- git_contribution_analyzer/domain/services/structural_signals.py +151 -0
- git_contribution_analyzer/domain/services/workload_rules.py +185 -0
- git_contribution_analyzer/gui/__init__.py +1 -0
- git_contribution_analyzer/gui/qml/Main.qml +1141 -0
- git_contribution_analyzer/gui/qml/__init__.py +1 -0
- git_contribution_analyzer/prompts/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/explanation.txt +4 -0
- git_contribution_analyzer/prompts/resume/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-concise.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-star.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-xyz.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/system.txt +3 -0
- git_contribution_analyzer/prompts/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/v1/capability_explanation.txt +2 -0
- git_contribution_analyzer/prompts/v1/contribution_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/overall_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/resume_bullet.txt +2 -0
- git_contribution_analyzer-0.8.0.dist-info/METADATA +667 -0
- git_contribution_analyzer-0.8.0.dist-info/RECORD +187 -0
- git_contribution_analyzer-0.8.0.dist-info/WHEEL +4 -0
- git_contribution_analyzer-0.8.0.dist-info/entry_points.txt +3 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/LICENSE +201 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/NOTICE +6 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
from collections import defaultdict
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
from dataclasses import asdict
|
|
8
|
+
from datetime import datetime, timedelta
|
|
9
|
+
from itertools import combinations
|
|
10
|
+
from types import MappingProxyType
|
|
11
|
+
|
|
12
|
+
from git_contribution_analyzer.domain.models.contribution import (
|
|
13
|
+
ContributionCommit,
|
|
14
|
+
ContributionItem,
|
|
15
|
+
)
|
|
16
|
+
from git_contribution_analyzer.domain.models.structural_baseline import (
|
|
17
|
+
StructuralBaseline,
|
|
18
|
+
StructuralBaselineSummary,
|
|
19
|
+
StructuralEdgeCount,
|
|
20
|
+
StructuralEdgeMetric,
|
|
21
|
+
StructuralFileCount,
|
|
22
|
+
StructuralFileMetric,
|
|
23
|
+
StructuralMaterialization,
|
|
24
|
+
StructuralRuleConfig,
|
|
25
|
+
StructuralTimeStrategy,
|
|
26
|
+
WorkItemStructuralContext,
|
|
27
|
+
)
|
|
28
|
+
from git_contribution_analyzer.domain.services.contribution_rules import is_generated_path
|
|
29
|
+
|
|
30
|
+
STRUCTURAL_FACT_RULE_VERSION = "structural-facts-v1"
|
|
31
|
+
STRUCTURAL_METRIC_RULE_VERSION = "structural-metrics-v1"
|
|
32
|
+
STRUCTURAL_THRESHOLD_VERSION = "structural-thresholds-community-v1"
|
|
33
|
+
|
|
34
|
+
_LIMITATIONS = (
|
|
35
|
+
"Historical co-change is an association, not a runtime dependency.",
|
|
36
|
+
"Historical hotspots are context signals, not individual performance conclusions.",
|
|
37
|
+
"Mechanical and oversized changes may be excluded or lower confidence.",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_structural_baseline(
|
|
42
|
+
commits: Iterable[ContributionCommit],
|
|
43
|
+
*,
|
|
44
|
+
cutoff: datetime,
|
|
45
|
+
config: StructuralRuleConfig | None = None,
|
|
46
|
+
identity_context: dict[str, str | None] | None = None,
|
|
47
|
+
) -> StructuralBaseline:
|
|
48
|
+
active_config = config or StructuralRuleConfig()
|
|
49
|
+
seen_patches: set[str] = set()
|
|
50
|
+
file_commits: defaultdict[str, set[str]] = defaultdict(set)
|
|
51
|
+
recent_file_commits: defaultdict[str, set[str]] = defaultdict(set)
|
|
52
|
+
edge_commits: defaultdict[tuple[str, str], set[str]] = defaultdict(set)
|
|
53
|
+
recent_edge_commits: defaultdict[tuple[str, str], set[str]] = defaultdict(set)
|
|
54
|
+
supporting: defaultdict[str, set[str]] = defaultdict(set)
|
|
55
|
+
eligible_hashes: list[str] = []
|
|
56
|
+
capped_commits = 0
|
|
57
|
+
recent_boundary = cutoff - timedelta(days=active_config.rolling_window_days)
|
|
58
|
+
|
|
59
|
+
ordered = sorted(commits, key=lambda value: (_occurred_at(value), value.hash))
|
|
60
|
+
for commit in ordered:
|
|
61
|
+
occurred_at = _occurred_at(commit)
|
|
62
|
+
if occurred_at >= cutoff or commit.merge:
|
|
63
|
+
continue
|
|
64
|
+
patch_key = commit.patch_id or commit.hash
|
|
65
|
+
if patch_key in seen_patches:
|
|
66
|
+
continue
|
|
67
|
+
seen_patches.add(patch_key)
|
|
68
|
+
paths = _eligible_paths(commit)
|
|
69
|
+
if not paths:
|
|
70
|
+
continue
|
|
71
|
+
is_recent = occurred_at >= recent_boundary
|
|
72
|
+
if active_config.time_strategy is StructuralTimeStrategy.ROLLING_WINDOW and not is_recent:
|
|
73
|
+
continue
|
|
74
|
+
eligible_hashes.append(commit.hash)
|
|
75
|
+
for path in paths:
|
|
76
|
+
file_commits[path].add(commit.hash)
|
|
77
|
+
supporting[f"file:{path}"].add(commit.hash)
|
|
78
|
+
if is_recent:
|
|
79
|
+
recent_file_commits[path].add(commit.hash)
|
|
80
|
+
if len(paths) > active_config.maximum_context_paths:
|
|
81
|
+
capped_commits += 1
|
|
82
|
+
continue
|
|
83
|
+
for left_path, right_path in combinations(paths, 2):
|
|
84
|
+
edge = (left_path, right_path)
|
|
85
|
+
edge_commits[edge].add(commit.hash)
|
|
86
|
+
supporting[_edge_key(edge)].add(commit.hash)
|
|
87
|
+
if is_recent:
|
|
88
|
+
recent_edge_commits[edge].add(commit.hash)
|
|
89
|
+
|
|
90
|
+
file_counts = tuple(
|
|
91
|
+
StructuralFileCount(
|
|
92
|
+
path=path,
|
|
93
|
+
change_count=len(hashes),
|
|
94
|
+
recent_change_count=len(recent_file_commits[path]),
|
|
95
|
+
)
|
|
96
|
+
for path, hashes in sorted(file_commits.items())
|
|
97
|
+
)
|
|
98
|
+
edge_counts = tuple(
|
|
99
|
+
StructuralEdgeCount(
|
|
100
|
+
left_path=edge[0],
|
|
101
|
+
right_path=edge[1],
|
|
102
|
+
co_change_count=len(hashes),
|
|
103
|
+
recent_co_change_count=len(recent_edge_commits[edge]),
|
|
104
|
+
)
|
|
105
|
+
for edge, hashes in sorted(edge_commits.items())
|
|
106
|
+
if hashes
|
|
107
|
+
)
|
|
108
|
+
baseline_id = _baseline_id(
|
|
109
|
+
eligible_hashes,
|
|
110
|
+
cutoff,
|
|
111
|
+
active_config,
|
|
112
|
+
file_counts,
|
|
113
|
+
edge_counts,
|
|
114
|
+
identity_context or {},
|
|
115
|
+
)
|
|
116
|
+
summary = StructuralBaselineSummary(
|
|
117
|
+
eligible_commits=len(eligible_hashes),
|
|
118
|
+
eligible_files=len(file_counts),
|
|
119
|
+
raw_edges=len(edge_counts),
|
|
120
|
+
capped_commits=capped_commits,
|
|
121
|
+
)
|
|
122
|
+
materialization = _materialize(
|
|
123
|
+
baseline_id,
|
|
124
|
+
summary,
|
|
125
|
+
file_counts,
|
|
126
|
+
edge_counts,
|
|
127
|
+
active_config,
|
|
128
|
+
)
|
|
129
|
+
immutable_supporting = MappingProxyType(
|
|
130
|
+
{key: tuple(sorted(value)) for key, value in sorted(supporting.items())}
|
|
131
|
+
)
|
|
132
|
+
return StructuralBaseline(
|
|
133
|
+
id=baseline_id,
|
|
134
|
+
cutoff=cutoff,
|
|
135
|
+
config=active_config,
|
|
136
|
+
summary=summary,
|
|
137
|
+
file_counts=file_counts,
|
|
138
|
+
edge_counts=edge_counts,
|
|
139
|
+
materialization=materialization,
|
|
140
|
+
supporting_commits=immutable_supporting,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def match_work_item_structural_context(
|
|
145
|
+
item: ContributionItem,
|
|
146
|
+
materialization: StructuralMaterialization,
|
|
147
|
+
) -> WorkItemStructuralContext:
|
|
148
|
+
paths = {path.replace("\\", "/").strip("/") for path in item.paths}
|
|
149
|
+
hotspots = tuple(entry for entry in materialization.file_metrics if entry.path in paths)
|
|
150
|
+
couplings = tuple(
|
|
151
|
+
entry
|
|
152
|
+
for entry in materialization.edge_metrics
|
|
153
|
+
if entry.left_path in paths and entry.right_path in paths
|
|
154
|
+
)
|
|
155
|
+
return WorkItemStructuralContext(
|
|
156
|
+
baseline_id=materialization.baseline_id,
|
|
157
|
+
hotspot_exposures=hotspots,
|
|
158
|
+
coupling_exposures=couplings,
|
|
159
|
+
confidence=materialization.confidence,
|
|
160
|
+
gaps=materialization.gaps,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _materialize(
|
|
165
|
+
baseline_id: str,
|
|
166
|
+
summary: StructuralBaselineSummary,
|
|
167
|
+
file_counts: tuple[StructuralFileCount, ...],
|
|
168
|
+
edge_counts: tuple[StructuralEdgeCount, ...],
|
|
169
|
+
config: StructuralRuleConfig,
|
|
170
|
+
) -> StructuralMaterialization:
|
|
171
|
+
if summary.eligible_commits < config.minimum_baseline_commits:
|
|
172
|
+
insufficient_gaps = ["INSUFFICIENT_STRUCTURAL_BASELINE"]
|
|
173
|
+
if summary.capped_commits:
|
|
174
|
+
insufficient_gaps.append("STRUCTURAL_CONTEXT_CAPPED")
|
|
175
|
+
return StructuralMaterialization(
|
|
176
|
+
baseline_id=baseline_id,
|
|
177
|
+
file_metrics=(),
|
|
178
|
+
edge_metrics=(),
|
|
179
|
+
confidence="LOW",
|
|
180
|
+
gaps=tuple(insufficient_gaps),
|
|
181
|
+
limitations=_LIMITATIONS,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
confidence = _confidence(summary.eligible_commits, config.minimum_baseline_commits)
|
|
185
|
+
change_counts = tuple(entry.change_count for entry in file_counts)
|
|
186
|
+
recent_counts = tuple(entry.recent_change_count for entry in file_counts)
|
|
187
|
+
file_metrics = tuple(
|
|
188
|
+
StructuralFileMetric(
|
|
189
|
+
path=entry.path,
|
|
190
|
+
change_count=entry.change_count,
|
|
191
|
+
percentile=_percentile(entry.change_count, change_counts),
|
|
192
|
+
recent_percentile=_percentile(entry.recent_change_count, recent_counts),
|
|
193
|
+
confidence=confidence,
|
|
194
|
+
)
|
|
195
|
+
for entry in file_counts
|
|
196
|
+
if _percentile(entry.change_count, change_counts) >= config.hotspot_percentile
|
|
197
|
+
)
|
|
198
|
+
by_path = {entry.path: entry.change_count for entry in file_counts}
|
|
199
|
+
edge_metrics: list[StructuralEdgeMetric] = []
|
|
200
|
+
for entry in edge_counts:
|
|
201
|
+
left_count = by_path[entry.left_path]
|
|
202
|
+
right_count = by_path[entry.right_path]
|
|
203
|
+
subset_ratio = entry.co_change_count / min(left_count, right_count)
|
|
204
|
+
left_conditional = entry.co_change_count / left_count
|
|
205
|
+
right_conditional = entry.co_change_count / right_count
|
|
206
|
+
union = left_count + right_count - entry.co_change_count
|
|
207
|
+
jaccard = entry.co_change_count / union if union else 0.0
|
|
208
|
+
hub_frequency = max(left_count, right_count) / summary.eligible_commits
|
|
209
|
+
hub_penalty = max(0.0, 1.0 - hub_frequency)
|
|
210
|
+
if (
|
|
211
|
+
entry.co_change_count < config.minimum_co_change_count
|
|
212
|
+
or subset_ratio < config.minimum_subset_ratio
|
|
213
|
+
or jaccard < config.minimum_jaccard
|
|
214
|
+
or hub_penalty < config.minimum_hub_penalty
|
|
215
|
+
):
|
|
216
|
+
continue
|
|
217
|
+
edge_metrics.append(
|
|
218
|
+
StructuralEdgeMetric(
|
|
219
|
+
left_path=entry.left_path,
|
|
220
|
+
right_path=entry.right_path,
|
|
221
|
+
co_change_count=entry.co_change_count,
|
|
222
|
+
subset_ratio=round(subset_ratio, 6),
|
|
223
|
+
left_conditional=round(left_conditional, 6),
|
|
224
|
+
right_conditional=round(right_conditional, 6),
|
|
225
|
+
jaccard=round(jaccard, 6),
|
|
226
|
+
hub_penalty=round(hub_penalty, 6),
|
|
227
|
+
cross_module=_module(entry.left_path) != _module(entry.right_path),
|
|
228
|
+
confidence=confidence,
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
edge_metrics.sort(
|
|
232
|
+
key=lambda value: (
|
|
233
|
+
-value.co_change_count,
|
|
234
|
+
-value.jaccard,
|
|
235
|
+
value.left_path,
|
|
236
|
+
value.right_path,
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
materialization_gaps = ("STRUCTURAL_CONTEXT_CAPPED",) if summary.capped_commits else ()
|
|
240
|
+
return StructuralMaterialization(
|
|
241
|
+
baseline_id=baseline_id,
|
|
242
|
+
file_metrics=tuple(
|
|
243
|
+
sorted(file_metrics, key=lambda value: (-value.percentile, value.path))
|
|
244
|
+
),
|
|
245
|
+
edge_metrics=tuple(edge_metrics),
|
|
246
|
+
confidence=confidence,
|
|
247
|
+
gaps=materialization_gaps,
|
|
248
|
+
limitations=_LIMITATIONS,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _eligible_paths(commit: ContributionCommit) -> tuple[str, ...]:
|
|
253
|
+
if (
|
|
254
|
+
commit.paths
|
|
255
|
+
and commit.binary_files >= len(commit.paths)
|
|
256
|
+
and commit.insertions + commit.deletions == 0
|
|
257
|
+
):
|
|
258
|
+
return ()
|
|
259
|
+
return tuple(
|
|
260
|
+
sorted(
|
|
261
|
+
{
|
|
262
|
+
normalized
|
|
263
|
+
for path in commit.paths
|
|
264
|
+
if (normalized := path.replace("\\", "/").strip("/"))
|
|
265
|
+
and not is_generated_path(normalized)
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _occurred_at(commit: ContributionCommit) -> datetime:
|
|
272
|
+
return commit.period_at or commit.authored_at
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _module(path: str) -> str:
|
|
276
|
+
normalized = path.strip("/")
|
|
277
|
+
return normalized.split("/", maxsplit=1)[0] if "/" in normalized else "root"
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _edge_key(edge: tuple[str, str]) -> str:
|
|
281
|
+
return f"edge:{edge[0]}\u0000{edge[1]}"
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _percentile(value: int, values: tuple[int, ...]) -> float:
|
|
285
|
+
if not values:
|
|
286
|
+
return 0.0
|
|
287
|
+
return round(sum(candidate <= value for candidate in values) / len(values), 6)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _confidence(eligible_commits: int, minimum: int) -> str:
|
|
291
|
+
return "HIGH" if eligible_commits >= max(10, minimum * 3) else "MEDIUM"
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _baseline_id(
|
|
295
|
+
hashes: list[str],
|
|
296
|
+
cutoff: datetime,
|
|
297
|
+
config: StructuralRuleConfig,
|
|
298
|
+
file_counts: tuple[StructuralFileCount, ...],
|
|
299
|
+
edge_counts: tuple[StructuralEdgeCount, ...],
|
|
300
|
+
identity_context: dict[str, str | None],
|
|
301
|
+
) -> str:
|
|
302
|
+
payload = {
|
|
303
|
+
"cutoff": cutoff.isoformat(),
|
|
304
|
+
"config": {
|
|
305
|
+
**asdict(config),
|
|
306
|
+
"time_strategy": config.time_strategy.value,
|
|
307
|
+
},
|
|
308
|
+
"factRuleVersion": STRUCTURAL_FACT_RULE_VERSION,
|
|
309
|
+
"metricRuleVersion": STRUCTURAL_METRIC_RULE_VERSION,
|
|
310
|
+
"thresholdVersion": STRUCTURAL_THRESHOLD_VERSION,
|
|
311
|
+
"identityContext": identity_context,
|
|
312
|
+
"commits": hashes,
|
|
313
|
+
"files": [asdict(value) for value in file_counts],
|
|
314
|
+
"edges": [asdict(value) for value in edge_counts],
|
|
315
|
+
}
|
|
316
|
+
canonical = json.dumps(payload, ensure_ascii=True, sort_keys=True, separators=(",", ":"))
|
|
317
|
+
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
from itertools import combinations
|
|
5
|
+
from typing import Any, TypedDict
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.domain.models.contribution import ContributionCommit
|
|
8
|
+
from git_contribution_analyzer.domain.services.contribution_rules import is_generated_path
|
|
9
|
+
|
|
10
|
+
STRUCTURAL_SIGNAL_RULE_VERSION = "structural-signals-v1"
|
|
11
|
+
MIN_CO_CHANGE_COMMITS = 2
|
|
12
|
+
MIN_HOTSPOT_COMMITS = 2
|
|
13
|
+
MAX_SIGNAL_ENTRIES = 20
|
|
14
|
+
MAX_COMMIT_HASHES = 50
|
|
15
|
+
|
|
16
|
+
_LIMITATIONS = (
|
|
17
|
+
"Repeated co-change indicates structural association, not a runtime dependency.",
|
|
18
|
+
"Hotspots indicate change concentration, not code quality or individual performance.",
|
|
19
|
+
"Merge commits, generated paths, binary-only changes, and duplicate patches are excluded.",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class _Coupling(TypedDict):
|
|
24
|
+
leftPath: str
|
|
25
|
+
rightPath: str
|
|
26
|
+
coChangeCommits: int
|
|
27
|
+
confidence: str
|
|
28
|
+
commitHashes: list[str]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _Hotspot(TypedDict):
|
|
32
|
+
path: str
|
|
33
|
+
changeCommits: int
|
|
34
|
+
coupledFiles: int
|
|
35
|
+
coChangeCommits: int
|
|
36
|
+
score: int
|
|
37
|
+
commitHashes: list[str]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def build_structural_signals(
|
|
41
|
+
commits: tuple[ContributionCommit, ...],
|
|
42
|
+
) -> dict[str, Any]:
|
|
43
|
+
file_commits: defaultdict[str, set[str]] = defaultdict(set)
|
|
44
|
+
edge_commits: defaultdict[tuple[str, str], set[str]] = defaultdict(set)
|
|
45
|
+
analyzed_commits = 0
|
|
46
|
+
seen_patches: set[str] = set()
|
|
47
|
+
|
|
48
|
+
for commit in sorted(commits, key=lambda value: (value.authored_at, value.hash)):
|
|
49
|
+
if commit.merge:
|
|
50
|
+
continue
|
|
51
|
+
patch_key = commit.patch_id or commit.hash
|
|
52
|
+
if patch_key in seen_patches:
|
|
53
|
+
continue
|
|
54
|
+
seen_patches.add(patch_key)
|
|
55
|
+
paths = _eligible_paths(commit)
|
|
56
|
+
if not paths:
|
|
57
|
+
continue
|
|
58
|
+
analyzed_commits += 1
|
|
59
|
+
for path in paths:
|
|
60
|
+
file_commits[path].add(commit.hash)
|
|
61
|
+
for left_path, right_path in combinations(paths, 2):
|
|
62
|
+
edge_commits[(left_path, right_path)].add(commit.hash)
|
|
63
|
+
|
|
64
|
+
strong_edges = {
|
|
65
|
+
edge: hashes
|
|
66
|
+
for edge, hashes in edge_commits.items()
|
|
67
|
+
if len(hashes) >= MIN_CO_CHANGE_COMMITS
|
|
68
|
+
}
|
|
69
|
+
couplings: list[_Coupling] = [
|
|
70
|
+
{
|
|
71
|
+
"leftPath": left_path,
|
|
72
|
+
"rightPath": right_path,
|
|
73
|
+
"coChangeCommits": len(hashes),
|
|
74
|
+
"confidence": _coupling_confidence(len(hashes)),
|
|
75
|
+
"commitHashes": sorted(hashes)[:MAX_COMMIT_HASHES],
|
|
76
|
+
}
|
|
77
|
+
for (left_path, right_path), hashes in strong_edges.items()
|
|
78
|
+
]
|
|
79
|
+
couplings.sort(
|
|
80
|
+
key=lambda value: (
|
|
81
|
+
-value["coChangeCommits"],
|
|
82
|
+
value["leftPath"],
|
|
83
|
+
value["rightPath"],
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
neighbors: defaultdict[str, set[str]] = defaultdict(set)
|
|
88
|
+
coupled_commits: defaultdict[str, int] = defaultdict(int)
|
|
89
|
+
for (left_path, right_path), hashes in strong_edges.items():
|
|
90
|
+
neighbors[left_path].add(right_path)
|
|
91
|
+
neighbors[right_path].add(left_path)
|
|
92
|
+
coupled_commits[left_path] += len(hashes)
|
|
93
|
+
coupled_commits[right_path] += len(hashes)
|
|
94
|
+
|
|
95
|
+
hotspots: list[_Hotspot] = [
|
|
96
|
+
{
|
|
97
|
+
"path": path,
|
|
98
|
+
"changeCommits": len(hashes),
|
|
99
|
+
"coupledFiles": len(neighbors[path]),
|
|
100
|
+
"coChangeCommits": coupled_commits[path],
|
|
101
|
+
"score": len(hashes) + coupled_commits[path],
|
|
102
|
+
"commitHashes": sorted(hashes)[:MAX_COMMIT_HASHES],
|
|
103
|
+
}
|
|
104
|
+
for path, hashes in file_commits.items()
|
|
105
|
+
if len(hashes) >= MIN_HOTSPOT_COMMITS
|
|
106
|
+
]
|
|
107
|
+
hotspots.sort(
|
|
108
|
+
key=lambda value: (
|
|
109
|
+
-value["score"],
|
|
110
|
+
-value["changeCommits"],
|
|
111
|
+
value["path"],
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
"ruleVersion": STRUCTURAL_SIGNAL_RULE_VERSION,
|
|
117
|
+
"summary": {
|
|
118
|
+
"analyzedCommits": analyzed_commits,
|
|
119
|
+
"analyzedFiles": len(file_commits),
|
|
120
|
+
"coupledPairs": len(couplings),
|
|
121
|
+
"hotspots": len(hotspots),
|
|
122
|
+
},
|
|
123
|
+
"couplings": couplings[:MAX_SIGNAL_ENTRIES],
|
|
124
|
+
"hotspots": hotspots[:MAX_SIGNAL_ENTRIES],
|
|
125
|
+
"limitations": list(_LIMITATIONS),
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _eligible_paths(commit: ContributionCommit) -> tuple[str, ...]:
|
|
130
|
+
if (
|
|
131
|
+
commit.paths
|
|
132
|
+
and commit.binary_files >= len(commit.paths)
|
|
133
|
+
and commit.insertions + commit.deletions == 0
|
|
134
|
+
):
|
|
135
|
+
return ()
|
|
136
|
+
return tuple(
|
|
137
|
+
sorted(
|
|
138
|
+
{
|
|
139
|
+
normalized
|
|
140
|
+
for path in commit.paths
|
|
141
|
+
if (normalized := path.replace("\\", "/").strip("/"))
|
|
142
|
+
and not is_generated_path(normalized)
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _coupling_confidence(co_change_commits: int) -> str:
|
|
149
|
+
if co_change_commits >= 3:
|
|
150
|
+
return "HIGH"
|
|
151
|
+
return "MEDIUM"
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from git_contribution_analyzer.domain.models.contribution import (
|
|
4
|
+
ContributionCommit,
|
|
5
|
+
ContributionItem,
|
|
6
|
+
)
|
|
7
|
+
from git_contribution_analyzer.domain.models.work_assessment import (
|
|
8
|
+
CompletionBucket,
|
|
9
|
+
SizeBand,
|
|
10
|
+
WorkItemSizeAssessment,
|
|
11
|
+
WorkloadBaseline,
|
|
12
|
+
)
|
|
13
|
+
from git_contribution_analyzer.domain.services.contribution_rules import is_generated_path
|
|
14
|
+
|
|
15
|
+
WORKLOAD_RULE_VERSION = "workload-rules-v1"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def classify_completion(item: ContributionItem) -> CompletionBucket:
|
|
19
|
+
if item.commits and all(commit.merge for commit in item.commits):
|
|
20
|
+
return CompletionBucket.INTEGRATION
|
|
21
|
+
statuses = {commit.delivery_status for commit in item.commits}
|
|
22
|
+
if "REVERTED" in statuses or any(
|
|
23
|
+
commit.commit_type == "REVERT" for commit in item.commits
|
|
24
|
+
):
|
|
25
|
+
return CompletionBucket.REWORK
|
|
26
|
+
if statuses and statuses <= {"AUTHORED_ONLY"}:
|
|
27
|
+
return CompletionBucket.PENDING
|
|
28
|
+
if statuses.intersection({"LANDED", "RELEASED"}):
|
|
29
|
+
return CompletionBucket.COMPLETED
|
|
30
|
+
return CompletionBucket.PENDING
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def assess_item_size(
|
|
34
|
+
item: ContributionItem,
|
|
35
|
+
*,
|
|
36
|
+
baseline: WorkloadBaseline | None = None,
|
|
37
|
+
) -> WorkItemSizeAssessment:
|
|
38
|
+
churn, effective_paths, excluded = _effective_metrics(item)
|
|
39
|
+
modules = {
|
|
40
|
+
path.replace("\\", "/").strip("/").split("/", maxsplit=1)[0]
|
|
41
|
+
if "/" in path.replace("\\", "/").strip("/")
|
|
42
|
+
else "root"
|
|
43
|
+
for path in effective_paths
|
|
44
|
+
}
|
|
45
|
+
use_repository_baseline = baseline is not None and baseline.sample_size >= 20
|
|
46
|
+
band = (
|
|
47
|
+
_repository_band(churn, len(effective_paths), len(modules), baseline)
|
|
48
|
+
if use_repository_baseline and baseline is not None
|
|
49
|
+
else _static_band(churn, len(effective_paths), len(modules))
|
|
50
|
+
)
|
|
51
|
+
return WorkItemSizeAssessment(
|
|
52
|
+
band=band,
|
|
53
|
+
effective_files=len(effective_paths),
|
|
54
|
+
effective_churn=churn,
|
|
55
|
+
module_span=len(modules),
|
|
56
|
+
baseline_sample_size=baseline.sample_size if baseline is not None else 0,
|
|
57
|
+
baseline_mode="REPOSITORY" if use_repository_baseline else "STATIC_FALLBACK",
|
|
58
|
+
rule_version=WORKLOAD_RULE_VERSION,
|
|
59
|
+
evidence_ids=item.evidence_ids,
|
|
60
|
+
excluded_changes=excluded,
|
|
61
|
+
confidence="HIGH" if use_repository_baseline else "MEDIUM",
|
|
62
|
+
gaps=() if use_repository_baseline else ("INSUFFICIENT_REPOSITORY_BASELINE",),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def build_workload_baseline(items: tuple[ContributionItem, ...]) -> WorkloadBaseline:
|
|
67
|
+
metrics = [_effective_metrics(item) for item in items]
|
|
68
|
+
churn = sorted(value[0] for value in metrics)
|
|
69
|
+
files = sorted(len(value[1]) for value in metrics)
|
|
70
|
+
modules = sorted(
|
|
71
|
+
len(
|
|
72
|
+
{
|
|
73
|
+
path.replace("\\", "/").strip("/").split("/", maxsplit=1)[0]
|
|
74
|
+
if "/" in path.replace("\\", "/").strip("/")
|
|
75
|
+
else "root"
|
|
76
|
+
for path in value[1]
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
for value in metrics
|
|
80
|
+
)
|
|
81
|
+
return WorkloadBaseline(
|
|
82
|
+
sample_size=len(items),
|
|
83
|
+
churn_percentiles=_percentiles(churn),
|
|
84
|
+
file_percentiles=_percentiles(files),
|
|
85
|
+
module_percentiles=_percentiles(modules),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _effective_metrics(
|
|
90
|
+
item: ContributionItem,
|
|
91
|
+
) -> tuple[int, set[str], tuple[str, ...]]:
|
|
92
|
+
commits, duplicate_count = _unique_effective_commits(item.commits)
|
|
93
|
+
effective_paths: set[str] = set()
|
|
94
|
+
churn = 0
|
|
95
|
+
excluded: list[str] = []
|
|
96
|
+
for commit in commits:
|
|
97
|
+
if commit.merge:
|
|
98
|
+
excluded.append(f"MERGE:{commit.hash}")
|
|
99
|
+
continue
|
|
100
|
+
eligible_paths = tuple(path for path in commit.paths if not is_generated_path(path))
|
|
101
|
+
if not eligible_paths:
|
|
102
|
+
excluded.append(f"NOISE_ONLY:{commit.hash}")
|
|
103
|
+
continue
|
|
104
|
+
if commit.binary_files >= len(commit.paths):
|
|
105
|
+
excluded.append(f"BINARY_ONLY:{commit.hash}")
|
|
106
|
+
continue
|
|
107
|
+
effective_paths.update(eligible_paths)
|
|
108
|
+
insertions = (
|
|
109
|
+
commit.effective_insertions
|
|
110
|
+
if commit.effective_insertions is not None
|
|
111
|
+
else commit.insertions
|
|
112
|
+
)
|
|
113
|
+
deletions = (
|
|
114
|
+
commit.effective_deletions
|
|
115
|
+
if commit.effective_deletions is not None
|
|
116
|
+
else commit.deletions
|
|
117
|
+
)
|
|
118
|
+
churn += insertions + deletions
|
|
119
|
+
if duplicate_count:
|
|
120
|
+
excluded.append(f"DUPLICATE_PATCHES:{duplicate_count}")
|
|
121
|
+
return churn, effective_paths, tuple(sorted(excluded))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _unique_effective_commits(
|
|
125
|
+
commits: tuple[ContributionCommit, ...],
|
|
126
|
+
) -> tuple[tuple[ContributionCommit, ...], int]:
|
|
127
|
+
seen: set[str] = set()
|
|
128
|
+
result: list[ContributionCommit] = []
|
|
129
|
+
duplicates = 0
|
|
130
|
+
for commit in sorted(commits, key=lambda value: (value.authored_at, value.hash)):
|
|
131
|
+
key = commit.patch_id or commit.hash
|
|
132
|
+
if key in seen:
|
|
133
|
+
duplicates += 1
|
|
134
|
+
continue
|
|
135
|
+
seen.add(key)
|
|
136
|
+
result.append(commit)
|
|
137
|
+
return tuple(result), duplicates
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _static_band(churn: int, files: int, modules: int) -> SizeBand:
|
|
141
|
+
if churn > 1000 or files > 30 or modules > 4:
|
|
142
|
+
return SizeBand.XLARGE
|
|
143
|
+
if churn > 300 or files > 10 or modules > 2:
|
|
144
|
+
return SizeBand.LARGE
|
|
145
|
+
if churn > 80 or files > 3 or modules > 1:
|
|
146
|
+
return SizeBand.MEDIUM
|
|
147
|
+
return SizeBand.SMALL
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _repository_band(
|
|
151
|
+
churn: int,
|
|
152
|
+
files: int,
|
|
153
|
+
modules: int,
|
|
154
|
+
baseline: WorkloadBaseline,
|
|
155
|
+
) -> SizeBand:
|
|
156
|
+
candidates = (
|
|
157
|
+
_percentile_band(churn, baseline.churn_percentiles),
|
|
158
|
+
_percentile_band(files, baseline.file_percentiles),
|
|
159
|
+
_percentile_band(modules, baseline.module_percentiles),
|
|
160
|
+
)
|
|
161
|
+
order = {band: index for index, band in enumerate(SizeBand)}
|
|
162
|
+
band = max(candidates, key=lambda value: order[value])
|
|
163
|
+
absolute = _static_band(churn, files, modules)
|
|
164
|
+
return min((band, absolute), key=lambda value: order[value])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _percentile_band(value: int, thresholds: tuple[int, int, int]) -> SizeBand:
|
|
168
|
+
if value <= thresholds[0]:
|
|
169
|
+
return SizeBand.SMALL
|
|
170
|
+
if value <= thresholds[1]:
|
|
171
|
+
return SizeBand.MEDIUM
|
|
172
|
+
if value <= thresholds[2]:
|
|
173
|
+
return SizeBand.LARGE
|
|
174
|
+
return SizeBand.XLARGE
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _percentiles(values: list[int]) -> tuple[int, int, int]:
|
|
178
|
+
if not values:
|
|
179
|
+
return (0, 0, 0)
|
|
180
|
+
|
|
181
|
+
def nearest_rank(percent: float) -> int:
|
|
182
|
+
index = max(0, min(len(values) - 1, round((len(values) - 1) * percent)))
|
|
183
|
+
return values[index]
|
|
184
|
+
|
|
185
|
+
return nearest_rank(0.50), nearest_rank(0.75), nearest_rank(0.90)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Packaged GUI resources."""
|