-
Notifications
You must be signed in to change notification settings - Fork 0
/
burndown.py
115 lines (90 loc) · 2.5 KB
/
burndown.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
#!/usr/bin/env python
# coding: utf-8
import os
from datetime import datetime
from assembla.api import API
api = API(
key=os.getenv('ASSEMBLA_KEY'),
secret=os.getenv('ASSEMBLA_SECRET')
)
aulasdovaca = api.spaces()[0]
api.space = aulasdovaca
milestones = api.milestones(space_id=aulasdovaca.id)
milestone = None
for ms in milestones:
if ms.planner_type == 2:
milestone = ms
break
if milestone is None:
raise TypeError('There is no default milestone!')
# burndown {
tickets = api.tickets(
space_id=aulasdovaca.id,
milestone_id=milestone.id
)
burndown_header = [
'"Ticket number"',
'"Completed date"',
'"Sprint estimate"',
'"Total working hours"',
'"Team"',
'"Assigned to"',
'"Ticket extra"',
'"Total estimate"',
'"Finalizar no sprint"',
'"Status"\n'
]
burndown_body = []
for ticket in tickets:
assigned_to = '-'
if ticket.assigned_to_id is not None:
assigned_to = api.user(id=ticket.assigned_to_id).name.encode('ascii', 'ignore')
burndown_body.append([
str(ticket.number),
str(ticket.completed_date or '-'),
str(ticket.total_estimate),
str(ticket.total_working_hours),
'"%s"' % ticket.custom_fields['Equipe'],
'"%s"' % assigned_to,
'"%s"' % ticket.custom_fields['Ticket extra?'],
'"%s"' % ticket.custom_fields['Estimativa inicial para acabar'],
'"%s"' % ticket.custom_fields['Finaliza no sprint?'],
'"%s"\n' % ticket.status
])
# sorting by team
burndown_body.sort(key=lambda x: x[4])
# }
# tasks/worked hours {
tasks_header = [
'Ticket',
'User',
'Worked hours',
'Created at'
]
_from = milestone.created_at
to = datetime.now()
tasks = api.tasks(
_from=_from.strftime('%d-%m-%Y'),
to=to.strftime('%d-%m-%Y')
)
tasks_body = []
for task in tasks:
ticket_number = '-'
if task.ticket_id:
ticket_number = api.ticket(space_id=aulasdovaca.id, id=task.ticket_id).number
tasks_body.append([
str(ticket_number),
api.user(id=task.user_id).name.encode('ascii', 'ignore'),
str(task.hours),
str(task.created_at) + '\n'
])
# }
# writing file
with open('burndown.csv', 'w') as out:
out.write(','.join(burndown_header))
for line in burndown_body:
out.write(','.join([l.encode('ascii', 'ignore') for l in line]))
out.write('\n\n')
out.write(','.join(tasks_header) + '\n')
for line in tasks_body:
out.write(','.join([l.encode('ascii', 'ignore') for l in line]))