-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert-jira-export.py
53 lines (43 loc) · 1.78 KB
/
convert-jira-export.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
#!/usr/bin/env python3
"""
This script can be used to convert the cycletimes downloaded with https://github.com/DeloitteDigitalUK/jira-agile-metrics
"""
import csv
from datetime import date
def timeToState(dates):
dateTimes = map(lambda t: date.fromisoformat(t) if t else None, dates)
previousDate = next(dateTimes)
previousIndex = 0
result = []
for (index, currentDate) in enumerate(dateTimes):
correctedIndex = index + 1 # TODO replace next() call by a peek so that we don't have to do this
if not currentDate:
continue
if currentDate > previousDate:
result+=(currentDate-previousDate).days*[previousIndex]
previousIndex=correctedIndex
previousDate=currentDate
result.append(len(dates)-1)
return result
def run():
with open('cycletime.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
header = next(reader)
stateColumnStart = header.index("Name")+1
stateColumnEnd = header.index("Type") # index exclusive
finalStatusColumn = header.index("Status")
with open('cycletime-cleaned.csv', 'w') as cleanedFile:
delimiter = ","
for row in reader:
# if not row[finalStatusColumn]=="Done":
# continue # Filters out tickets not in done, for example canceled tickets
cleanedFile.write(delimiter.join(map(str, timeToState(row[stateColumnStart:stateColumnEnd])))+"\n")
def test():
times=["2019-11-01", None, "2019-11-05", "2019-11-06"]
result = timeToState(times)
assert result==[0,0,0,0,2,3]
times=["2019-11-01", "2019-11-01", "2019-11-01", "2019-11-06"]
result = timeToState(times)
assert result==[2,2,2,2,2,3]
test()
run()