forked from caldwelljs/velocity-prep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfake-deploy-data.py
117 lines (104 loc) · 4.93 KB
/
fake-deploy-data.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
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
#!/usr/bin/python
from faker.factory import Factory
import csv
import sys
import random
import datetime as DT
# TODO: It would be cool if these had links to randomly generated fake PR's on a WP site's pages
def writeTo_csv(fake):
authors = generateAuthorList(15)
pr_list = createPrs(authors)
createDeploys(pr_list)
createCrs(authors)
createTickets()
createZabbix()
def generateAuthorList(num_authors):
authors = []
for _ in range(num_authors):
authors.append(fake.name())
return authors
def createPrs(authors):
pr_list = []
pr_date_id = 1
with open('prs.csv', 'wb') as csvfile:
write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
write_to_csv.writerow(['pr_id', 'pr_author', 'pr_title', 'pr_date', 'pr_desc'])
for _ in range(100):
pr_id = fake.random_int(min=100, max=99999)
pr_author = random.choice(authors)
pr_title = "PR-" + str(pr_id) + ": Did stuff to something"
pr_date_change = 100 - pr_date_id
start_date = "-{}d".format(pr_date_change)
end_date = "-{}d".format(pr_date_change - 10)
pr_date = fake.date_time_between(start_date=start_date, end_date=end_date)
pr_desc = "This PR did some stuff and added integration tests to make sure it works properly"
write_to_csv.writerow((pr_id, pr_author, pr_title, pr_date, pr_desc))
pr_properties = [pr_id, pr_author, pr_title, pr_date, pr_desc]
pr_list.append(pr_id)
# Add Logging
return pr_list
def createDeploys(full_pr_list):
with open('deploys.csv', 'wb') as csvfile:
subversion = 1
pr_min = 1
pr_max = 10
# Setup release_date
format = "%Y-%m-%d %H:%M:%S"
today = DT.datetime.today()
repos = ['nas2','soapbox','cm','deltas','snappyshot']
write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
write_to_csv.writerow(['version', 'release_date', 'repo', 'prs'])
for _ in range(10):
version = "1." + str(subversion) + ".0"
description = "Deploy"
# Figure out the correct release date
date_delta = 100 - pr_max
release_date = today - DT.timedelta(days=date_delta)
release_date = release_date.strftime(format)
repo = random.choice(repos)
# Get range of prs from list
pr_group = full_pr_list[pr_min:pr_max]
prs = ' '.join(str(e) for e in pr_group)
pr_min += 10
pr_max += 10
subversion += 1
write_to_csv.writerow((version, release_date, repo, prs))
# Add Logging
def createCrs(authors):
with open('crs.csv', 'wb') as csvfile:
write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
write_to_csv.writerow(['cr_author', 'cr_id', 'cr_title', 'cr_date', 'cr_desc'])
for _ in range(100):
cr_author = random.choice(authors)
cr_id = fake.random_int(min=100, max=99999)
cr_title = "CR-" + str(cr_id) + ": Fixed bug in code that was breaking things"
cr_date = fake.date_time_between(start_date="-100d", end_date="now")
cr_desc = "This PR did some stuff and added integration tests to make sure it works properly"
write_to_csv.writerow((cr_author, cr_id, cr_title, cr_date, cr_desc))
# TODO: Add logging
def createTickets():
with open('tickets.csv', 'wb') as csvfile:
write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
write_to_csv.writerow(['ticket_id', 'ticket_date', 'ticket_desc'])
for _ in range(1000):
ticket_id = fake.random_int(min=100, max=99999)
ticket_date = fake.date_time_between(start_date="-100d", end_date="now")
ticket_desc = "Customer site returning a 500 instead of site content. Site has been down for 15 minutes."
write_to_csv.writerow((ticket_id, ticket_date, ticket_desc))
# Add spikes in tickets every 10 days
# TODO: Add logging
def createZabbix():
with open('zabbix.csv', 'wb') as csvfile:
write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
write_to_csv.writerow(['zabbix_id', 'zabbix_date', 'zabbix_desc'])
for _ in range(1000):
zabbix_id = fake.random_int(min=100, max=99999)
zabbix_date = fake.date_time_between(start_date="-100d", end_date="now")
server_number = random.randint(1000,99999)
zabbix_desc = "Server number {} is down.".format(server_number)
write_to_csv.writerow((zabbix_id, zabbix_date, zabbix_desc))
# Add spikes in tickets every 10 days
# TODO: Add logging
if __name__ == "__main__":
fake = Factory.create('en_US')
writeTo_csv(fake)