-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_asof.py
More file actions
48 lines (40 loc) · 1.62 KB
/
test_asof.py
File metadata and controls
48 lines (40 loc) · 1.62 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
import sys, datetime, csv, os, pprint
from v1pysdk import V1Meta
statuses = [
'Not Started',
'Ready for Dev',
'Developing',
'Ready for Test',
'Testing',
'Tested',
]
select_template = "Workitems:PrimaryWorkitem[Status.Name='{0}'].Estimate.@Sum"
def parsedate(d):
return datetime.datetime.strptime(d, "%Y-%m-%d")
def as_of_times(start, end, hoursper=6):
current = start
while current <= end:
yield current
current += datetime.timedelta(hours=hoursper)
if __name__=="__main__":
username, password, sprintName, outputFolder = sys.argv[1:5]
with V1Meta('www7.v1host.com', 'V1Production', username, password) as v1:
timebox = (v1.Timebox
.where(Name=sprintName)
.select("BeginDate", "EndDate")
.first())
startdate = parsedate(timebox.BeginDate)
enddate = parsedate(timebox.EndDate) + datetime.timedelta(days=1)
individual_times = as_of_times(startdate, enddate)
select_list = [ select_template.format(status) for status in statuses]
results = (v1.Timebox
.asof(individual_times)
.where(Name=sprintName)
.select(*select_list))
outfilename = os.path.join(outputFolder, sprintName + ".dat")
with open(outfilename, "w") as outfile:
writer = csv.writer(outfile, delimiter="|")
writer.writerow(['# Date'] + statuses)
for result in results:
row = [result.data[select_term] for select_term in select_list]
writer.writerow([result.data['AsOf']] + row)