mirror of
https://git.ari.lt/ari/forgejo-stats.git
synced 2024-11-09 11:02:37 +00:00
add a background
Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
parent
588a58d9ea
commit
c020c11787
1 changed files with 38 additions and 35 deletions
73
stats.py
73
stats.py
|
@ -76,7 +76,7 @@ def get_repositories() -> t.List[t.Dict[str, t.Any]]:
|
|||
|
||||
while True:
|
||||
response: requests.Response = requests.get(
|
||||
f"{BASE_URL}/users/{USERNAME}/repos?page={page}&limit=100"
|
||||
f"{BASE_URL}/users/{USERNAME}/repos?page={page}&limit=4"
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
|
@ -93,6 +93,7 @@ def get_repositories() -> t.List[t.Dict[str, t.Any]]:
|
|||
all_repos.append(repo)
|
||||
|
||||
page += 1
|
||||
break
|
||||
|
||||
return all_repos
|
||||
|
||||
|
@ -180,26 +181,29 @@ def plot_data(
|
|||
plt.style.use("dark_background")
|
||||
|
||||
# -*- Language statistics -*-
|
||||
print("Plotting languages...")
|
||||
|
||||
print(f"Plotting languages...")
|
||||
|
||||
sorted_languages: t.List[t.Tuple[str, int]] = sorted(
|
||||
language_stats.items(), key=lambda x: x[1], reverse=True
|
||||
)[: (7 * LANG_COLS)]
|
||||
sorted_languages = sorted(language_stats.items(), key=lambda x: x[1], reverse=True)[
|
||||
: 7 * LANG_COLS
|
||||
]
|
||||
languages, counts = zip(*sorted_languages)
|
||||
total: int = sum(counts)
|
||||
total = sum(counts)
|
||||
|
||||
fig_lang, ax_lang = plt.subplots(
|
||||
figsize=((10 / 3) * LANG_COLS, (2 / 3) * LANG_COLS)
|
||||
)
|
||||
fig_lang.patch.set_facecolor("#000000")
|
||||
fig_lang.patch.set_alpha(0.5)
|
||||
|
||||
cumulative_counts = np.cumsum([0] + list(counts[:-1]))
|
||||
|
||||
plt.figure(figsize=((10 / 3) * LANG_COLS, (2 / 3) * LANG_COLS))
|
||||
|
||||
for lang, count, cum_count in zip(languages, counts, cumulative_counts):
|
||||
color = language_colours.get(lang.lower(), "#CCCCCC")
|
||||
plt.barh(0, count, color=color, left=cum_count, edgecolor="white")
|
||||
ax_lang.barh(0, count, color=color, left=cum_count, edgecolor="white")
|
||||
|
||||
plt.axis("off")
|
||||
plt.title("Top Programming Languages by Usage", fontsize=14, color=COLOUR)
|
||||
plt.legend(
|
||||
ax_lang.axis("off")
|
||||
ax_lang.set_title("Top Programming Languages by Usage", fontsize=14, color=COLOUR)
|
||||
ax_lang.legend(
|
||||
handles=[
|
||||
plt.Rectangle(
|
||||
(0, 0), 1, 1, color=language_colours.get(lang.lower(), "#CCCCCC")
|
||||
|
@ -217,42 +221,41 @@ def plot_data(
|
|||
)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig("languages.png", transparent=True, dpi=DPI)
|
||||
plt.savefig("languages.png", dpi=DPI)
|
||||
print("Wrote languages.png")
|
||||
|
||||
# -*- Commit statistics -*-
|
||||
|
||||
print(f"Plotting commits...")
|
||||
print("Plotting commits...")
|
||||
|
||||
two_years_ago: datetime = datetime.now() - timedelta(days=(365.25 * COMMIT_YEARS))
|
||||
filtered_dates: t.Dict[str, int] = {
|
||||
two_years_ago = datetime.now() - timedelta(days=(365.25 * COMMIT_YEARS))
|
||||
filtered_dates = {
|
||||
date: count
|
||||
for date, count in commit_activity.items()
|
||||
if datetime.strptime(date, "%Y-%m-%d") >= two_years_ago
|
||||
}
|
||||
|
||||
dates: t.List[str] = sorted(filtered_dates.keys())
|
||||
counts: t.List[int] = [filtered_dates[date] for date in dates]
|
||||
dates: t.List[np.datetime64] = [np.datetime64(date) for date in dates]
|
||||
dates = sorted(filtered_dates.keys())
|
||||
counts = [filtered_dates[date] for date in dates]
|
||||
dates = [np.datetime64(date) for date in dates]
|
||||
|
||||
plt.figure(figsize=(16, 9))
|
||||
fig_commits, ax_commits = plt.subplots(figsize=(16, 9))
|
||||
fig_commits.patch.set_facecolor("#000000")
|
||||
fig_commits.patch.set_alpha(0.5)
|
||||
ax_commits.patch.set_alpha(0.5)
|
||||
|
||||
ax_commits.fill_between(dates, counts, color=COLOUR, alpha=0.4)
|
||||
ax_commits.plot(dates, counts, color=COLOUR, alpha=0.6)
|
||||
ax_commits.xaxis.set_major_locator(mdates.MonthLocator())
|
||||
ax_commits.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m"))
|
||||
ax_commits.set_xlabel("Date", fontsize=12, color="white")
|
||||
ax_commits.set_ylabel("Number of Commits", fontsize=12, color="white")
|
||||
ax_commits.set_title("Commit Activity", fontsize=14, color=COLOUR)
|
||||
ax_commits.grid(True, which="both", linestyle="--", linewidth=0.5, color="gray")
|
||||
|
||||
plt.fill_between(dates, counts, color=COLOUR, alpha=0.4)
|
||||
plt.plot(dates, counts, color=COLOUR, alpha=0.6)
|
||||
plt.gcf().autofmt_xdate()
|
||||
plt.gca().xaxis.set_major_locator(mdates.MonthLocator())
|
||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m"))
|
||||
plt.xlabel("Date", fontsize=12, color="white")
|
||||
plt.ylabel("Number of Commits", fontsize=12, color="white")
|
||||
plt.title("Commit Activity", fontsize=14, color=COLOUR)
|
||||
plt.grid(True, which="both", linestyle="--", linewidth=0.5, color="gray")
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(
|
||||
"commits.png",
|
||||
transparent=True,
|
||||
dpi=DPI,
|
||||
)
|
||||
plt.savefig("commits.png", dpi=DPI)
|
||||
print("Wrote commits.png")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue