大家好,对不起我的英语!
在这个问题上,我需要您的帮助: 我列出了一些问题(其中包括史诗,任务,故事,子任务等) 以某种方式,我过滤了此类信息的ID并将其放置在列表中:
listOfKeys = [id1,id2,id3,id4,id5...]
然后,我需要获取一个表格(屏幕截图中将基于问题建立的数据,该数据位于listOfKeys中): see my screenshot
为此,我编写了以下“代码”:
listOfWorklogs=pd.DataFrame() #table from the screenshot (I used pandas (pd) lib)
lst={} #dictionary for help, where the worklogs will be stored
for i in range(len(listOfKeys)):
worklogs=jira.worklogs(listOfKeys[i]) #getting list of worklogs
if(len(worklogs)) == 0:
i+=1
else:
for j in range(len(worklogs)):
lst = {
'self': worklogs[j].self,
'author': worklogs[j].author,
'started': worklogs[j].started,
'created': worklogs[j].created,
'updated': worklogs[j].updated,
'timespent': worklogs[j].timeSpentSeconds
}
listOfWorklogs = listOfWorklogs.append(lst, ignore_index=True)
########### Below there is the recording to the .xlsx file ################
但是它运行非常缓慢,即使出现100个问题(约3分钟)也是如此。我大约有10,000期((( 也许有一些解决方法?谢谢您,我会很乐意的。
答案 0 :(得分:0)
我使您的代码更具pythonic性,使用迭代器可能会更快一些:
list_of_keys = [
id1, id2, id3, id4, id5
]
resulting_logs = []
for worklog_key in list_of_keys:
worklogs = jira.worklogs(worklog_key)
for log in worklogs:
resulting_logs.append({
'self': log.self,
'author': log.author,
'started': log.started,
'created': log.created,
'updated': log.updated,
'timespent': log.timeSpentSeconds
})
df = pd.DataFrame(resulting_logs)
您可能还会受到jira API响应时间的限制。
但是您可以尝试使用列表理解功能,但尚未进行测试:
list_of_keys = [
id1, id2, id3, id4, id5
]
def parse_log(log):
return {
'self': log.self,
'author': log.author,
'started': log.started,
'created': log.created,
'updated': log.updated,
'timespent': log.timeSpentSeconds
}
resulting_logs = [
parse_log(log)
for log in jira.worklogs(key)
for key in list_of_keys
]
df = pd.DataFrame(resulting_logs)