Skip to content

Commit

Permalink
Update GitStats (#62)
Browse files Browse the repository at this point in the history
Add collab repo count stat
  • Loading branch information
R055A committed Jul 30, 2024
1 parent b41f7f4 commit 4cd803b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ Generate daily updated visualizations of user and repository statistics from the
## Description of Statistical Terminology

| GitHub Statistics Term | Description |
|----------------|-------------|
| All-time GitHub contributions | Count of all contributions ([as defined by GitHub](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/viewing-contributions-on-your-profile)) to any and all repositories any time for a given user |
| Lines of code changes* | Sum of all code additions and deletions to all repositories contributed to for a user, measured by lines |
| Avg contributions [weighted]* | Average code changes per collaborative repository for a user [weighted relative to contributor count] |
| Repos contributed [% owned]* | Count of all repositories contributed to by a user [including percent of these owned by the user] |
| Repo views (as of YYYY-MM-DD)* | Sum of views to all repositories since created, if owned, or contributed to (from a given date) |
| Repo collaborators* | Sum of collaborator and contributor counts for all repositories contributed to or owned for a user |
| Repo forks* | Sum of all-time fork counts for all repositories contributed to or owned for a user |
| Repo stars* | Sum of all-time star counts for all repositories contributed to or owned for a user |
| # [+#] Implemented Languages* | Listed [and hidden] percentages of implemented languages relative to sizes of files contributed to |
| GitHub Statistics Term | Description |
|--------------------------------|----------------------------------------------------------------------------------------------------------------|
| All-time GitHub contributions | Count of all contributions ([as defined by GitHub](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/viewing-contributions-on-your-profile)) to any and all repositories any time for a given user |
| Lines of code changes* | Sum of all code additions and deletions to all repositories contributed to for a user, measured by lines |
| Avg contributions [weighted]* | Average code changes per collaborative repository for a user [weighted relative to contributor count] |
| Repos contributed [% collab]* | Count of all repositories contributed to by a user [including percent in collaboration with others] |
| Repo views (as of YYYY-MM-DD)* | Sum of views to all repositories since created, if owned, or contributed to (from a given date) |
| Repo collaborators* | Sum of collaborator and contributor counts for all repositories contributed to or owned for a user |
| Repo forks* | Sum of all-time fork counts for all repositories contributed to or owned for a user |
| Repo stars* | Sum of all-time star counts for all repositories contributed to or owned for a user |
| # [+#] Implemented Languages* | Listed [and hidden] percentages of implemented languages relative to sizes of files contributed to |

> \* Customisable as instructed in the :closed_lock_with_key: Options section below
Expand Down
4 changes: 2 additions & 2 deletions src/generate_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ async def generate_overview(self) -> None:
output = sub("{{ avg_contribution_percent }}", avg_contribution_percent, output)

num_repos = len(await self.__stats.repos)
num_owned_repos = len(await self.__stats.owned_repos)
num_collab_repos = len(await self.__stats.contributed_collab_repos)
repos = (
num_repos
if len(str(num_repos)) < TXT_SPACER_MAX_LEN
else add_unit(num_repos)
)
repos = f"{repos:,} [{'%g' % round(num_owned_repos / num_repos * 100, 1)}%]"
repos = f"{repos:,} [{'%g' % round(num_collab_repos / num_repos * 100, 1)}%]"
output = sub("{{ repos }}", repos, output)

collaborators_and_contributors = f"{await self.__stats.collaborators:,}"
Expand Down
28 changes: 23 additions & 5 deletions src/github_repo_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, environment_vars: EnvironmentVariables, session: ClientSessio
self._issues: Optional[int] = None
self._empty_repos: Optional[Set[str]] = None
self._collab_repos: Optional[Set[str]] = None
self._contributed_collab_repos: Optional[Set[str]] = None
self._is_fetch_rate_limit_exceeded: Optional[bool] = False

async def to_str(self) -> str:
Expand All @@ -72,6 +73,7 @@ async def to_str(self) -> str:
Forks: {await self.forks:,}
All-time contributions: {await self.total_contributions:,}
Repositories with contributions: {len(await self.repos):,}
Repositories in collaboration with at least one other user: {len(await self.contributed_collab_repos):,}
Lines of code added: {users_lines_changed[0]:,}
Lines of code deleted: {users_lines_changed[1]:,}
Total lines of code changed: {sum(users_lines_changed):,}
Expand Down Expand Up @@ -361,6 +363,17 @@ async def owned_repos(self) -> Set[str]:
)
return self._owned_repos

@property
async def contributed_collab_repos(self) -> Set[str]:
"""
:return: list of names of repos contributed to user in collaborations with at least one other
"""
if self._contributed_collab_repos is not None:
return self._contributed_collab_repos
await self.lines_changed
assert self._contributed_collab_repos is not None
return self._contributed_collab_repos

@property
async def total_contributions(self) -> int:
"""
Expand Down Expand Up @@ -412,7 +425,9 @@ async def lines_changed(self) -> Tuple[int, int]:
author_total_additions = 0
author_total_deletions = 0

repos = []
self._contributed_collab_repos = collab_repos.copy().union(
slave_status_repos.copy()
)

for repo in await self.repos:
if repo in self._empty_repos:
Expand Down Expand Up @@ -449,6 +464,10 @@ async def lines_changed(self) -> Tuple[int, int]:
author_total_additions += author_additions
author_total_deletions += author_deletions

# add repo if in collaboration with at least one other to list for comparing with total repo count
if other_authors_total_changes > 0:
self._contributed_collab_repos.add(repo)

# calculate average author's contributions to each repository with at least one other collaborator
if (
repo not in self.environment_vars.exclude_collab_repos
Expand All @@ -461,8 +480,9 @@ async def lines_changed(self) -> Tuple[int, int]:
and (
other_authors_total_changes > 0
or repo
in collab_repos
| slave_status_repos # either collaborators are ghosting or no show in repo
in collab_repos.union(
slave_status_repos
) # either collaborators are ghosting or no show in repo
)
):
repo_total_changes = (
Expand All @@ -484,8 +504,6 @@ async def lines_changed(self) -> Tuple[int, int]:
)
repo_total_changes_arr.append(repo_total_changes)

repos.append(repo)

if sum(author_contribution_percentages) > 0:
self._avg_percent = f"{(sum(author_contribution_percentages) / len(repo_total_changes_arr) * 100):0.2f}%"
self._avg_percent_weighted = f"{(sum(author_contribution_percentages_weighted) / len(repo_total_changes_arr) * 100):0.2f}%"
Expand Down
2 changes: 1 addition & 1 deletion src/templates/overview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4cd803b

Please sign in to comment.