forked from Imulion/MHFZ_Overlay
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommits_per_hour.py
More file actions
82 lines (65 loc) · 2.8 KB
/
commits_per_hour.py
File metadata and controls
82 lines (65 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# © 2023 The mhfz-overlay developers.
# Use of this source code is governed by a MIT license that can be
# found in the LICENSE file.
import re
import datetime
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
author_name = "Doriel Rivalet" # replace with your name for display
author_email = "100863878+DorielRivalet@users.noreply.github.com" # replace with your email for identification
input_file = './input/git_anonymized.txt'
output_file = './output/commits_per_hour.png'
data = [] # this will hold our commit times
commit_regex = r"Date:\s+(.+)" # regex to match the datetime line
author_regex = r"Author:\s+(.+)" # regex to match the author line
current_author = None
# get the current working directory
current_working_directory = Path.cwd()
# print output to the console
print(current_working_directory)
print("Calculating commits per hour... ")
with open(input_file, 'r', encoding='utf-8') as f:
for line in f:
author_match = re.search(author_regex, line)
if author_match:
current_author = author_match.group(1)
date_match = re.search(commit_regex, line)
if date_match and author_email in current_author:
date_string = date_match.group(1)
date = datetime.datetime.strptime(date_string, '%a %b %d %H:%M:%S %Y %z')
data.append(date)
print("Data: ", data)
# Check if the data list is empty
if len(data) == 0:
print(f"No data for author {author_name} ({author_email}).")
exit()
df = pd.DataFrame(data, columns=['datetime'])
df['datetime'] = pd.to_datetime(df['datetime'], utc=True)
df['hour'] = df['datetime'].dt.hour # extract the hour from the datetime
commits_per_hour = df['hour'].value_counts().sort_index() # count the number of commits per hour
# Use a dark background
plt.style.use('dark_background')
# Set figure size
fig_width = 10 # width in inches
fig_height = 5.625 # height in inches (to maintain the 16:9 aspect ratio)
plt.figure(figsize=(fig_width, fig_height))
ax = plt.gca()
ax.bar(commits_per_hour.index, commits_per_hour.values, color='#f38ba8')
plt.xlabel('Hour of the Day', color='#cdd6f4')
plt.ylabel('Number of Commits', color='#cdd6f4')
plt.title(f'Number of Commits per Hour by {author_name}', color='#cdd6f4')
plt.xticks(range(24), color='#cdd6f4') # Ensure all hours from 0 to 23 are shown
plt.yticks(color='#cdd6f4') # Set y-ticks color
# Add horizontal lines at each y-tick
for y_marker in ax.get_yticks():
ax.axhline(y=y_marker, color='#cdd6f4', linestyle='--', alpha=0.5)
# Calculate dpi for 1080p resolution
dpi_width = 1920 / fig_width
dpi_height = 1080 / fig_height
dpi = max(dpi_width, dpi_height)
# Set dpi to control the size of the output image
# Save the figure as a PNG image
plt.savefig(output_file, dpi=dpi)
plt.show()
print('Created commits per hour image succesfully')