Skip to content

Commit d221cf8

Browse files
committed
refactor: mini refactoring for backend
1 parent 61a7bbc commit d221cf8

29 files changed

Lines changed: 266 additions & 411 deletions

Pipfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

frontend/src/views/AuthorsView.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ async function load() {
2727
}
2828
}
2929
30-
/** New API: activity.authors_statistics is author -> stats; legacy: authors_statistics.authors */
30+
/** Root authors_statistics or author -> stats; legacy: activity / nested .authors */
3131
const authorsStats = computed(() => {
3232
const root = stats.value;
33-
const fromActivity = root?.activity?.authors_statistics;
34-
const legacy = root?.authors_statistics;
35-
if (fromActivity != null) {
36-
if (fromActivity.authors != null && typeof fromActivity.authors === "object") {
37-
return fromActivity.authors;
38-
}
39-
return fromActivity;
33+
const pick =
34+
root?.authors_statistics ??
35+
root?.activity?.authors_statistics;
36+
if (pick == null) {
37+
return {};
4038
}
41-
if (legacy?.authors != null) {
42-
return legacy.authors;
39+
if (pick.authors != null && typeof pick.authors === "object") {
40+
return pick.authors;
4341
}
44-
return {};
42+
return pick;
4543
});
4644
4745
/** Pie slices: commit count per author (desc). */

frontend/src/views/OverviewView.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ async function load() {
4343
}
4444
}
4545
46-
/** New API: activity.commits_summary; legacy: root commits_summary */
46+
/** Root commits_summary; legacy: activity.commits_summary */
4747
const commitsSummary = computed(() => {
4848
const root = stats.value;
49-
return root?.activity?.commits_summary ?? root?.commits_summary ?? {};
49+
return root?.commits_summary ?? root?.activity?.commits_summary ?? {};
5050
});
5151
5252
const commitTypeRaw = computed(() => {
5353
const root = stats.value;
54-
return (
55-
root?.activity?.commit_type ??
56-
root?.commit_type?.commit_type_by_week ??
57-
{}
58-
);
54+
const ct = root?.commit_type ?? root?.activity?.commit_type;
55+
if (!ct || typeof ct !== "object") {
56+
return {};
57+
}
58+
if (ct.commit_type_by_week && typeof ct.commit_type_by_week === "object") {
59+
return ct.commit_type_by_week;
60+
}
61+
return ct;
5962
});
6063
6164
const commitTypeWeeks = computed(() => {
@@ -75,10 +78,14 @@ const commitTypes = computed(() => {
7578
return orderedCommitTypes(typeSet);
7679
});
7780
78-
/** activity.derived.weekly_lines_history: week -> { extension -> line count } */
81+
/** Root weekly_lines_history; legacy: activity.derived.weekly_lines_history */
7982
const weeklyLinesHistory = computed(() => {
8083
const root = stats.value;
81-
return root?.activity?.derived?.weekly_lines_history ?? {};
84+
return (
85+
root?.weekly_lines_history ??
86+
root?.activity?.derived?.weekly_lines_history ??
87+
{}
88+
);
8289
});
8390
8491
const weeklyLinesWeeks = computed(() => Object.keys(weeklyLinesHistory.value).sort());
@@ -111,6 +118,7 @@ const weeklyLinesExtensions = computed(() =>
111118
const busFactorRaw = computed(() => {
112119
const root = stats.value;
113120
return (
121+
root?.bus_factor ??
114122
root?.risks?.bus_factor ??
115123
root?.post_data?.bus_factor ??
116124
root?.commits_summary?.post_data?.bus_factor
@@ -165,7 +173,7 @@ const codeChurn21dPercent = computed(() => {
165173
166174
const codeChurn21dRaw = computed(() => {
167175
const root = stats.value;
168-
return root?.activity?.code_churn_21d ?? root?.code_churn_21d ?? {};
176+
return root?.code_churn_21d ?? root?.activity?.code_churn_21d ?? {};
169177
});
170178
171179
const codeChurnAddedLines = computed(() => {
@@ -607,7 +615,7 @@ onUnmounted(() => {
607615
<span class="font-semibold">Lines of code by week</span>
608616
<div
609617
class="tooltip tooltip-right before:max-w-xs before:text-left before:whitespace-normal"
610-
data-tip="Stacked area: estimated lines per file extension at the end of each week (from activity.derived.weekly_lines_history)."
618+
data-tip="Stacked area: estimated lines per file extension at the end of each week (weekly_lines_history)."
611619
>
612620
<button
613621
type="button"
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# from .authors import AuthorsCollector
2-
# from .commit_type import CommitTypeCollector
3-
# from .summary import SummaryCollector
4-
# from .code_curn_21d import CodeChurnCollector
5-
# from .weekly_file_extensions import WeeklyFileExtensionsCollector
1+
from .authors import AuthorCommitsCounter
2+
from .commit_type import CommitTypeCollector
3+
from .summary import CommitsSummaryCollector
4+
from .code_churn import CodeChurnCollector
5+
from .weekly_file_extensions import WeeklyFileExtensionsCollector
66

7-
# __all__ = [
8-
# # "AuthorsCollector",
9-
# "CommitTypeCollector",
10-
# "SummaryCollector",
11-
# "CodeChurnCollector",
12-
# "WeeklyFileExtensionsCollector",
13-
# ]
7+
__all__ = [
8+
"AuthorCommitsCounter",
9+
"CommitTypeCollector",
10+
"CommitsSummaryCollector",
11+
"CodeChurnCollector",
12+
"WeeklyFileExtensionsCollector",
13+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Dict, List, Any, Optional
33
from abc import ABC, abstractmethod
44

5-
from git_analytics.engines.metrics import CommitContext
5+
from git_analytics.history import CommitContext
66

77

88
class WeeklyCollector(ABC):

git_analytics/collectors/authors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from git_analytics.engines.metrics import CommitContext
1+
from git_analytics.history import CommitContext
22

33

44
class AuthorCommitsCounter:
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33
from collections import defaultdict, deque
44
from datetime import datetime, timedelta, timezone
55

6-
from git_analytics.engines.metrics import CommitContext
6+
from git_analytics.history import CommitContext
77

88

99
class CodeChurnCollector:
1010
name = "code_churn_21d"
1111

1212
def __init__(
1313
self,
14-
reporting_days: int = 365,
1514
churn_days: int = 21,
16-
now: Optional[datetime] = None,
1715
) -> None:
18-
self._reporting_days = reporting_days
1916
self._churn_days = churn_days
20-
self._now = (now or datetime.now(timezone.utc)).astimezone(timezone.utc)
21-
22-
self._report_start = self._now - timedelta(days=reporting_days)
2317
self._churn_window_seconds = churn_days * 24 * 60 * 60
2418

19+
# Начало периода отчетности устанавливается динамически:
20+
# первый_коммит + churn_days
21+
self._report_start: Optional[datetime] = None
22+
self._first_commit_date: Optional[datetime] = None
23+
2524
# file_path -> normalized_line -> deque[birth_ts]
2625
self._live_lines: Dict[str, Dict[str, deque[int]]] = defaultdict(lambda: defaultdict(deque))
2726

@@ -38,6 +37,12 @@ def consume(self, ctx: CommitContext) -> None:
3837
parent = commit.parents[0]
3938
commit_dt = ctx.committed_datetime.astimezone(timezone.utc)
4039
commit_ts = int(commit_dt.timestamp())
40+
41+
# Устанавливаем период отчетности при первом коммите
42+
if self._first_commit_date is None:
43+
self._first_commit_date = commit_dt
44+
self._report_start = self._first_commit_date + timedelta(days=self._churn_days)
45+
4146
is_in_reporting_period = commit_dt >= self._report_start
4247

4348
diffs = parent.diff(commit, create_patch=True)

git_analytics/collectors/commit_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Dict
2-
from git_analytics.engines.metrics import CommitContext
3-
from .base import WeeklyCollector
2+
from git_analytics.history import CommitContext
3+
from ._base import WeeklyCollector
44

55

66
LIST_OF_TYPE_COMMIT: List[str] = ["feature", "fix", "docs", "style", "refactor", "test", "chore", "wip", "merge"]

git_analytics/collectors/summary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date
2-
from typing import Dict, Optional, Set
2+
from typing import Optional, Set
33

4-
from git_analytics.engines.metrics import CommitContext
4+
from git_analytics.history import CommitContext
55

66

77
class CommitsSummaryCollector:

git_analytics/collectors/weekly_file_extensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict
22
from pathlib import Path
3-
from git_analytics.engines.metrics import CommitContext
4-
from .base import WeeklyCollector
3+
from git_analytics.history import CommitContext
4+
from ._base import WeeklyCollector
55

66

77
def _get_file_extension(file_path: str) -> str:

0 commit comments

Comments
 (0)