-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_test_datasets.py
More file actions
193 lines (164 loc) · 7.22 KB
/
Copy pathgenerate_test_datasets.py
File metadata and controls
193 lines (164 loc) · 7.22 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import json
import random
from datetime import datetime, timedelta
# ── PROFILES ──────────────────────────────────────────────────────────────────
# Each profile defines how a different team behaves
PROFILES = {
"team_b_high_performing": {
"team_name": "Engineering Team B",
"date_range": "January 2024 – March 2024",
"delivery_rate": 0.88, # high delivery
"large_sp_delivery": 0.78, # even large items get done
"state_multiplier": 0.65, # faster than baseline
"anomaly_sprints_qa": [], # no QA anomalies
"anomaly_sprints_cr": [], # no code review anomalies
"anomaly_assignee": None,
"anomaly_assignee_sprints": [],
},
"team_c_struggling": {
"team_name": "Engineering Team C",
"date_range": "January 2024 – March 2024",
"delivery_rate": 0.50, # low delivery
"large_sp_delivery": 0.25, # large items rarely done
"state_multiplier": 1.6, # much slower than baseline
"anomaly_sprints_qa": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], # QA slow almost every sprint
"anomaly_sprints_cr": [2, 4, 6, 8, 10],
"anomaly_assignee": "alice",
"anomaly_assignee_sprints": [3, 4, 5, 6, 7, 8, 9, 10],
},
}
NUM_SPRINTS = 12
ITEMS_PER_SPRINT = (20, 30)
SPRINT_DURATION = 14
START_DATE = datetime(2024, 1, 1)
ISSUE_TYPES = ["story", "bug", "task"]
ISSUE_TYPE_WEIGHTS = [0.45, 0.35, 0.20]
STORY_POINTS = [1, 2, 3, 5, 8, 13]
STORY_POINT_WEIGHTS= [0.10, 0.20, 0.30, 0.25, 0.10, 0.05]
ASSIGNEES = ["alice", "bob", "carol", "david", "eve"]
STATE_DURATIONS = {
"story": {
"todo": (0.5, 2.0),
"in_progress": (2.0, 6.0),
"code_review": (1.0, 4.0),
"qa": (1.5, 5.0),
"deployment": (0.5, 1.5),
},
"bug": {
"todo": (0.5, 1.5),
"in_progress": (1.0, 4.0),
"code_review": (0.5, 3.0),
"qa": (1.0, 3.5),
"deployment": (0.5, 1.0),
},
"task": {
"todo": (0.5, 1.5),
"in_progress": (1.0, 3.0),
"code_review": (0.5, 2.0),
"qa": (0.5, 2.0),
"deployment": (0.5, 1.0),
},
}
TITLES = {
"story": [
"Add user authentication flow", "Build dashboard overview page",
"Implement export to CSV feature", "Create onboarding wizard",
"Add team settings panel", "Integrate Slack notifications",
"Build sprint summary view", "Add role-based permissions",
"Implement search functionality", "Create API rate limiting",
],
"bug": [
"Fix login timeout issue", "Resolve broken pagination",
"Fix date formatting on reports", "Resolve null pointer on assignee field",
"Fix duplicate notifications bug", "Resolve sprint dates overlap",
"Fix broken CSV export", "Resolve incorrect story point totals",
"Fix missing state transitions", "Resolve timezone mismatch",
],
"task": [
"Update dependencies to latest versions", "Write unit tests for baseline engine",
"Set up staging environment", "Document API endpoints",
"Clean up legacy migration scripts", "Review and update error logging",
"Configure CI/CD pipeline", "Audit database indexes",
],
}
def build_states(issue_type, sprint_start, sprint_idx, assignee, delivered, profile):
states = []
curr_time = sprint_start + timedelta(hours=random.randint(0, 48))
mult = profile["state_multiplier"]
for state in ["todo", "in_progress", "code_review", "qa", "deployment"]:
min_d, max_d = STATE_DURATIONS[issue_type][state]
min_d *= mult
max_d *= mult
if state == "qa" and sprint_idx in profile["anomaly_sprints_qa"]:
max_d *= 2.2
if state == "code_review" and sprint_idx in profile["anomaly_sprints_cr"]:
max_d *= 2.0
if assignee == profile.get("anomaly_assignee") and \
sprint_idx in profile["anomaly_assignee_sprints"]:
max_d *= 1.8
duration = timedelta(days=random.uniform(min_d, max_d))
entered = curr_time
exited = curr_time + duration
if not delivered and state == "qa":
states.append({"state": state, "entered": entered.strftime("%Y-%m-%d"), "exited": None})
break
states.append({
"state": state,
"entered": entered.strftime("%Y-%m-%d"),
"exited": exited.strftime("%Y-%m-%d"),
})
curr_time = exited
if delivered:
states.append({"state": "done", "entered": curr_time.strftime("%Y-%m-%d"), "exited": None})
return states
def generate_dataset(profile_key):
profile = PROFILES[profile_key]
all_issues = []
issue_counter = 100
for sprint_idx in range(NUM_SPRINTS):
sprint_start = START_DATE + timedelta(days=sprint_idx * SPRINT_DURATION)
sprint_end = sprint_start + timedelta(days=SPRINT_DURATION)
sprint_id = f"sprint_{sprint_idx + 1:02d}"
num_items = random.randint(*ITEMS_PER_SPRINT)
for _ in range(num_items):
issue_type = random.choices(ISSUE_TYPES, weights=ISSUE_TYPE_WEIGHTS)[0]
story_points = random.choices(STORY_POINTS, weights=STORY_POINT_WEIGHTS)[0]
assignee = random.choice(ASSIGNEES)
base_rate = profile["delivery_rate"]
if story_points >= 8:
base_rate = profile["large_sp_delivery"]
elif story_points >= 5:
base_rate = (profile["delivery_rate"] + profile["large_sp_delivery"]) / 2
# Struggling team gets progressively worse over time
if profile_key == "team_c_struggling" and sprint_idx >= 6:
base_rate *= 0.85
delivered = random.random() < base_rate
states = build_states(
issue_type, sprint_start, sprint_idx,
assignee, delivered, profile
)
all_issues.append({
"issue_id": f"PROJ-{issue_counter:03d}",
"title": random.choice(TITLES[issue_type]),
"type": issue_type,
"story_points": story_points,
"assignee": assignee,
"sprint_id": sprint_id,
"sprint_start": sprint_start.strftime("%Y-%m-%d"),
"sprint_end": sprint_end.strftime("%Y-%m-%d"),
"committed": True,
"delivered": delivered,
"states": states,
})
issue_counter += 1
return all_issues, profile
if __name__ == "__main__":
for profile_key in PROFILES:
print(f"\nGenerating {profile_key}...")
data, profile = generate_dataset(profile_key)
output_path = f"data/{profile_key}.json"
with open(output_path, "w") as f:
json.dump(data, f, indent=2)
delivered = sum(1 for i in data if i["delivered"])
print(f" {len(data)} issues, {delivered/len(data)*100:.1f}% delivery rate")
print(f" Saved to {output_path}")