Created
February 6, 2024 17:31
-
-
Save Magnus167/76d092b91b95956caf697f65edf47d97 to your computer and use it in GitHub Desktop.
Commit frequency plotter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load commit_data.csv | |
from typing import List, Optional | |
import pandas as pd | |
df = pd.read_csv("commit_data.csv") | |
# filter where username is Palash Tyagi or Spalash | |
df = df[(df["username"] == "Palash Tyagi") | (df["username"] == "Spalash")] | |
# get the most active hours | |
# time_of_day is a string HH:MM, just use the hour part | |
df["hour"] = df["time_of_day"].str.split(":").str[0] | |
# group by hour and sum the additions and deletions | |
df = df.groupby("hour").sum(numeric_only=True) | |
# plot the results | |
# drop total column | |
df = df.drop(columns="total") | |
import matplotlib.pyplot as plt | |
df.plot(kind="bar") | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygit2 | |
import pandas as pd | |
from datetime import datetime | |
# Path to your local git repository | |
repo_path = "C:/Users/PalashTyagi/Code/repo/repo" | |
# Initialize the repository object | |
repo = pygit2.Repository(repo_path) | |
# Prepare a list to hold commit data | |
commits_data = [] | |
# Iterate through the repository's commits | |
for commit in repo.walk( | |
repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL | pygit2.GIT_SORT_REVERSE | |
): | |
additions = 0 | |
deletions = 0 | |
# For each commit, calculate additions and deletions by diffing with its parent | |
if commit.parents: | |
parent_commit = commit.parents[0] | |
diff = repo.diff(parent_commit, commit) | |
for patch in diff: | |
for hunk in patch.hunks: | |
for line in hunk.lines: | |
if line.origin == "+": | |
additions += 1 | |
elif line.origin == "-": | |
deletions += 1 | |
# Note: This simplistic approach may not account for all edge cases in diff analysis | |
# Append commit data to the list | |
commits_data.append( | |
{ | |
"sha": commit.hex, | |
"time": datetime.fromtimestamp(commit.commit_time), | |
# time of day - hour and minute | |
"time_of_day": datetime.fromtimestamp(commit.commit_time).strftime("%H:%M"), | |
"additions": additions, | |
"deletions": deletions, | |
"total": additions + deletions, | |
"username": commit.author.name, | |
} | |
) | |
# Convert the list to a DataFrame | |
df = pd.DataFrame(commits_data) | |
# save the dataframe to a csv file | |
# save to ./commit_data.csv | |
df.to_csv("commit_data.csv", index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment