-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
212 lines (156 loc) · 5.58 KB
/
main.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from jira_connection_base import JiraConnection
from Story import Story
from Task import Task
import json
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
import time
from configuration import userpsw, DEBUG
def json_task_post(scrumteam, jira_connection):
body='''
{
"jql": "filter=AWO-%s-Sprint-Task",
"startAt": 0,
"maxResults" : 2000,
"fields": [
"assignee",
"issuetype",
"status",
"aggregateprogress"
]
}
'''%scrumteam
jira_connection.\
setUserAndPass(userpsw).\
setHeader().\
setBody(body)
try:
x=jira_connection.sendRequest()
except Exception:
raise
task= Task(json.loads(x.decode()))
return task.get_task()
def json_story_post(scrumteam, jira_connection):
# Body
body='''
{
"jql": "filter=AWO-%s-Sprint-Story",
"startAt": 0,
"maxResults" : 1000
}
'''%scrumteam
jira_connection = JiraConnection()
jira_connection.\
setUserAndPass(userpsw).\
setHeader().\
setBody(body)
try:
x=jira_connection.sendRequest()
except Exception:
raise
story = Story(json.loads(x.decode()))
return story.get_story()
def test_storyfile_json():
jfile=open("jira_story.json")
story = Story(json.loads(jfile.read()))
return story.get_story()
def test_taskfile_json():
jfile=open("jira_task.json")
tasks = Task(json.loads(jfile.read()))
return tasks.get_task()
def story_crunch(stories):
pdata=pd.DataFrame.from_records(stories,columns=['key','Story Developer','Story Point','status','Bug'])
data=pd.DataFrame(pdata.groupby('Story Developer')['Story Point'].sum()).\
join(pdata.groupby('Story Developer')['Bug'].sum()).\
sort_values(by=['Story Point'])
data['Bug Rate']=data['Bug']/data['Story Point']
data['Bug Rate']=data['Bug Rate'].round(3)
print(data)
return data
def task_crunch(tasks):
pdata = pd.DataFrame.from_records(
list(map(lambda x:x[0:4]+[(x[-1]-x[-2])/3600], tasks)),
columns=['Key','Assignee', 'Issuetype', 'Status', 'Remaining_hrs']
)
data=pdata.groupby('Assignee').sum().\
sort_values(by=['Remaining_hrs'])
print(data)
return data
##########################
def report():
if (DEBUG):
print("Test story...")
stories = test_storyfile_json()
story_data=story_crunch(stories)
ax=story_data.plot(kind='barh')
for p in ax.patches:
ax.annotate(str(p.get_width()), (p.get_width() * 1.005, p.get_y() * 1.005))
plt.subplots_adjust(left=0.2)
plt.show()
print("Test task...")
tasks = test_taskfile_json()
task_data=task_crunch(tasks)
task_data.plot.pie(subplots=True, y=['Remaining_hrs'], figsize=(6, 6), radius=0.7)
plt.legend(loc="lower right", fontsize=10,
bbox_transform=plt.gcf().transFigure)
plt.subplots_adjust(left=0.0, bottom=0.1, right=0.85)
plt.show()
if (not DEBUG):
rpt=open("report.html","w+")
rpt.write('<h3> The data generated from JIRA at: '+time.strftime("%c")+'</h3>')
jira_connection = JiraConnection()
if (jira_connection==None):
return None
summary=pd.DataFrame(columns=['Total Story Point', 'Average Bug Rate'])
for i in range(1,11):
try:
if i<8:
CNx="CN"+str(i)
else:
CNx="NA"+str(i-7)
rpt.write('<hr/>')
rpt.write('<h2>Team: %s</h2>'%CNx)
# render story
stories = json_story_post(CNx, jira_connection)
story_data= story_crunch(stories)
ax=story_data.plot(kind='barh')
for p in ax.patches:
ax.annotate(str(p.get_width()), (p.get_width() * 1.01, p.get_y() * 1.005))
plt.subplots_adjust(left=0.2)
plt.savefig('pic/SP_'+CNx+'.png')
rpt.write('<img src="/pic/SP_'+CNx+'.png'+'" />')
rpt.write('<span style="display: inline-block">%s</span>'%
story_data.to_html())
rpt.flush()
# render task
tasks = json_task_post(CNx, jira_connection)
task_data=task_crunch(tasks)
rpt.write('<span style="display: inline-block">%s</span>'%
task_data.to_html())
#
# summary.append(pd.DataFrame(
# [story_data['Story Point'].sum(),story_data['Bug'].sum()/story_data['Story Point'].sum()],
# index=str(i)))
summary.loc[CNx, ['Total Story Point', 'Average Bug Rate']] = \
[story_data['Story Point'].sum(),
round(story_data['Bug'].sum()/story_data['Story Point'].sum(),3)]
except IOError:
print(IOError.errno)
finally:
rpt.flush()
plt.close()
plt.close("all")
rpt.write('<hr/>')
rpt.write('<h3> Team Summary </h3>')
rpt.write('<span style="display: inline-block">%s</span>'%
summary.to_html())
rpt.flush()
rpt.close()
if __name__ == '__main__':
while True:
print('Start running report ...')
report()
print('Start sleeping 15 minutes ...')
time.sleep(60*15)