-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue_trend_by_month.py
91 lines (79 loc) · 2.58 KB
/
issue_trend_by_month.py
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
83
84
85
86
87
88
89
90
91
from pymongo import MongoClient
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# Establish a connection to the MongoDB database
client = MongoClient("mongodb://localhost:27017/")
db = client["terraform"]
collection = db["issues"]
# Function to generate monthly range
def month_range(start_year, start_month, end_year, end_month):
start_date = datetime(start_year, start_month, 1)
end_date = datetime(end_year, end_month, 1)
while start_date <= end_date:
yield start_date
start_date += timedelta(days=31)
start_date = start_date.replace(day=1)
# Prepare to store the statistics
opened_issues = {}
closed_issues = {}
remaining_open_issues = {}
cumulative_opened = 0
cumulative_closed = 0
for date in month_range(2015, 12, 2024, 2):
next_month = date + timedelta(days=31)
next_month = next_month.replace(day=1)
# MongoDB query to count issues opened each month
opened_count = collection.count_documents(
{
"created_at": {
"$gte": date.strftime("%Y-%m-%dT00:00:00Z"),
"$lt": next_month.strftime("%Y-%m-%dT00:00:00Z"),
}
}
)
cumulative_opened += opened_count
opened_issues[date.strftime("%Y-%m")] = opened_count
# MongoDB query to count issues closed each month
closed_count = collection.count_documents(
{
"closed_at": {
"$gte": date.strftime("%Y-%m-%dT00:00:00Z"),
"$lt": next_month.strftime("%Y-%m-%dT00:00:00Z"),
}
}
)
cumulative_closed += closed_count
closed_issues[date.strftime("%Y-%m")] = closed_count
# Calculate the remaining open issues
remaining_open_issues[date.strftime("%Y-%m")] = (
cumulative_opened - cumulative_closed
)
# Plotting
plt.figure(figsize=(15, 7))
plt.plot(
list(opened_issues.keys()),
list(opened_issues.values()),
label="Issues Opened",
marker="o",
)
plt.plot(
list(closed_issues.keys()),
list(closed_issues.values()),
label="Issues Closed",
marker="o",
)
plt.plot(
list(remaining_open_issues.keys()),
list(remaining_open_issues.values()),
label="Cumulative Remaining Open Issues",
marker="o",
linestyle="--", # Dashed line for cumulative remaining open issues
)
plt.title("Terraform GitHub Enhancement Issues Opened and Closed (2015-2024)")
plt.xlabel("Month")
plt.ylabel("Number of Issues")
plt.xticks(rotation=90) # Rotate labels to improve readability
plt.legend()
plt.grid(True)
plt.tight_layout() # Adjust layout to make room for the rotated x-axis labels
plt.show()