-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_downtime.py
More file actions
46 lines (40 loc) · 1.52 KB
/
calc_downtime.py
File metadata and controls
46 lines (40 loc) · 1.52 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
#!/usr/bin/env python3
import subprocess
import datetime
from collections import Counter
def get_commit_hours(repo_path="."):
# Get all commit timestamps in ISO 8601 format
result = subprocess.run(
["git", "-C", repo_path, "log", "--pretty=format:%ci"],
capture_output=True, text=True, check=True
)
commit_times = result.stdout.strip().split("\n")
hours = []
for time_str in commit_times:
try:
dt = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S %z")
hours.append(dt.hour)
except ValueError:
continue # skip invalid entries
return hours
def find_least_active_hours(hours):
counter = Counter(hours)
total_commits = sum(counter.values())
activity = [(hour, counter[hour], counter[hour]/total_commits*100) for hour in range(24)]
activity.sort(key=lambda x: x[1]) # Sort by least activity
return activity
def print_activity_summary(activity):
print("Commit activity by hour (UTC):")
for hour, count, pct in activity:
print(f"{hour:02d}:00 - {count:4d} commits ({pct:5.2f}%)")
least_active = activity[0][0]
print(f"\n💤 Least active hour: {least_active:02d}:00 UTC")
print(f"Suggested build window: around {least_active:02d}:00 UTC\n")
if __name__ == "__main__":
repo = "." # current directory by default
hours = get_commit_hours(repo)
if not hours:
print("No commits found.")
else:
activity = find_least_active_hours(hours)
print_activity_summary(activity)