You've already forked wakapi-readme-stats
graph redrawn
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import Dict
|
||||
|
||||
from numpy import arange, array, add, amax
|
||||
from numpy import arange, array, add, amax, zeros
|
||||
import matplotlib.patches as mpatches
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@@ -9,6 +9,7 @@ from manager_download import DownloadManager as DM
|
||||
|
||||
MAX_LANGUAGES = 5 # Number of top languages to add to chart, for each year quarter
|
||||
GRAPH_PATH = "assets/bar_graph.png" # Chart saving path.
|
||||
GRAPH_Y_ZOOM = 1.3
|
||||
|
||||
|
||||
async def create_loc_graph(yearly_data: Dict, save_path: str):
|
||||
@@ -27,26 +28,28 @@ async def create_loc_graph(yearly_data: Dict, save_path: str):
|
||||
languages_all_loc = dict()
|
||||
for i, y in enumerate(sorted(yearly_data.keys())):
|
||||
for q in yearly_data[y].keys():
|
||||
langs = sorted(yearly_data[y][q].keys(), key=lambda n: yearly_data[y][q][n], reverse=True)[0:MAX_LANGUAGES]
|
||||
langs = sorted(yearly_data[y][q].keys(), key=lambda n: yearly_data[y][q][n]["add"] + yearly_data[y][q][n]["del"], reverse=True)[0:MAX_LANGUAGES]
|
||||
|
||||
for lang in langs:
|
||||
if lang not in languages_all_loc:
|
||||
languages_all_loc[lang] = array([[0] * years] * 4)
|
||||
languages_all_loc[lang][q - 1][i] = yearly_data[y][q][lang]
|
||||
languages_all_loc[lang] = zeros((years, 4, 2), dtype=int)
|
||||
languages_all_loc[lang][i][q - 1] = array([yearly_data[y][q][lang]["add"], yearly_data[y][q][lang]["del"]])
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_axes([0, 0, 1.5, 1])
|
||||
|
||||
language_handles = []
|
||||
cumulative = array([[0] * years] * 4)
|
||||
cumulative = zeros((years, 4, 2), dtype=int)
|
||||
|
||||
for key, value in languages_all_loc.items():
|
||||
color = colors[key]["color"] if colors[key]["color"] is not None else "w"
|
||||
language_handles += [mpatches.Patch(color=color, label=key)]
|
||||
|
||||
for quarter in range(4):
|
||||
ax.bar(year_indexes + quarter * 0.21, value[quarter], 0.2, bottom=cumulative[quarter], color=color)
|
||||
cumulative[quarter] = add(cumulative[quarter], value[quarter])
|
||||
ax.bar(year_indexes + quarter * 0.21, value[:, quarter][:, 0], 0.2, bottom=cumulative[:, quarter][:, 0], color=color)
|
||||
ax.bar(year_indexes + quarter * 0.21, -value[:, quarter][:, 1], 0.2, bottom=-cumulative[:, quarter][:, 1], color=color)
|
||||
cumulative[:, quarter] = add(cumulative[:, quarter], value[:, quarter])
|
||||
ax.axhline(y=0.5, lw=0.5, snap=True, color="k")
|
||||
|
||||
ax.set_ylabel("LOC added", fontdict=dict(weight="bold"))
|
||||
ax.set_xticks(array([arange(i, i + 0.84, step=0.21) for i in year_indexes]).flatten(), labels=["Q1", "Q2", "Q3", "Q4"] * years)
|
||||
@@ -62,6 +65,6 @@ async def create_loc_graph(yearly_data: Dict, save_path: str):
|
||||
ax.spines["top"].set_visible(False)
|
||||
ax.spines["right"].set_visible(False)
|
||||
|
||||
plt.ylim(0, 1.05 * amax(cumulative))
|
||||
plt.ylim(top=GRAPH_Y_ZOOM * amax(cumulative[:, 0]), bottom=-GRAPH_Y_ZOOM * amax(cumulative[:, 1]))
|
||||
plt.savefig(save_path, bbox_inches="tight")
|
||||
plt.close(fig)
|
||||
|
||||
@@ -148,7 +148,7 @@ async def get_stats() -> str:
|
||||
|
||||
if EM.SHOW_LINES_OF_CODE:
|
||||
DBM.i("Adding lines of code info...")
|
||||
total_loc = sum([yearly_data[y][q][d] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()])
|
||||
total_loc = sum([yearly_data[y][q][d]["add"] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()])
|
||||
data = f"{intword(total_loc)} {LM.t('Lines of code')}"
|
||||
stats += f")}-{quote(data)}-blue)\n\n"
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from manager_debug import DebugManager as DBM
|
||||
async def calculate_yearly_commit_data(repositories: Dict) -> Dict:
|
||||
"""
|
||||
Calculate commit data by years.
|
||||
Commit data includes difference between contribution additions and deletions in each quarter of each recorded year.
|
||||
Commit data includes contribution additions and deletions in each quarter of each recorded year.
|
||||
|
||||
:param repositories: user repositories info dictionary.
|
||||
:returns: Commit quarter yearly data dictionary.
|
||||
@@ -21,7 +21,7 @@ async def calculate_yearly_commit_data(repositories: Dict) -> Dict:
|
||||
total = len(repositories["data"]["user"]["repositories"]["nodes"])
|
||||
for ind, repo in enumerate(repositories["data"]["user"]["repositories"]["nodes"]):
|
||||
if repo["name"] not in EM.IGNORED_REPOS:
|
||||
repo_name = "private" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}"
|
||||
repo_name = "[private]" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}"
|
||||
DBM.i(f"\t{ind + 1}/{total} Retrieving repo: {repo_name}")
|
||||
await update_yearly_data_with_commit_stats(repo, yearly_data)
|
||||
DBM.g("Yearly commit data calculated!")
|
||||
@@ -55,5 +55,6 @@ async def update_yearly_data_with_commit_stats(repo_details: Dict, yearly_data:
|
||||
if quarter not in yearly_data[curr_year]:
|
||||
yearly_data[curr_year][quarter] = dict()
|
||||
if repo_details["primaryLanguage"]["name"] not in yearly_data[curr_year][quarter]:
|
||||
yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] = 0
|
||||
yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] += commit["additions"] - commit["deletions"]
|
||||
yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] = {"add": 0, "del": 0}
|
||||
yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]]["add"] += commit["additions"]
|
||||
yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]]["del"] += commit["deletions"]
|
||||
|
||||
Reference in New Issue
Block a user