Skip to content

Commit f6b8382

Browse files
authored
Merge pull request #13 from n0rfas/time_for_weeks
added new design ui
2 parents 03860a1 + 0f06472 commit f6b8382

File tree

12 files changed

+621
-317
lines changed

12 files changed

+621
-317
lines changed
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,57 @@
11
from collections import Counter, defaultdict
22
from dataclasses import dataclass
3-
from datetime import date
4-
from enum import Enum
5-
from typing import Dict
3+
from typing import Dict, List
64

75
from git_analytics.entities import AnalyticsCommit, AnalyticsResult
6+
from git_analytics.helpers import get_number_week
87
from git_analytics.interfaces import CommitAnalyzer
98

109

11-
class CommitType(Enum):
12-
FEATURE = "feature"
13-
FIX = "fix"
14-
DOCS = "docs"
15-
STYLE = "style"
16-
REFACTOR = "refactor"
17-
TEST = "test"
18-
CHORE = "chore"
19-
WIP = "wip"
20-
MERGE = "merge"
21-
UNKNOWN = "unknown"
22-
23-
2410
@dataclass
2511
class Result(AnalyticsResult):
26-
timeseries: Dict[date, Dict[CommitType, int]]
27-
total_counter: Dict[CommitType, int]
28-
author_total_counter: Dict[str, Dict[CommitType, int]]
12+
commit_type_by_week: Dict[str, Dict[str, int]]
13+
commit_type_counter: Dict[str, int]
14+
author_commit_type_by_week: Dict[str, Dict[str, Dict[str, int]]]
15+
author_commit_type_counter: Dict[str, Dict[str, int]]
2916

3017

31-
TYPE_COMMIT_LIST: tuple = tuple(ct.value for ct in CommitType)
18+
LIST_OF_TYPE_COMMIT: List[str] = ["feature", "fix", "docs", "style", "refactor", "test", "chore", "wip", "merge"]
3219

3320

34-
def _get_type_list(commit_message: str):
35-
result = [tag for tag in TYPE_COMMIT_LIST if tag in commit_message.lower()]
21+
def _get_type_list(commit_message: str) -> List[str]:
22+
result = [tag for tag in LIST_OF_TYPE_COMMIT if tag in commit_message.lower()]
3623
if result:
3724
return result
38-
return [CommitType.UNKNOWN.value]
25+
return ["unknown"]
3926

4027

4128
class CommitTypeAnalyzer(CommitAnalyzer):
4229
name = "commit_type"
4330

4431
def __init__(self) -> None:
45-
self._by_date: Dict[date, Counter] = defaultdict(Counter)
46-
self._total_counter: Counter = Counter()
47-
self._author_total_counter: Dict[str, Counter] = defaultdict(Counter)
32+
self._commit_type_by_week: Dict[str, Counter] = defaultdict(Counter)
33+
self._commit_type_counter: Counter = Counter()
34+
self._author_commit_type_by_week: Dict[str, Dict[str, Counter]] = defaultdict(lambda: defaultdict(Counter))
35+
self._author_commit_type_counter: Dict[str, Counter] = defaultdict(Counter)
4836

4937
def process(self, commit: AnalyticsCommit) -> None:
50-
commit_date = commit.committed_datetime.date()
38+
week_number = get_number_week(commit.committed_datetime)
5139
commit_types = _get_type_list(commit.message)
5240
for commit_type in commit_types:
53-
self._by_date[commit_date][commit_type] += 1
54-
self._total_counter[commit_type] += 1
55-
self._author_total_counter[commit.commit_author][commit_type] += 1
41+
self._commit_type_by_week[week_number][commit_type] += 1
42+
self._commit_type_counter[commit_type] += 1
43+
self._author_commit_type_by_week[commit.commit_author][week_number][commit_type] += 1
44+
self._author_commit_type_counter[commit.commit_author][commit_type] += 1
5645

5746
def result(self) -> Result:
5847
return Result(
59-
timeseries={dt: dict(counter) for dt, counter in self._by_date.items()},
60-
author_total_counter={author: dict(counter) for author, counter in self._author_total_counter.items()},
61-
total_counter=dict(self._total_counter),
48+
commit_type_by_week={wn: dict(sorted(c.items())) for wn, c in sorted(self._commit_type_by_week.items())},
49+
commit_type_counter=dict(sorted(self._commit_type_counter.items())),
50+
author_commit_type_by_week={
51+
a: {wn: dict(sorted(c.items())) for wn, c in sorted(weeks.items())}
52+
for a, weeks in sorted(self._author_commit_type_by_week.items())
53+
},
54+
author_commit_type_counter={
55+
a: dict(sorted(c.items())) for a, c in sorted(self._author_commit_type_counter.items())
56+
},
6257
)

git_analytics/analyzers/language_statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_file_extension(file_path: str) -> str:
2323
filename_parts = filename.split(".")
2424
if len(filename_parts) == 1 or filename_parts[0] == "":
2525
return "no_extension"
26-
return filename_parts[-1].lower()
26+
return filename_parts[-1].lower().replace("}", "")
2727

2828

2929
class LanguageAnalyzer(CommitAnalyzer):

git_analytics/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44

55
def get_number_week(dt: Union[date, datetime]) -> str:
6-
return f"w{dt.isocalendar()[1]:02d}"
6+
year = dt.year
7+
week = dt.isocalendar()[1]
8+
return f"{year}-W{week:02d}" # ISO-8601 week number

git_analytics/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from wsgiref.simple_server import make_server
23

34
from git import InvalidGitRepositoryError, Repo
@@ -28,7 +29,8 @@ def make_analyzers():
2829

2930
def run():
3031
try:
31-
repo = Repo()
32+
path_repo = os.getenv("PATH_REPO", ".")
33+
repo = Repo(path_repo)
3234
name_branch = repo.active_branch.name
3335
except InvalidGitRepositoryError:
3436
print("Error: Current directory is not a git repository.")

git_analytics/static/css/bootstrap-icons.min.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
176 KB
Binary file not shown.
131 KB
Binary file not shown.

0 commit comments

Comments
 (0)